PHP code example of skeeks / yii2-proxmox

1. Go to this page and download the library: Download skeeks/yii2-proxmox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

skeeks / yii2-proxmox example snippets



    '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