new file: CHANGELOG.md
modified: README.md modified: support-provisioning-portal/assets/portal.css modified: support-provisioning-portal/assets/portal.js modified: support-provisioning-portal/includes/class-spp-activator.php modified: support-provisioning-portal/includes/class-spp-admin-page.php modified: support-provisioning-portal/includes/class-spp-http-proxmox-client.php modified: support-provisioning-portal/includes/class-spp-mock-proxmox-client.php new file: support-provisioning-portal/includes/class-spp-permissions.php modified: support-provisioning-portal/includes/class-spp-plugin.php modified: support-provisioning-portal/includes/class-spp-repository.php modified: support-provisioning-portal/includes/class-spp-rest-controller.php modified: support-provisioning-portal/includes/class-spp-shortcode.php modified: support-provisioning-portal/includes/interface-spp-proxmox-client.php modified: support-provisioning-portal/support-provisioning-portal.php
This commit is contained in:
@@ -17,6 +17,35 @@ final class SPP_Http_Proxmox_Client implements SPP_Proxmox_Client
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function list_templates(): array
|
||||
{
|
||||
$data = $this->request("/nodes/{$this->options['node']}/qemu", 'GET');
|
||||
$vms = is_array($data) ? $data : [];
|
||||
$templates = [];
|
||||
|
||||
foreach ($vms as $vm) {
|
||||
if (!is_array($vm) || empty($vm['template']) || empty($vm['vmid'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$templates[] = [
|
||||
'vmId' => (int) $vm['vmid'],
|
||||
'name' => isset($vm['name']) && $vm['name'] !== '' ? (string) $vm['name'] : 'template-' . (int) $vm['vmid'],
|
||||
'cpuCores' => max(1, (int) ($vm['cpus'] ?? 1)),
|
||||
'memoryMb' => $this->bytes_to_mb((int) ($vm['maxmem'] ?? 0)),
|
||||
'diskGb' => $this->bytes_to_gb((int) ($vm['maxdisk'] ?? 0)),
|
||||
'status' => isset($vm['status']) ? (string) $vm['status'] : 'unknown',
|
||||
];
|
||||
}
|
||||
|
||||
usort(
|
||||
$templates,
|
||||
static fn(array $left, array $right): int => strcasecmp((string) $left['name'], (string) $right['name'])
|
||||
);
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
public function clone_vm(array $input): array
|
||||
{
|
||||
$vm_id = (int) $this->request('/cluster/nextid', 'GET');
|
||||
@@ -86,6 +115,24 @@ final class SPP_Http_Proxmox_Client implements SPP_Proxmox_Client
|
||||
return array_values(array_unique($ips));
|
||||
}
|
||||
|
||||
private function bytes_to_mb(int $bytes): int
|
||||
{
|
||||
if ($bytes < 1) {
|
||||
return 1024;
|
||||
}
|
||||
|
||||
return max(128, (int) ceil($bytes / 1048576));
|
||||
}
|
||||
|
||||
private function bytes_to_gb(int $bytes): int
|
||||
{
|
||||
if ($bytes < 1) {
|
||||
return 8;
|
||||
}
|
||||
|
||||
return max(1, (int) ceil($bytes / 1073741824));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int|string> $body
|
||||
* @return mixed
|
||||
|
||||
Reference in New Issue
Block a user