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 #
4
2
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.
7
7
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 ##
9
12
10
13
PHP 5 with cURL (including SSL) support.
11
14
12
- ## Usage: ##
15
+ ## Usage ##
13
16
14
17
Example - Return status array for each Proxmox Host in this cluster.
15
18
19
+ ``` php
16
20
require("./pve2-api-php-client/pve2_api.class.php");
17
21
18
22
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
19
23
# realm above can be pve, pam or any other realm available.
20
24
21
25
if ($pve2->constructor_success()) {
22
- /* Optional - enable debugging. It print()'s any results currently */
23
- // $pve2->set_debug(true);
24
-
25
26
if ($pve2->login()) {
26
27
foreach ($pve2->get_node_list() as $node_name) {
27
28
print_r($pve2->get("/nodes/".$node_name."/status"));
@@ -34,21 +35,18 @@ Example - Return status array for each Proxmox Host in this cluster.
34
35
print("Could not create PVE2_API object.\n");
35
36
exit;
36
37
}
38
+ ```
37
39
38
40
Example - Create a new OpenVZ Container on the first host in the cluster.
39
41
42
+ ``` php
40
43
require("./pve2-api-php-client/pve2_api.class.php");
41
44
42
45
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
43
46
# realm above can be pve, pam or any other realm available.
44
47
45
48
if ($pve2->constructor_success()) {
46
-
47
- /* Optional - enable debugging. It print()'s any results currently */
48
- // $pve2->set_debug(true);
49
-
50
49
if ($pve2->login()) {
51
-
52
50
# Get first node name.
53
51
$nodes = $pve2->get_node_list();
54
52
$first_node = $nodes[0];
@@ -78,21 +76,18 @@ Example - Create a new OpenVZ Container on the first host in the cluster.
78
76
print("Could not create PVE2_API object.\n");
79
77
exit;
80
78
}
79
+ ```
81
80
82
81
Example - Modify DNS settings on an existing container on the first host.
83
82
83
+ ``` php
84
84
require("./pve2-api-php-client/pve2_api.class.php");
85
85
86
86
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
87
87
# realm above can be pve, pam or any other realm available.
88
88
89
89
if ($pve2->constructor_success()) {
90
-
91
- /* Optional - enable debugging. It print()'s any results currently */
92
- // $pve2->set_debug(true);
93
-
94
90
if ($pve2->login()) {
95
-
96
91
# Get first node name.
97
92
$nodes = $pve2->get_node_list();
98
93
$first_node = $nodes[0];
@@ -112,19 +107,17 @@ Example - Modify DNS settings on an existing container on the first host.
112
107
print("Could not create PVE2_API object.\n");
113
108
exit;
114
109
}
110
+ ```
115
111
116
112
Example - Delete an existing container.
117
113
114
+ ``` php
118
115
require("./pve2-api-php-client/pve2_api.class.php");
119
116
120
117
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
121
118
# realm above can be pve, pam or any other realm available.
122
119
123
120
if ($pve2->constructor_success()) {
124
-
125
- /* Optional - enable debugging. It print()'s any results currently */
126
- // $pve2->set_debug(true);
127
-
128
121
if ($pve2->login()) {
129
122
# NOTE - replace XXXX with node short name, and YYYY with container ID.
130
123
var_dump($pve2->delete("/nodes/XXXX/openvz/YYYY"));
@@ -136,6 +129,7 @@ Example - Delete an existing container.
136
129
print("Could not create PVE2_API object.\n");
137
130
exit;
138
131
}
132
+ ```
139
133
140
134
Licensed under the MIT License.
141
135
See LICENSE file.
0 commit comments