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
87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
final class SPP_Mock_Proxmox_Client implements SPP_Proxmox_Client
|
|
{
|
|
public function list_templates(): array
|
|
{
|
|
return [
|
|
[
|
|
'vmId' => 9001,
|
|
'name' => 'Turnkey PBX Test Appliance',
|
|
'cpuCores' => 2,
|
|
'memoryMb' => 2048,
|
|
'diskGb' => 24,
|
|
'status' => 'stopped',
|
|
],
|
|
[
|
|
'vmId' => 9002,
|
|
'name' => 'Windows Support Client',
|
|
'cpuCores' => 4,
|
|
'memoryMb' => 8192,
|
|
'diskGb' => 80,
|
|
'status' => 'stopped',
|
|
],
|
|
[
|
|
'vmId' => 9003,
|
|
'name' => 'Linux Utility VM',
|
|
'cpuCores' => 2,
|
|
'memoryMb' => 2048,
|
|
'diskGb' => 32,
|
|
'status' => 'stopped',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function clone_vm(array $input): array
|
|
{
|
|
$next_id = (int) get_option('spp_mock_next_vm_id', 10000);
|
|
update_option('spp_mock_next_vm_id', $next_id + 1, false);
|
|
update_option('spp_mock_vm_status_' . $next_id, 'stopped', false);
|
|
update_option('spp_mock_vm_ips_' . $next_id, [sprintf('192.0.2.%d', (($next_id - 10000) % 200) + 10)], false);
|
|
|
|
return ['vm_id' => $next_id];
|
|
}
|
|
|
|
public function start_vm(int $vm_id): void
|
|
{
|
|
$this->ensure_vm($vm_id);
|
|
update_option('spp_mock_vm_status_' . $vm_id, 'running', false);
|
|
}
|
|
|
|
public function stop_vm(int $vm_id): void
|
|
{
|
|
$this->ensure_vm($vm_id);
|
|
update_option('spp_mock_vm_status_' . $vm_id, 'stopped', false);
|
|
}
|
|
|
|
public function delete_vm(int $vm_id): void
|
|
{
|
|
$this->ensure_vm($vm_id);
|
|
delete_option('spp_mock_vm_status_' . $vm_id);
|
|
delete_option('spp_mock_vm_ips_' . $vm_id);
|
|
}
|
|
|
|
public function get_status(int $vm_id): string
|
|
{
|
|
return (string) get_option('spp_mock_vm_status_' . $vm_id, 'unknown');
|
|
}
|
|
|
|
public function get_ip_addresses(int $vm_id): array
|
|
{
|
|
$ips = get_option('spp_mock_vm_ips_' . $vm_id, []);
|
|
|
|
return is_array($ips) ? array_values(array_map('strval', $ips)) : [];
|
|
}
|
|
|
|
private function ensure_vm(int $vm_id): void
|
|
{
|
|
if (get_option('spp_mock_vm_status_' . $vm_id, null) === null) {
|
|
throw new RuntimeException('Mock Proxmox VM does not exist.');
|
|
}
|
|
}
|
|
}
|