From 4f78af9182a499ba9e90e4875278ff89fc8ba925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Schl=C3=A4pfer?= Date: Sat, 30 Sep 2023 08:09:32 +0200 Subject: [PATCH] Uses pve2-api-client package --- src/ProxmoxAuthentication.php | 6 +++--- src/ProxmoxServer.php | 14 +++++++------- src/ProxmoxVM.php | 14 +++++++------- src/Service.php | 6 ++++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/ProxmoxAuthentication.php b/src/ProxmoxAuthentication.php index 44bae86..6c6a487 100644 --- a/src/ProxmoxAuthentication.php +++ b/src/ProxmoxAuthentication.php @@ -37,7 +37,7 @@ public function prepare_pve_setup($server) $serveraccess = $this->find_access($server); // Create a new instance of the PVE2_API class with the server access details - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); // Attempt to log in to the server using the API if (!$proxmox->login()) { @@ -195,7 +195,7 @@ public function test_access($server) $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); // Create a new instance of the PVE2_API class with the server access details - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); // Attempt to log in to the server using the API if (!$proxmox->login()) { @@ -245,7 +245,7 @@ public function create_client_user($server, $client) $this->di['db']->store($clientuser); $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); if (!$proxmox->login()) { throw new \Box_Exception("Failed to connect to the server. create_client_user"); } diff --git a/src/ProxmoxServer.php b/src/ProxmoxServer.php index 840fb72..51f3ee4 100644 --- a/src/ProxmoxServer.php +++ b/src/ProxmoxServer.php @@ -36,7 +36,7 @@ public function test_connection($server) // Test if login $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); // check if tokenname and tokenvalue contain values by checking their content if (empty($server->tokenname) || empty($server->tokenvalue)) { if (!empty($server->root_user) && !empty($server->root_password)) { @@ -66,7 +66,7 @@ public function test_token_connection($server) // Test if login $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); // check if tokenname and tokenvalue contain values by checking their content if (empty($server->tokenname) || empty($server->tokenvalue)) { throw new \Box_Exception("Token Access Failed: No tokenname or tokenvalue provided"); @@ -188,7 +188,7 @@ public function getHardwareData($server) // Retrieve associated server $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { error_log("ProxmoxServer.php: getHardwareData: Login successful"); @@ -204,7 +204,7 @@ public function getStorageData($server) // Retrieve associated server $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $storage = $proxmox->get("/nodes/" . $server->name . "/storage"); return $storage; @@ -219,7 +219,7 @@ public function getAssignedResources($server) // Retrieve associated server $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $assigned_resources = $proxmox->get("/nodes/" . $server->name . "/qemu"); return $assigned_resources; @@ -235,7 +235,7 @@ public function getAvailableAppliances() $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $appliances = $proxmox->get("/nodes/" . $server->name . "/aplinfo"); return $appliances; @@ -249,7 +249,7 @@ public function getQemuTemplates($server) { $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $templates = $proxmox->get("/nodes/" . $server->name . "/qemu"); return $templates; diff --git a/src/ProxmoxVM.php b/src/ProxmoxVM.php index 8b416e8..681caba 100644 --- a/src/ProxmoxVM.php +++ b/src/ProxmoxVM.php @@ -96,7 +96,7 @@ public function delete($order, $model) // Connect to YNH API $serveraccess = $this->find_access($server); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $proxmox->post("/nodes/" . $model->node . "/" . $product_config['virt'] . "/" . $model->vmid . "/status/shutdown", array()); @@ -141,7 +141,7 @@ public function vm_info($order, $service) // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->get_version()) { $status = $proxmox->get("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/current"); // VM monitoring? @@ -170,7 +170,7 @@ public function vm_reboot($order, $service) // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $proxmox->post("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/shutdown", array()); $status = $proxmox->get("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/current"); @@ -217,7 +217,7 @@ public function vm_start($order, $service) // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $proxmox->post("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/start", array()); return true; @@ -242,7 +242,7 @@ public function vm_shutdown($order, $service) $clientuser = $this->di['db']->findOne('service_proxmox_users', 'server_id = ? and client_id = ?', array($server->id, $client->id)); //echo "D: ".var_dump($order); $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $settings = array( 'forceStop' => true @@ -278,9 +278,9 @@ public function vm_cli($order, $service) // The user enters the password to see the iframe: TBD //$password = 'test'; - //$proxmox = new PVE2_API($serveraccess, $client->id, $server->name, $password); + //$proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $client->id, $server->name, $password); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->view_tokenname, tokensecret: $clientuser->view_tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->view_tokenname, tokensecret: $clientuser->view_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { // Get VNC Web proxy ticket by calling /nodes/{node}/{type}/{vmid}/vncproxy diff --git a/src/Service.php b/src/Service.php index d76144e..08288c3 100644 --- a/src/Service.php +++ b/src/Service.php @@ -18,11 +18,13 @@ namespace Box\Mod\Serviceproxmox; +require __DIR__ . '/vendor/autoload.php'; + use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; -use PVE2APIClient\PVE2APIClient\PVE2_API; use PDO; +use \PVE2APIClient\PVE2_API as PVE2_API; /** * Proxmox module for FOSSBilling @@ -688,7 +690,7 @@ public function activate($order, $model) // find client permissions for server $clientuser = $this->di['db']->findOne('service_proxmox_users', 'server_id = ? and client_id = ?', array($server->id, $client->id)); $config = $this->di['mod_config']('Serviceproxmox'); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); + $proxmox = new \PVE2APIClient\PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); // Create Proxmox VM if ($proxmox->login()) {