Skip to content

Commit

Permalink
Fix index parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Oct 9, 2019
1 parent 886408f commit e267d09
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 64 deletions.
92 changes: 46 additions & 46 deletions src/PveClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function __construct($hostname, $port = 8006) {
* @param string $name name
* @param array $values values
*/
public static function addIndexedParameter(&$params, $name, $values) {
public function addIndexedParameter(&$params, $name, $values) {
if ($values == null) {
return;
}
Expand Down Expand Up @@ -643,7 +643,7 @@ public function createRest($clustername, $linkN = null, $nodeid = null, $votes =
$params = ['clustername' => $clustername,
'nodeid' => $nodeid,
'votes' => $votes];
$this->addIndexedParameter($params, 'link', $linkN);
$this->client->addIndexedParameter($params, 'link', $linkN);
return $this->client->create("/cluster/config", $params);
}

Expand Down Expand Up @@ -758,7 +758,7 @@ public function createRest($force = null, $linkN = null, $nodeid = null, $votes
$params = ['force' => $force,
'nodeid' => $nodeid,
'votes' => $votes];
$this->addIndexedParameter($params, 'link', $linkN);
$this->client->addIndexedParameter($params, 'link', $linkN);
return $this->client->create("/cluster/config/nodes/{$this->node}", $params);
}

Expand Down Expand Up @@ -831,7 +831,7 @@ public function createRest($fingerprint, $hostname, $password, $force = null, $l
'force' => $force,
'nodeid' => $nodeid,
'votes' => $votes];
$this->addIndexedParameter($params, 'link', $linkN);
$this->client->addIndexedParameter($params, 'link', $linkN);
return $this->client->create("/cluster/config/join", $params);
}

Expand Down Expand Up @@ -4707,18 +4707,18 @@ public function createRest($vmid, $acpi = null, $agent = null, $arch = null, $ar
'vmgenid' => $vmgenid,
'vmstatestorage' => $vmstatestorage,
'watchdog' => $watchdog];
$this->addIndexedParameter($params, 'hostpci', $hostpciN);
$this->addIndexedParameter($params, 'ide', $ideN);
$this->addIndexedParameter($params, 'ipconfig', $ipconfigN);
$this->addIndexedParameter($params, 'net', $netN);
$this->addIndexedParameter($params, 'numa', $numaN);
$this->addIndexedParameter($params, 'parallel', $parallelN);
$this->addIndexedParameter($params, 'sata', $sataN);
$this->addIndexedParameter($params, 'scsi', $scsiN);
$this->addIndexedParameter($params, 'serial', $serialN);
$this->addIndexedParameter($params, 'unused', $unusedN);
$this->addIndexedParameter($params, 'usb', $usbN);
$this->addIndexedParameter($params, 'virtio', $virtioN);
$this->client->addIndexedParameter($params, 'hostpci', $hostpciN);
$this->client->addIndexedParameter($params, 'ide', $ideN);
$this->client->addIndexedParameter($params, 'ipconfig', $ipconfigN);
$this->client->addIndexedParameter($params, 'net', $netN);
$this->client->addIndexedParameter($params, 'numa', $numaN);
$this->client->addIndexedParameter($params, 'parallel', $parallelN);
$this->client->addIndexedParameter($params, 'sata', $sataN);
$this->client->addIndexedParameter($params, 'scsi', $scsiN);
$this->client->addIndexedParameter($params, 'serial', $serialN);
$this->client->addIndexedParameter($params, 'unused', $unusedN);
$this->client->addIndexedParameter($params, 'usb', $usbN);
$this->client->addIndexedParameter($params, 'virtio', $virtioN);
return $this->client->create("/nodes/{$this->node}/qemu", $params);
}

Expand Down Expand Up @@ -8184,18 +8184,18 @@ public function createRest($acpi = null, $agent = null, $arch = null, $args = nu
'vmgenid' => $vmgenid,
'vmstatestorage' => $vmstatestorage,
'watchdog' => $watchdog];
$this->addIndexedParameter($params, 'hostpci', $hostpciN);
$this->addIndexedParameter($params, 'ide', $ideN);
$this->addIndexedParameter($params, 'ipconfig', $ipconfigN);
$this->addIndexedParameter($params, 'net', $netN);
$this->addIndexedParameter($params, 'numa', $numaN);
$this->addIndexedParameter($params, 'parallel', $parallelN);
$this->addIndexedParameter($params, 'sata', $sataN);
$this->addIndexedParameter($params, 'scsi', $scsiN);
$this->addIndexedParameter($params, 'serial', $serialN);
$this->addIndexedParameter($params, 'unused', $unusedN);
$this->addIndexedParameter($params, 'usb', $usbN);
$this->addIndexedParameter($params, 'virtio', $virtioN);
$this->client->addIndexedParameter($params, 'hostpci', $hostpciN);
$this->client->addIndexedParameter($params, 'ide', $ideN);
$this->client->addIndexedParameter($params, 'ipconfig', $ipconfigN);
$this->client->addIndexedParameter($params, 'net', $netN);
$this->client->addIndexedParameter($params, 'numa', $numaN);
$this->client->addIndexedParameter($params, 'parallel', $parallelN);
$this->client->addIndexedParameter($params, 'sata', $sataN);
$this->client->addIndexedParameter($params, 'scsi', $scsiN);
$this->client->addIndexedParameter($params, 'serial', $serialN);
$this->client->addIndexedParameter($params, 'unused', $unusedN);
$this->client->addIndexedParameter($params, 'usb', $usbN);
$this->client->addIndexedParameter($params, 'virtio', $virtioN);
return $this->client->create("/nodes/{$this->node}/qemu/{$this->vmid}/config", $params);
}

