zoedaemon / cv4pve-api-php

Proxmox VE Client API PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cv4pve-api-php

License Packagist Version Donate to this project using Paypal

ProxmoVE Client API PHP

ProxmoxVE Api

Packagist

Donations

If you like my work and want to support it, then please consider to deposit a donation through Paypal by clicking on the next button:

paypal

   ______                _                      __
  / ____/___  __________(_)___ _   _____  _____/ /_
 / /   / __ \/ ___/ ___/ / __ \ | / / _ \/ ___/ __/
/ /___/ /_/ / /  (__  ) / / / / |/ /  __(__  ) /_
\____/\____/_/  /____/_/_/ /_/|___/\___/____/\__/

Corsinvest for Proxmox VE Api Client  (Made in Italy)

General

The client is generated from a JSON Api on ProxmoxVE.

This PHP 5.4+ library allows you to interact with your Proxmox server via API. The client is generated from a JSON Api on ProxmoxVE.

Result

The result is class Result and contain methods:

  • getResponse() returned from ProxmoxVE (data,errors,...) Object/Array
  • responseInError (bool) : Contains errors from ProxmoxVE.
  • getStatusCode() (int) : Status code of the HTTP response.
  • getReasonPhrase() (string): The reason phrase which typically is sent by servers together with the status code.
  • isSuccessStatusCode() (bool) : Gets a value that indicates if the HTTP response was successful.
  • getError() (string) : Get error.

Main features

  • Easy to learn
  • No dependency external lybrary only native curl
  • Method named
  • Method no named rest (same parameters)
    • getRest
    • setRest
    • createRest
    • deleteRest
  • Set ResponseType json, png
  • Full method generated from documentation
  • Comment any method and parameters
  • Parameters indexed eg [n] is structured in array index and value
  • Tree structure
    • $client->getNodes()->get("pve1")->getQemu()->get(100)->getSnapshot()->snapshotList()->getResponse()->data
  • Return data proxmox
  • Return result status
    • getStatusCode
    • getReasonPhrase
    • isSuccessStatusCode
  • Wait task finish task
    • waitForTaskToFinish
    • taskIsRunning
    • getExitStatusTask
  • Method directry access
    • get
    • set
    • create
    • delete
  • Login return bool if access
  • Return Result class more information
  • Return object/array data
    • default object disable from client.setResultIsObject(false)
  • ClientBase lite function

Installation

Recommended installation is using [Composer], if you do not have [Composer] what are you waiting?

In the root of your project execute the following:

composer require Corsinvest/cv4pve-api-php ~1.0

Or add this to your composer.json file:

{
    "require": {
        "Corsinvest/cv4pve-api-php": "~1.0"
    }
}

Usage

<?php

// Require the autoloader
require_once 'vendor/autoload.php';

$client = new Corsinvest\ProxmoxVE\Api\Client("192.168.0.24");

//login check bool
if($client->login('root','password','pam')){
  //get version from get method
  var_dump($client->get('/version')->getResponse());

  // $client->put
  // $client->post
  // $client->delete

  $retPippo=$client->get("/pippo");
  echo "\n" . $retPippo->getStatusCode();
  echo "\n" . $retPippo->getReasonPhrase();

  //loop nodes
  foreach ($client->getNodes()->Index()->getResponse()->data as $node) {
    echo "\n" . $node->id;
  }

  //loop vm
  foreach ($client->getNodes()->get("pve1")->getQemu()->Vmlist()->getResponse()->data as $vm) {
      echo "\n" . $vm->vmid ." - " .$vm->name;
  }

  //loop snapshots
  foreach ($client->getNodes()->get("pve1")->getQemu()->get(100)->getSnapshot()->snapshotList()->getResponse()->data as $snap) {
    echo "\n" . $snap->name;
  }

  //return object
  var_dump($client->getVersion()->version()->getResponse());

  //disable return object
  $client->setResultIsObject(false);
  //return array
  $retArr = $client->getVersion()->version()->getResponse();
  var_dump($retArr);
  echo "\n" . $retArr['data']['release'];

  //eneble return objet
  $client->setResultIsObject(true);

  //image rrd
  $client->setResponseType('png');
  echo "<img src='{$client->getNodes()->get("pve1")->getRrd()->rrd('cpu','day')->getResponse()}' \>";

  //resewt json result
  $client->setResponseType('json');
  var_dump($client->get('/version')->getResponse());
}

Sample output version request:

//object result
var_dump($client->getVersion()->Version()->getResponse());

object(stdClass)#9 (1) {
  ["data"]=>
  object(stdClass)#32 (4) {
    ["version"]=>
    string(3) "5.0"
    ["release"]=>
    string(2) "31"
    ["keyboard"]=>
    string(2) "it"
    ["repoid"]=>
    string(8) "27769b1f"
  }
}

//disable return object
$client->setResultIsObject(false);

//array result
var_dump($client->getVersion()->Version());

array(1) {
  ["data"]=>
  array(4) {
    ["repoid"]=>
    string(8) "2560e073"
    ["release"]=>
    string(2) "32"
    ["version"]=>
    string(3) "5.0"
    ["keyboard"]=>
    string(2) "it"
  }
}

The parameter indexed end with '[n]' in documentation (method createVM in Qemu parameter ide) require array whit key and value

[
  1 => "....",
  3 => "....",
]

About

Proxmox VE Client API PHP

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%