skeeks / yii2-proxmox
为yii2的ProxmoxVE API客户端
1.0.0
2015-11-13 22:36 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: *
- zzantares/proxmoxve: ~3.0
This package is auto-updated.
Last update: 2024-08-25 10:24:33 UTC
README
安装
$ composer require skeeks/yii2-proxmox "*"
或者将其添加到您的 composer.json
文件中
{ "require": { "skeeks/yii2-proxmox": "*" } }
用法
配置
'proxmox' => [ 'class' => 'skeeks\proxmox\ProxmoxComponent', 'hostname' => 'server1.proxmox.com', 'username' => 'root', 'password' => 'password', //'realm' => 'pam', //pve //'port' => '8006', ], 'proxmox2' => [ 'class' => 'skeeks\proxmox\ProxmoxComponent', 'hostname' => 'server2.proxmox.com', 'username' => 'root', 'password' => 'password', //'realm' => 'pam', //pve //'port' => '8006', ],
用法
if (\Yii::$app->proxmox->api) { $allNodes = \Yii::$app->proxmox->api->get('/nodes'); print_r($allNodes); } else { //\Yii::$app->proxmox->error — \Exception \Yii::$app->proxmox->error->getMessage(); } if (\Yii::$app->proxmox2->api) { \Yii::$app->proxmox2->api->get('/nodes'); } ....
示例输出
Array ( [data] => Array ( [0] => Array ( [disk] => 2539465464 [cpu] => 0.031314446882002 [maxdisk] => 30805066770 [maxmem] => 175168446464 [node] => mynode1 [maxcpu] => 24 [level] => [uptime] => 139376 [id] => node/mynode1 [type] => node [mem] => 20601992182 ) ) )
// It is common to fetch images and then use base64 to display the image easily in a webpage \Yii::$app->proxmox->api->setResponseType('pngb64'); // Sample format: data:image/png;base64,iVBORw0KGgoAAAA... $base64 = \Yii::$app->proxmox->api->get('/nodes/hosting4-skeeks/rrd', ['ds' => 'cpu', 'timeframe' => 'day']); // So we can do something like this echo "<img src='{$base64}' \>";
// Ask for nodes, gives back a PHP string with HTML response \Yii::$app->proxmox->api->get('/nodes'); // Change response type to JSON \Yii::$app->proxmox->api->setResponseType('json'); // Now asking for nodes gives back JSON raw string \Yii::$app->proxmox->api->get('/nodes'); // If you want again return PHP arrays you can use the 'array' format. \Yii::$app->proxmox->api->setResponseType('array'); // Also you can call getResponseType for whatever reason you have $responseType = \Yii::$app->proxmox->api->getResponseType(); // array
文档
在您的Proxmox客户端对象上,您可以使用 get()
、create()
、set()
和 delete()
函数操作在[PVE2 API文档]中指定的所有资源,参数作为关联数组中的第二个参数传递。
我可以与哪些资源或路径交互以及如何交互?
在您的Proxmox服务器上,您可以使用pvesh CLI工具来管理所有pve资源,您可以使用此库以与使用pvesh工具完全相同的方式使用它。例如,您可以运行pvesh
,然后,如屏幕信息所示,您可以输入help [path] [--verbose]
以查看如何使用路径以及应传递给它的参数。请确保在[Proxmox wiki]上阅读有关pvesh CLI工具的信息。
SkeekS CMS (Yii2) —— 快速、简单、有效!
skeeks.com | cms.skeeks.com