Expand Down Expand Up @@ -8439,18 +8439,18 @@ public function setRest($acpi = null, $agent = null, $arch = null, $args = null,
'vmgenid' => $vmgenid,
'vmstatestorage' => $vmstatestorage,
'watchdog' => $watchdog];
$this->addIndexedParameter($params, 'hostpci', $hostpciN);
$this->addIndexedParameter($params, 'ide', $ideN);
$this->addIndexedParameter($params, 'ipconfig', $ipconfigN);
$this->addIndexedParameter($params, 'net', $netN);
$this->addIndexedParameter($params, 'numa', $numaN);
$this->addIndexedParameter($params, 'parallel', $parallelN);
$this->addIndexedParameter($params, 'sata', $sataN);
$this->addIndexedParameter($params, 'scsi', $scsiN);
$this->addIndexedParameter($params, 'serial', $serialN);
$this->addIndexedParameter($params, 'unused', $unusedN);
$this->addIndexedParameter($params, 'usb', $usbN);
$this->addIndexedParameter($params, 'virtio', $virtioN);
$this->client->addIndexedParameter($params, 'hostpci', $hostpciN);
$this->client->addIndexedParameter($params, 'ide', $ideN);
$this->client->addIndexedParameter($params, 'ipconfig', $ipconfigN);
$this->client->addIndexedParameter($params, 'net', $netN);
$this->client->addIndexedParameter($params, 'numa', $numaN);
$this->client->addIndexedParameter($params, 'parallel', $parallelN);
$this->client->addIndexedParameter($params, 'sata', $sataN);
$this->client->addIndexedParameter($params, 'scsi', $scsiN);
$this->client->addIndexedParameter($params, 'serial', $serialN);
$this->client->addIndexedParameter($params, 'unused', $unusedN);
$this->client->addIndexedParameter($params, 'usb', $usbN);
$this->client->addIndexedParameter($params, 'virtio', $virtioN);
return $this->client->set("/nodes/{$this->node}/qemu/{$this->vmid}/config", $params);
}

