Skip to content

Commit

Permalink
Reimplemented result with dedicated class
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Oct 5, 2017
1 parent f459690 commit 6cf9fa7
Show file tree
Hide file tree
Showing 2 changed files with 1,865 additions and 1,617 deletions.
77 changes: 52 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
# eve2pve-api-php

ProxmoVE Client API PHP

General
------------
[ProxmoxVE Api](https://pve.proxmox.com/pve-docs/api-viewer/)

[Packagist](https://packagist.org/packages/enterpriseve/eve2pve-api-php)

```text
______ __ _ _ ________
/ ____/___ / /____ _________ _____(_)_______ | | / / ____/
/ __/ / __ \/ __/ _ \/ ___/ __ \/ ___/ / ___/ _ \ | | / / __/
/ /___/ / / / /_/ __/ / / /_/ / / / (__ ) __/ | |/ / /___
/_____/_/ /_/\__/\___/_/ / .___/_/ /_/____/\___/ |___/_____/
/_/
(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.
The result is a complete response from server.

[ProxmoxVE Api](https://pve.proxmox.com/pve-docs/api-viewer/)
## 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

Main features
------------
* Easy to learn
* Method named
* 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()->data
* $client->getNodes()->get("pve1")->getQemu()->get(100)->getSnapshot()->snapshotList()->getResponse()->data
* Return data proxmox
* Method result status
* getReasonPhrase
* Return result status
* getStatusCode
* getReasonPhrase
* isSuccessStatusCode
* Wait task finish task
* waitForTaskToFinish
* Method directry access
* get
* post
* put
* delete
* login return bool if access
* return object/array data
* Login return bool if access
* Return Result class more information
* return object/array data
* default object disable from client.setResultIsObject(false)

Installation
------------
## Installation

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

Expand All @@ -53,8 +81,7 @@ Or add this to your `composer.json` file:
}
```

Usage
-----
## Usage

```php
<?php
Expand All @@ -67,38 +94,38 @@ $client = new EnterpriseVE\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'));
var_dump($client->get('/version')->getResponse());

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

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

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

//loop vm
foreach ($client->getNodes()->get("pve1")->getQemu()->Vmlist()->data as $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()->data as $snap) {
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());
var_dump($client->getVersion()->version()->getResponse());

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

Expand All @@ -112,7 +139,7 @@ Sample output version request:

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

object(stdClass)#9 (1) {
["data"]=>
Expand Down Expand Up @@ -156,4 +183,4 @@ The parameter indexed end with '[n]' in documentation (method createVM in Qemu p
1 => "....",
3 => "....",
]
```
```
Loading

0 comments on commit 6cf9fa7

Please sign in to comment.