PHP code example of client-api / pmg

1. Go to this page and download the library: Download client-api/pmg 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/ */

    

client-api / pmg example snippets



ClientApi\Pmg\Configuration;
use ClientApi\Pmg\Pve;

$cfg = Configuration::getDefaultConfiguration()
    ->setHost('https://pmg1.example.com:8006/api2/json')
    ->setApiKey('Authorization', 'PMGAPIToken=user@realm!tokenid=uuid-secret');

$pve = new Pmg($cfg);

// Per-tag accessors are lazily instantiated and share the same Configuration.
$status = $pmg->qemu()->qemuVmStatus(node: 'pmg1', vmid: 100);
$nodes  = $pmg->nodes()->nodesGetNodes();

use ClientApi\Pmg\Model\PveQemuNetConfig;

$cfg = new PveQemuNetConfig([
    'model'    => 'virtio',
    'bridge'   => 'vmbr0',
    'firewall' => 1,
]);
$shorthand = $cfg->toShorthand();
// → 'virtio,bridge=vmbr0,firewall=1'

$parsed = PveQemuNetConfig::fromShorthand($shorthand);

$req->setNets([
    0 => 'virtio,bridge=vmbr0',
    3 => 'e1000,bridge=vmbr1',
]);
// Wire format: { "net0": "virtio,bridge=vmbr0", "net3": "e1000,bridge=vmbr1" }