1- This class provides the building blocks for someone wanting to use PHP to talk to Proxmox 2.0.
2- Relatively simple piece of code, just provides a get/put/post/delete abstraction layer as methods
3- on top of Proxmox's REST API, while also handling the Login Ticket headers required for authentication.
1+ # PVE2 API - PHP Client #
42
5- See http://pve.proxmox.com/wiki/Proxmox_VE_API for information about how this API works.
6- API spec available at http://pve.proxmox.com/pve2-api-doc/
3+ This class provides the building blocks for someone wanting to use PHP to talk
4+ to Proxmox 2.0+. Relatively simple piece of code, just provides a
5+ get/put/post/delete abstraction layer as methods on top of Proxmox's REST API,
6+ while also handling the Login Ticket headers required for authentication.
77
8- ## Requirements: ##
8+ See < http://pve.proxmox.com/wiki/Proxmox_VE_API > for information about how this
9+ API works. API spec available at < http://pve.proxmox.com/pve2-api-doc/ >
10+
11+ ## Requirements ##
912
1013PHP 5 with cURL (including SSL) support.
1114
12- ## Usage: ##
15+ ## Usage ##
1316
1417Example - Return status array for each Proxmox Host in this cluster.
1518
19+ ``` php
1620 require("./pve2-api-php-client/pve2_api.class.php");
1721
1822 $pve2 = new PVE2_API("hostname", "username", "realm", "password");
1923 # realm above can be pve, pam or any other realm available.
2024
2125 if ($pve2->constructor_success()) {
22- /* Optional - enable debugging. It print()'s any results currently */
23- // $pve2->set_debug(true);
24-
2526 if ($pve2->login()) {
2627 foreach ($pve2->get_node_list() as $node_name) {
2728 print_r($pve2->get("/nodes/".$node_name."/status"));
@@ -34,21 +35,18 @@ Example - Return status array for each Proxmox Host in this cluster.
3435 print("Could not create PVE2_API object.\n");
3536 exit;
3637 }
38+ ```
3739
3840Example - Create a new OpenVZ Container on the first host in the cluster.
3941
42+ ``` php
4043 require("./pve2-api-php-client/pve2_api.class.php");
4144
4245 $pve2 = new PVE2_API("hostname", "username", "realm", "password");
4346 # realm above can be pve, pam or any other realm available.
4447
4548 if ($pve2->constructor_success()) {
46-
47- /* Optional - enable debugging. It print()'s any results currently */
48- // $pve2->set_debug(true);
49-
5049 if ($pve2->login()) {
51-
5250 # Get first node name.
5351 $nodes = $pve2->get_node_list();
5452 $first_node = $nodes[0];
@@ -78,21 +76,18 @@ Example - Create a new OpenVZ Container on the first host in the cluster.
7876 print("Could not create PVE2_API object.\n");
7977 exit;
8078 }
79+ ```
8180
8281Example - Modify DNS settings on an existing container on the first host.
8382
83+ ``` php
8484 require("./pve2-api-php-client/pve2_api.class.php");
8585
8686 $pve2 = new PVE2_API("hostname", "username", "realm", "password");
8787 # realm above can be pve, pam or any other realm available.
8888
8989 if ($pve2->constructor_success()) {
90-
91- /* Optional - enable debugging. It print()'s any results currently */
92- // $pve2->set_debug(true);
93-
9490 if ($pve2->login()) {
95-
9691 # Get first node name.
9792 $nodes = $pve2->get_node_list();
9893 $first_node = $nodes[0];
@@ -112,19 +107,17 @@ Example - Modify DNS settings on an existing container on the first host.
112107 print("Could not create PVE2_API object.\n");
113108 exit;
114109 }
110+ ```
115111
116112Example - Delete an existing container.
117113
114+ ``` php
118115 require("./pve2-api-php-client/pve2_api.class.php");
119116
120117 $pve2 = new PVE2_API("hostname", "username", "realm", "password");
121118 # realm above can be pve, pam or any other realm available.
122119
123120 if ($pve2->constructor_success()) {
124-
125- /* Optional - enable debugging. It print()'s any results currently */
126- // $pve2->set_debug(true);
127-
128121 if ($pve2->login()) {
129122 # NOTE - replace XXXX with node short name, and YYYY with container ID.
130123 var_dump($pve2->delete("/nodes/XXXX/openvz/YYYY"));
@@ -136,6 +129,7 @@ Example - Delete an existing container.
136129 print("Could not create PVE2_API object.\n");
137130 exit;
138131 }
132+ ```
139133
140134Licensed under the MIT License.
141135See LICENSE file.
0 commit comments