cv4pve api php
v8.3.0
Proxmox VE 客户端 API PHP
Proxmox VE API
______ _ __
/ ____/___ __________(_)___ _ _____ _____/ /_
/ / / __ / ___/ ___/ / __ | / / _ / ___/ __/
/ /___/ /_/ / / (__ ) / / / / |/ / __(__ ) /_
____/____/_/ /____/_/_/ /_/|___/___/____/__/
Corsinvest for Proxmox VE Api Client (Made in Italy)
版权所有:Corsinvest Srl 有关许可详细信息,请访问许可证
该软件是名为 cv4pve-tools 的工具套件的一部分。如果您需要商业支持,请访问该网站
客户端是从 Proxmox VE 上的 JSON Api 生成的。
这个 PHP 5.4+ 库允许您通过 API 与 Proxmox 服务器交互。客户端是从 Proxmox VE 上的 JSON Api 生成的。
结果是类Result并包含方法:
从 Proxmox VE 6.2 版本开始,可以使用 Api 令牌。此功能允许在不使用用户名和密码的情况下执行 Api。如果在创建 api 令牌时使用权限分离,请记住在权限中指定。格式USER@REALM!TOKENID=TOKEN
(使用示例如下)
推荐安装使用【Composer】,如果你没有【Composer】还等什么呢?
在项目的根目录中执行以下命令:
composer require Corsinvest/cv4pve-api-php
或者将其添加到您的composer.json
<?php
// Require the autoloader
require_once ' vendor/autoload.php ' ;
//if you want use lite version only get/set/create/delete use PveClientBase
$ client = new Corsinvest ProxmoxVE Api PveClient ( " 192.168.0.24 " );
//login check bool
if ( $ client -> login ( ' root ' , ' password ' , ' pam ' )){
//get version from get method
var_dump ( $ client -> get ( ' /version ' )-> getResponse ());
// $client->put
// $client->post
// $client->delete
$ retPippo = $ client -> get ( " /pippo " );
echo "n" . $ retPippo -> getStatusCode ();
echo "n" . $ retPippo -> getReasonPhrase ();
//loop nodes
foreach ( $ client -> getNodes ()-> Index ()-> getResponse ()-> data as $ node ) {
echo "n" . $ node -> id ;
}
//loop vm
foreach ( $ client -> getNodes ()-> get ( " pve1 " )-> getQemu ()-> Vmlist ()-> getResponse ()-> data as $ vm ) {
echo "n" . $ vm -> vmid . " - " . $ vm -> name ;
}
//loop snapshots
foreach ( $ client -> getNodes ()-> get ( " pve1 " )-> getQemu ()-> get ( 100 )-> getSnapshot ()-> snapshotList ()-> getResponse ()-> data as $ snap ) {
echo "n" . $ snap -> name ;
}
//return object
var_dump ( $ client -> getVersion ()-> version ()-> getResponse ());
//disable return object
$ client -> setResultIsObject ( false );
//return array
$ retArr = $ client -> getVersion ()-> version ()-> getResponse ();
var_dump ( $ retArr );
echo "n" . $ retArr [ ' data ' ][ ' release ' ];
//enable return objet
$ client -> setResultIsObject ( true );
//image rrd
$ client -> setResponseType ( ' png ' );
echo " <img src=' { $ client -> getNodes ()-> get ( " pve1 " )-> getRrd ()-> rrd ( ' cpu ' , ' day ' )-> getResponse ()} ' > " ;
//result json result
$ client -> setResponseType ( ' json ' );
var_dump ( $ client -> get ( ' /version ' )-> getResponse ());
//set connection timeout (by default no timeout)
$ client -> setTimeout ( 2 )-> get ( ' /version ' )-> getResponse ();
}
输出版本请求示例:
//object result
var_dump ( $ client -> getVersion ()-> Version ()-> getResponse ());
object (stdClass) #9 (1) {
[ " data " ]=>
object(stdClass) #32 (4) {
[ " version " ]=>
string( 3 ) " 5.0 "
[ " release " ]=>
string( 2 ) " 31 "
[ " keyboard " ]=>
string( 2 ) " it "
[ " repoid " ]=>
string( 8 ) " 27769b1f "
}
}
//disable return object
$ client -> setResultIsObject (false);
//array result
var_dump( $ client -> getVersion ()->Version());
array(1) {
[ " data"]=>
array ( 4 ) {
[ " repoid " ]=>
string( 8 ) " 2560e073 "
[ " release " ]=>
string( 2 ) " 32 "
[ " version " ]=>
string( 3 ) " 5.0 "
[ " keyboard " ]=>
string( 2 ) " it "
}
}
文档中以“[n]”索引结束的参数(Qemu参数ide中的方法createVM)需要数组惠特键和值
[
1 => " .... " ,
3 => " .... " ,
]
<?php
// Require the autoloader
require_once ' vendor/autoload.php ' ;
//if you want use lite version only get/set/create/delete use PveClientBase
$ client = new Corsinvest ProxmoxVE Api PveClient ( " hostname " , " 8006 " );
$ client -> setApiToken ( " root@pam!mytokenname=<TOKEN COMES HERE> " );
echo $ client -> getVersion ();