Skip to content

Commit

Permalink
Uses pve2-api-client package
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Schläpfer committed Sep 30, 2023
1 parent a4d3f5a commit 4f78af9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/ProxmoxAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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");
}
Expand Down
14 changes: 7 additions & 7 deletions src/ProxmoxServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/ProxmoxVM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 4f78af9

Please sign in to comment.