Skip to content

Commit 206ae1e

Browse files
committed
fix readme examples - remove constructor_success() references
1 parent 03d8a24 commit 206ae1e

File tree

1 file changed

+57
-76
lines changed

1 file changed

+57
-76
lines changed

README.md

Lines changed: 57 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,125 +15,106 @@ Example - Return status array for each Proxmox Host in this cluster.
1515

1616
require("./pve2-api-php-client/pve2_api.class.php");
1717

18+
# You can try/catch exception handle the constructor here if you want.
1819
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
1920
# realm above can be pve, pam or any other realm available.
2021

21-
if ($pve2->constructor_success()) {
22-
/* Optional - enable debugging. It print()'s any results currently */
23-
// $pve2->set_debug(true);
24-
25-
if ($pve2->login()) {
26-
foreach ($pve2->get_node_list() as $node_name) {
27-
print_r($pve2->get("/nodes/".$node_name."/status"));
28-
}
29-
} else {
30-
print("Login to Proxmox Host failed.\n");
31-
exit;
22+
/* Optional - enable debugging. It print()'s any results currently */
23+
// $pve2->set_debug(true);
24+
25+
if ($pve2->login()) {
26+
foreach ($pve2->get_node_list() as $node_name) {
27+
print_r($pve2->get("/nodes/".$node_name."/status"));
3228
}
3329
} else {
34-
print("Could not create PVE2_API object.\n");
30+
print("Login to Proxmox Host failed.\n");
3531
exit;
3632
}
3733

3834
Example - Create a new OpenVZ Container on the first host in the cluster.
3935

4036
require("./pve2-api-php-client/pve2_api.class.php");
4137

38+
# You can try/catch exception handle the constructor here if you want.
4239
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
4340
# realm above can be pve, pam or any other realm available.
4441

45-
if ($pve2->constructor_success()) {
46-
47-
/* Optional - enable debugging. It print()'s any results currently */
48-
// $pve2->set_debug(true);
49-
50-
if ($pve2->login()) {
51-
52-
# Get first node name.
53-
$nodes = $pve2->get_node_list();
54-
$first_node = $nodes[0];
55-
unset($nodes);
56-
57-
# Create a VZ container on the first node in the cluster.
58-
$new_container_settings = array();
59-
$new_container_settings['ostemplate'] = "local:vztmpl/debian-6.0-standard_6.0-4_amd64.tar.gz";
60-
$new_container_settings['vmid'] = "1234";
61-
$new_container_settings['cpus'] = "2";
62-
$new_container_settings['description'] = "Test VM using Proxmox 2.0 API";
63-
$new_container_settings['disk'] = "8";
64-
$new_container_settings['hostname'] = "testapi.domain.tld";
65-
$new_container_settings['memory'] = "1024";
66-
$new_container_settings['nameserver'] = "4.2.2.1";
67-
68-
// print_r($new_container_settings);
69-
print("---------------------------\n");
70-
71-
print_r($pve2->post("/nodes/".$first_node."/openvz", $new_container_settings));
72-
print("\n\n");
73-
} else {
74-
print("Login to Proxmox Host failed.\n");
75-
exit;
76-
}
42+
/* Optional - enable debugging. It print()'s any results currently */
43+
// $pve2->set_debug(true);
44+
45+
if ($pve2->login()) {
46+
47+
# Get first node name.
48+
$nodes = $pve2->get_node_list();
49+
$first_node = $nodes[0];
50+
unset($nodes);
51+
52+
# Create a VZ container on the first node in the cluster.
53+
$new_container_settings = array();
54+
$new_container_settings['ostemplate'] = "local:vztmpl/debian-6.0-standard_6.0-4_amd64.tar.gz";
55+
$new_container_settings['vmid'] = "1234";
56+
$new_container_settings['cpus'] = "2";
57+
$new_container_settings['description'] = "Test VM using Proxmox 2.0 API";
58+
$new_container_settings['disk'] = "8";
59+
$new_container_settings['hostname'] = "testapi.domain.tld";
60+
$new_container_settings['memory'] = "1024";
61+
$new_container_settings['nameserver'] = "4.2.2.1";
62+
63+
// print_r($new_container_settings);
64+
print("---------------------------\n");
65+
66+
print_r($pve2->post("/nodes/".$first_node."/openvz", $new_container_settings));
67+
print("\n\n");
7768
} else {
78-
print("Could not create PVE2_API object.\n");
69+
print("Login to Proxmox Host failed.\n");
7970
exit;
8071
}
8172

8273
Example - Modify DNS settings on an existing container on the first host.
8374

8475
require("./pve2-api-php-client/pve2_api.class.php");
8576

77+
# You can try/catch exception handle the constructor here if you want.
8678
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
8779
# realm above can be pve, pam or any other realm available.
8880

89-
if ($pve2->constructor_success()) {
90-
91-
/* Optional - enable debugging. It print()'s any results currently */
92-
// $pve2->set_debug(true);
81+
/* Optional - enable debugging. It print()'s any results currently */
82+
// $pve2->set_debug(true);
9383

94-
if ($pve2->login()) {
84+
if ($pve2->login()) {
9585

96-
# Get first node name.
97-
$nodes = $pve2->get_node_list();
98-
$first_node = $nodes[0];
99-
unset($nodes);
86+
# Get first node name.
87+
$nodes = $pve2->get_node_list();
88+
$first_node = $nodes[0];
89+
unset($nodes);
10090

101-
# Update container settings.
102-
$container_settings = array();
103-
$container_settings['nameserver'] = "4.2.2.2";
91+
# Update container settings.
92+
$container_settings = array();
93+
$container_settings['nameserver'] = "4.2.2.2";
10494

105-
# NOTE - replace XXXX with container ID.
106-
var_dump($pve2->put("/nodes/".$first_node."/openvz/XXXX/config", $container_settings));
107-
} else {
108-
print("Login to Proxmox Host failed.\n");
109-
exit;
110-
}
95+
# NOTE - replace XXXX with container ID.
96+
var_dump($pve2->put("/nodes/".$first_node."/openvz/XXXX/config", $container_settings));
11197
} else {
112-
print("Could not create PVE2_API object.\n");
98+
print("Login to Proxmox Host failed.\n");
11399
exit;
114100
}
115101

116102
Example - Delete an existing container.
117103

118104
require("./pve2-api-php-client/pve2_api.class.php");
119105

106+
# You can try/catch exception handle the constructor here if you want.
120107
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
121108
# realm above can be pve, pam or any other realm available.
122109

123-
if ($pve2->constructor_success()) {
110+
/* Optional - enable debugging. It print()'s any results currently */
111+
// $pve2->set_debug(true);
124112

125-
/* Optional - enable debugging. It print()'s any results currently */
126-
// $pve2->set_debug(true);
127-
128-
if ($pve2->login()) {
129-
# NOTE - replace XXXX with node short name, and YYYY with container ID.
130-
var_dump($pve2->delete("/nodes/XXXX/openvz/YYYY"));
131-
} else {
132-
print("Login to Proxmox Host failed.\n");
133-
exit;
134-
}
113+
if ($pve2->login()) {
114+
# NOTE - replace XXXX with node short name, and YYYY with container ID.
115+
var_dump($pve2->delete("/nodes/XXXX/openvz/YYYY"));
135116
} else {
136-
print("Could not create PVE2_API object.\n");
117+
print("Login to Proxmox Host failed.\n");
137118
exit;
138119
}
139120

0 commit comments

Comments
 (0)