PHP code example of enterpriseve / eve2pve-api-php
1. Go to this page and download the library: Download enterpriseve/eve2pve-api-php 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/ */
enterpriseve / eve2pve-api-php example snippets
Corsinvest\ProxmoxVE\Api\PveClient;
// Create client instance
$client = new PveClient("your-proxmox-host.com");
// Authenticate
if ($client->login('root@pam', 'password')) {
// Get cluster status
$status = $client->getCluster()->status();
echo "Cluster: {$status->getResponse()->data[0]->name}\n";
// List all VMs
$vms = $client->getNodes()->get("pve1")->getQemu()->vmlist();
foreach ($vms->getResponse()->data as $vm) {
echo "VM {$vm->vmid}: {$vm->name} - {$vm->status}\n";
}
}
// Create and configure a new VM with individual parameters (PHP 8.1+)
// Using named arguments (PHP 8.0+) for clarity
$result = $client->getNodes()->get("pve1")->getQemu()->createVm(
vmid: 100,
name: 'production-web-server',
memory: 4096,
cores: 4,
net0: 'virtio,bridge=vmbr0',
scsi0: 'local-lvm:32',
acpi: true,
balloon: 0,
cpu: 'host',
numa: false,
hotplug: 'network,disk,cpu,memory',
tags: 'production,web',
template: false
);
if ($result->isSuccessStatusCode()) {
echo "VM created successfully!\n";
// Start the VM
$startResult = $client->getNodes()->get("pve1")->getQemu()->get(100)->getStatus()->getStart()->vmStart();
if ($startResult->isSuccessStatusCode()) {
echo "VM started successfully!\n";
}
} else {
echo "Error creating VM: " . $result->getError() . "\n";
}