Expand Down Expand Up @@ -10453,9 +10453,9 @@ public function createRest($ostemplate, $vmid, $arch = null, $bwlimit = null, $c
'tty' => $tty,
'unique' => $unique,
'unprivileged' => $unprivileged];
$this->addIndexedParameter($params, 'mp', $mpN);
$this->addIndexedParameter($params, 'net', $netN);
$this->addIndexedParameter($params, 'unused', $unusedN);
$this->client->addIndexedParameter($params, 'mp', $mpN);
$this->client->addIndexedParameter($params, 'net', $netN);
$this->client->addIndexedParameter($params, 'unused', $unusedN);
return $this->client->create("/nodes/{$this->node}/lxc", $params);
}

Expand Down Expand Up @@ -10894,9 +10894,9 @@ public function setRest($arch = null, $cmode = null, $console = null, $cores = n
'template' => $template,
'tty' => $tty,
'unprivileged' => $unprivileged];
$this->addIndexedParameter($params, 'mp', $mpN);
$this->addIndexedParameter($params, 'net', $netN);
$this->addIndexedParameter($params, 'unused', $unusedN);
$this->client->addIndexedParameter($params, 'mp', $mpN);
$this->client->addIndexedParameter($params, 'net', $netN);
$this->client->addIndexedParameter($params, 'unused', $unusedN);
return $this->client->set("/nodes/{$this->node}/lxc/{$this->vmid}/config", $params);
}

Expand Down
29 changes: 19 additions & 10 deletions src/PveClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,25 @@ function login($userName, $password, $realm = "pam") {
$userName = $uData[0];
$realm = $uData[1];
}

$oldResultIsObject = $this->getResultIsObject();
$this->setResultIsObject(true);
$params = ['password' => $password, 'username' => $userName, 'realm' => $realm];

$params = [
'password' => $password,
'username' => $userName,
'realm' => $realm
];

$result = $this->create("/access/ticket", $params);
$this->setResultIsObject($oldResultIsObject);

if ($result->isSuccessStatusCode()) {
$this->ticketCSRFPreventionToken = $result->getResponse()->data->CSRFPreventionToken;
$this->ticketPVEAuthCookie = $result->getResponse()->data->ticket;
return true;
}

return false;
}

Expand Down Expand Up @@ -252,26 +261,26 @@ private function executeAction($resource, $method, $parameters = []) {
$prox_ch = curl_init();
switch ($method) {
case "GET":
$action_postfields_string = http_build_query($params);
$url .= '?' . $action_postfields_string;
unset($action_postfields_string);
$action_postfields = http_build_query($params);
$url .= '?' . $action_postfields;
unset($action_postfields);
$methodType = "GET";
break;

case "PUT":
curl_setopt($prox_ch, CURLOPT_CUSTOMREQUEST, "PUT");
$action_postfields_string = http_build_query($params);
curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $action_postfields_string);
unset($action_postfields_string);
$action_postfields = http_build_query($params);
curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $action_postfields);
unset($action_postfields);
curl_setopt($prox_ch, CURLOPT_HTTPHEADER, $headers);
$methodType = "SET";
break;

case "POST":
curl_setopt($prox_ch, CURLOPT_POST, true);
$action_postfields_string = http_build_query($params);
curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $action_postfields_string);
unset($action_postfields_string);
$action_postfields = http_build_query($params);
curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $action_postfields);
unset($action_postfields);
curl_setopt($prox_ch, CURLOPT_HTTPHEADER, $headers);
$methodType = "CREATE";
break;
Expand Down
13 changes: 5 additions & 8 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class Result {
*/
private $methodType;

/**
/**
* @ignore
*/
private $responseType;

/**
* @ignore
*/
Expand All @@ -89,26 +89,23 @@ function __construct($response,

/**
* Request method type
*
* @return
* @return string
*/
function getMethodType() {
return $this->methodType;
}

/**
* Response type
*
* @return
* @return string
*/
function getResponseType() {
return $this->responseType;
}

/**
* Resource request
*
* @return
* @return string
*/
function getRequestResource() {
return $this->requestResource;
Expand Down

0 comments on commit e267d09

Please sign in to comment.