2017 © Pedro Peláez
 

library eve2pve-api-php

ProxmoVE Client API PHP

image

enterpriseve/eve2pve-api-php

ProxmoVE Client API PHP

  • Friday, May 18, 2018
  • by franklupo
  • Repository
  • 2 Watchers
  • 3 Stars
  • 58 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 9 Versions
  • 5 % Grown

The README.md

cv4pve-api-php

License Packagist Version Packagist Downloads (custom server), (*1)

Proxmox VE Client API PHP, (*2)

Proxmox VE Api, (*3)

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

Corsinvest for Proxmox VE Api Client  (Made in Italy)

Copyright: Corsinvest Srl For licensing details please visit LICENSE, (*4)

Commercial Support

This software is part of a suite of tools called cv4pve-tools. If you want commercial support, visit the site, (*5)

General

The client is generated from a JSON Api on Proxmox VE., (*6)

This PHP 5.4+ library allows you to interact with your Proxmox server via API. The client is generated from a JSON Api on Proxmox VE., (*7)

Result

The result is class Result and contain methods:, (*8)

  • getResponse() returned from Proxmox VE (data,errors,...) Object/Array
  • responseInError (bool) : Contains errors from Proxmox VE.
  • 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.
  • getResponseHeaders() (string) : Gets the raw HTTP headers associated with this response.

Main features

  • Easy to learn
  • No dependency external library only native curl
  • Implementation respect the Api structure of Proxmox VE
  • Method named
  • 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
    • Request
    • Response
    • Status
  • Wait task finish task
    • waitForTaskToFinish
    • taskIsRunning
    • getExitStatusTask
  • Method direct 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
  • Form Proxmox VE 6.2 support Api Token for user
  • Login with One-time password for Two-factor authentication.
  • Set Timeout for the Connection.

Api token

From version 6.2 of Proxmox VE is possible to use Api token. This feature permit execute Api without using user and password. If using Privilege Separation when create api token remember specify in permission. Format USER@REALM!TOKENID=TOKEN (Usage example below), (*9)

Installation

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

In the root of your project execute the following:, (*11)

composer require Corsinvest/cv4pve-api-php

Or add this to your composer.json, (*12)

Usage

<?php

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

//if you want use lite version only get/set/create/delete use PveClientBase

$client = new Corsinvest\ProxmoxVE\Api\PveClient("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'];

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

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

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

  //set connection timeout (by default no timeout)
  $client->setTimeout(2)->get('/version')->getResponse();
}

Sample output version request:, (*13)

//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, (*14)

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

Usage with API-token instead username/password

<?php

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

//if you want use lite version only get/set/create/delete use PveClientBase

$client = new Corsinvest\ProxmoxVE\Api\PveClient("hostname", "8006");
$client->setApiToken("root@pam!mytokenname=<TOKEN COMES HERE>");
echo $client->getVersion();

The Versions

18/05 2018

dev-master

9999999-dev

ProxmoVE Client API PHP

  Sources   Download

GPL 3 GPL-3.0-only

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

18/05 2018

v1.0.9

1.0.9.0

ProxmoVE Client API PHP

  Sources   Download

GPL-3.0-only

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

16/01 2018

v1.0.8

1.0.8.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

02/11 2017

v1.0.7

1.0.7.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

25/10 2017

v1.0.6

1.0.6.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

05/10 2017

v1.0.5

1.0.5.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

26/09 2017

v1.0.4

1.0.4.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

16/09 2017

v1.0.3

1.0.3.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve

12/09 2017

v1.0.2

1.0.2.0

ProxmoVE Client API PHP

  Sources   Download

GPL 3

The Requires

 

by Daniele Corsini

api lxc virtualization proxmox kvm proxmoxve enterpriseve