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 ();