monbro / pve2api
此软件包最新版本(dev-master)没有可用的许可信息。
这是一个简单的PHP客户端,用于Proxmox API,带有Composer包装器
dev-master
2016-07-07 11:34 UTC
This package is not auto-updated.
Last update: 2024-09-28 15:59:58 UTC
README
此类为想要使用PHP与Proxmox 2.0通信的人提供构建模块。相对简单的代码,只是提供了在Proxmox的REST API之上的get/put/post/delete抽象层,同时处理用于认证的登录票据头。
有关此API如何工作的信息,请参阅 http://pve.proxmox.com/wiki/Proxmox_VE_API。API规范可在 http://pve.proxmox.com/pve2-api-doc/ 获取。
要求
PHP 5支持cURL(包括SSL)。
用法
示例 - 返回此集群中每个Proxmox主机的状态数组。
require("./pve2-api-php-client/pve2_api.class.php");
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
# realm above can be pve, pam or any other realm available.
if ($pve2->constructor_success()) {
/* Optional - enable debugging. It print()'s any results currently */
// $pve2->set_debug(true);
if ($pve2->login()) {
foreach ($pve2->get_node_list() as $node_name) {
print_r($pve2->get("/nodes/".$node_name."/status"));
}
} else {
print("Login to Proxmox Host failed.\n");
exit;
}
} else {
print("Could not create PVE2_API object.\n");
exit;
}
示例 - 在集群的第一个主机上创建一个新的OpenVZ容器。
require("./pve2-api-php-client/pve2_api.class.php");
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
# realm above can be pve, pam or any other realm available.
if ($pve2->constructor_success()) {
/* Optional - enable debugging. It print()'s any results currently */
// $pve2->set_debug(true);
if ($pve2->login()) {
# Get first node name.
$nodes = $pve2->get_node_list();
$first_node = $nodes[0];
unset($nodes);
# Create a VZ container on the first node in the cluster.
$new_container_settings = array();
$new_container_settings['ostemplate'] = "local:vztmpl/debian-6.0-standard_6.0-4_amd64.tar.gz";
$new_container_settings['vmid'] = "1234";
$new_container_settings['cpus'] = "2";
$new_container_settings['description'] = "Test VM using Proxmox 2.0 API";
$new_container_settings['disk'] = "8";
$new_container_settings['hostname'] = "testapi.domain.tld";
$new_container_settings['memory'] = "1024";
$new_container_settings['nameserver'] = "4.2.2.1";
// print_r($new_container_settings);
print("---------------------------\n");
print_r($pve2->post("/nodes/".$first_node."/openvz", $new_container_settings));
print("\n\n");
} else {
print("Login to Proxmox Host failed.\n");
exit;
}
} else {
print("Could not create PVE2_API object.\n");
exit;
}
示例 - 修改第一个主机上现有容器的DNS设置。
require("./pve2-api-php-client/pve2_api.class.php");
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
# realm above can be pve, pam or any other realm available.
if ($pve2->constructor_success()) {
/* Optional - enable debugging. It print()'s any results currently */
// $pve2->set_debug(true);
if ($pve2->login()) {
# Get first node name.
$nodes = $pve2->get_node_list();
$first_node = $nodes[0];
unset($nodes);
# Update container settings.
$container_settings = array();
$container_settings['nameserver'] = "4.2.2.2";
# NOTE - replace XXXX with container ID.
var_dump($pve2->put("/nodes/".$first_node."/openvz/XXXX/config", $container_settings));
} else {
print("Login to Proxmox Host failed.\n");
exit;
}
} else {
print("Could not create PVE2_API object.\n");
exit;
}
示例 - 删除现有容器。
require("./pve2-api-php-client/pve2_api.class.php");
$pve2 = new PVE2_API("hostname", "username", "realm", "password");
# realm above can be pve, pam or any other realm available.
if ($pve2->constructor_success()) {
/* Optional - enable debugging. It print()'s any results currently */
// $pve2->set_debug(true);
if ($pve2->login()) {
# NOTE - replace XXXX with node short name, and YYYY with container ID.
var_dump($pve2->delete("/nodes/XXXX/openvz/YYYY"));
} else {
print("Login to Proxmox Host failed.\n");
exit;
}
} else {
print("Could not create PVE2_API object.\n");
exit;
}
许可协议为MIT License。请参阅LICENSE文件。