Code Monkey home page Code Monkey logo

proxmoxve's Introduction

ProxmoxVE API Client

This PHP 5.5+ library allows you to interact with your Proxmox server via API.

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

I'm not actively maintaining this library anymore (I've left PHP behind) but the API is pretty stable, if it doesn't suit your needs take a look at the forks or better yet create a PR to add the things you're missing, if you're interested I can transfer the project to you.

Looking for a PHP 5.3 library version? Search through the releases one that fits your needs, I recommend using the 2.1.1 version.

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 zzantares/proxmoxve ~4.0

Or add this to your composer.json file:

{
    "require": {
        "zzantares/proxmoxve": "~4.0"
    }
}

Then perform the installation:

$ composer install --no-dev

Usage

<?php

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

// Use the library namespace
use ProxmoxVE\Proxmox;

// Create your credentials array
$credentials = [
    'hostname' => 'proxmox.server.com',  // Also can be an IP
    'username' => 'root',
    'password' => 'secret',
];

// realm and port defaults to 'pam' and '8006' but you can specify them like so
$credentials = [
    'hostname' => 'proxmox.server.com',
    'username' => 'root',
    'password' => 'secret',
    'realm' => 'pve',
    'port' => '9009',
];

// Then simply pass your credentials when creating the API client object.
$proxmox = new Proxmox($credentials);

$allNodes = $proxmox->get('/nodes');

print_r($allNodes);

Sample output:

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [disk] => 2539465464
                    [cpu] => 0.031314446882002
                    [maxdisk] => 30805066770
                    [maxmem] => 175168446464
                    [node] => mynode1
                    [maxcpu] => 24
                    [level] =>
                    [uptime] => 139376
                    [id] => node/mynode1
                    [type] => node
                    [mem] => 20601992182
                )

        )

)

Using the MailGateway API

This library can be used to communicate with the Proxmox MailGateway API as well, by simply changing the system entry in the credentials array.

<?php

$credentials = [
    'hostname' => 'proxmox.server.com',  // Also can be an IP
    'username' => 'root',
    'password' => 'secret',
    'system' => 'pmg', // Defaults to 'pve' for the PVE API. Use 'pmg' for the PMG API.
];

Want to know more nifty tricks?

Checkout our wiki.

Docs

On your proxmox client object you can use get(), create(), set() and delete() functions for all resources specified at PVE2 API Documentation, params are passed as the second parameter in an associative array.

What resources or paths can I interact with and how?

In your proxmox server you can use the pvesh CLI Tool to manage all the pve resources, you can use this library in the exact same way you would use the pvesh tool. For instance you could run pvesh then, as the screen message should say, you can type help [path] [--verbose] to see how you could use a path and what params you should pass to it. Be sure to read about the pvesh CLI Tool at the Proxmox wiki.

How does the Proxmox API works?

Consult the ProxmoxVE API article at the Proxmox wiki.

I feel you're hiding some cool tricks! I need more docs!

See the project's wiki for a more detailed documentation, it's all in there I swear it... I think.

License

This project is released under the MIT License. See the bundled LICENSE file for details.

Want to contribute?

Thank you! Take a look at the CONTRIBUTING, you could easily set up a development environment to get you started in no time!

proxmoxve's People

Contributors

belcloud avatar gothshoot avatar keepwn avatar madmath03 avatar ramonsmit avatar skipworkgh avatar zzantares avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proxmoxve's Issues

Planning on any dependency updates?

Hi,

As I tried installing your bundle I got the following composer message:

$ composer require zzantares/proxmoxve
Using version ^3.0 for zzantares/proxmoxve
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for zzantares/proxmoxve ^3.0 -> satisfiable by zzantares/proxmoxve[v3.0.0].
    - Conclusion: remove guzzlehttp/guzzle 6.0.2
    - Conclusion: don't install guzzlehttp/guzzle 6.0.2
    - zzantares/proxmoxve v3.0.0 requires guzzlehttp/guzzle ~4.0 -> satisfiable by guzzlehttp/guzzle[4.0.0, 4.0.1, 4.0.2, 4.1.0, 4.1.1, 4.1.2, 4.1.3, 4.1.4, 4.1.5, 4.1.6, 4.1.7, 4.1.8, 4.2.0, 4.2.1, 4.2.2, 4.2.3].
    - Can only install one of: guzzlehttp/guzzle[4.0.0, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.0.1, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.0.2, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.0, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.1, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.2, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.3, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.4, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.5, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.6, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.7, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.1.8, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.2.0, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.2.1, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.2.2, 6.0.2].
    - Can only install one of: guzzlehttp/guzzle[4.2.3, 6.0.2].
    - Installation request for guzzlehttp/guzzle == 6.0.2.0 -> satisfiable by guzzlehttp/guzzle[6.0.2].

Are you planning on updating these dependencies any time soon ?

issue with OS template

hey can you brief me about the architecture for os templates which proxmox supports??

I mean does it support only "i386" and "amd64"? or it goes with x86_64 as well??

I am trying to create Openvz container using api but it does not identify the os template.
can you help me out...:)

Update guzzlehttp requirements

This wrapper currently requires guzzlehttp version 4 which is now unmaintained.
Updating to guzzlehttp to version 6, or at least 5, might be nice ;-)

V5 to revolution !

Hi everyone, I plan to completely revisit the way to use that library with more POO compliant usage where everythings is represented as object. 💥

You can provide help about that and suggest many change with more modern usage of PHP. 🚀

@zzantares If you authorize me to do that things ? 🙏

Fatal error: Class 'ProxmoxVE\Proxmox' not found

Using the dev branch, I'm getting Fatal error: Class 'ProxmoxVE\Proxmox' not found

use ProxmoxVE\Credentials;
use ProxmoxVE\Proxmox;

$creds = [
    'hostname' => $request->input('hostname'),
    'username' => $request->input('username'),
    'password' => $request->input('password'),
    'realm'    => $realm,
    'port'     => $port
];

$proxmox = new Proxmox($creds);

I'm showing the the namespace in autoload_psr4.php so not really sure why it's not loading.

Limit access to specific CA or SSL cert

Hello

Would it be possible to add an option to drop the connection if the proxmox's ssl certificate is not a specific one or does not belong to a specific CA?
Because if it accepts proxmox's self-signed certificate, it will accept any certificate in the case of a mitm attack.

Thank you

It's not work #27 is old post for this problem

Sorry, because it's not work :/
http://prntscr.com/jauyi8
This is my Code. The "new Proxmox" work, by the function loading information i become information becaus stop dont work (Login with root user)
http://prntscr.com/jauz7n Login data Loading work

Now http://prntscr.com/jauzhz i dont become true back and the server stop not.
equal is this by start. The type is LXC Proxmox version is "Virtual Environment 5.1-41"

Thanks for all answers and sorry for my bad english

Problem with method POST

Hi i have problem with sending post

my code:

$bot->proxmox->post("/nodes/".$bot->firstNode."/qemu/$vmid/status/reboot");

but Call to undefined method ProxmoxVE\Proxmox::post()

How i can send post data?

Guzzle ^7.0 support ?

Hello,

Possible to have a new release with guzzlehttp/guzzle in version ^7.0 ?
Many packages require them but your lib doesn't support over 6.5 😞

Thanks

no samples for 5.3 or 5.4

no sample page for using with php 5.3 or 5.4

create a wiki page on the howto for php 5.4 and php 5.3

I had to look back threw the history of readme.md to get it working...

Php version conflict

ProxmoxVE depends on guzzle 4 but guzzle 4 depends on php >=5.4 so ProxmoxVE doesn't run under php < 5.4.

Would it be possible to create a special ProxmoxVE version which depends on guzzle 3.8.1 ?

Thanks.

invalid format - invalid urlencoded string with SSH keys on qemu

Hey,

thanks for this great library. However I'm fighting about a rather minor issue.
Maybe I'm doing something wrong, but I will always get the following error:

invalid format - invalid urlencoded string: ssh-rsa+REDACTED : sshkeys

I use this code:

  public function updateVM($vm,$data = array(),$route = 'config')
  {
    // getNode
    $node=$this->getFreeNode();
    if($route == 'config')
    {
      $data=array_merge($data,$this->generateVMConfig($vm));
    }
    $return=$this->getProxmox()->set('nodes/'.$node->getName().'/qemu/'.$vm->getProxmoxId().'/'.$route,$data);
    if(isset($return['errors']))
    {
      foreach ($return["errors"] as $key => $error)
      {
        $this->appendMessage(new Message($error.': '.$key, "cluster", "failure"));
      }
      return false;
    }
    return true;
  }

Where $this->generateVMConfig returns an array with the VM configuration and merges it with an given array (in this case the ssh keys). So good, every config will be set, except for the SSH keys which I generate with that code:

public function setSSHKeys($vm)
  {
    foreach($vm->getProject()->getUsers() as $project_user)
    {
      if($project_user->getUser()->getSSHKeys())
      {
        foreach($project_user->getUser()->getSSHKeys() as $sshkey)
        {
          $config['sshkeys'] .= urlencode($sshkey->getSSHPublicKey()."\n");
        }
      }
    }
    return $this->updateVM($vm,$config);
  }

Even when I remove the "urlencode" function it returns me the same error.

Please help!

Detecting Http error

Hi,
first of all: thank you very much for your code!

I have a problem detecting http related errors.
In example, trying something like this:
print_r ($proxmox->set('/nodes/foo/qemu/200/config'. ['lock' => 'bar']));

I correctly get an error like:

Array
(    
    [errors] => Array
        (
            [lock] => value 'bar' does not have a value in the enumeration 'migrate, backup, snapshot, rollback'
        )
    
         [data] =>
)

The error in in response body so it's correctly parsed.

But if error is in response header, like this case:
print_r ($proxmox->set('/nodes/foo/qemuZZ/200/config'. ['lock' => 'bar']));
I get no error at all:

Array
(
    [data] =>
)

Am I missing something?
Regards,
Massimo

Timeout with GuzzleHttp

There's currently no timeout in the GuzzleHttp calls in this wrapper. That's not a big deal, but by default, GuzzleHttp waits indefinitely (or until your PHP gets killed).

We could probably consider adding an optional $timeout variable on the API calls, and pass it to the http calls ?

Problem with composer install

Hello, i got this error from composer:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package zzantares/proxmoxve No version set (parsed as 1.0.0) is satisfiable by zzantares/proxmoxve[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.


Installation failed, reverting ./composer.json to its original content.

PHP:

PHP 5.6.30 (cli) (built: Oct 29 2017 20:30:32) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

composer.json:

{
    "name": "zzantares/proxmoxve",
    "type": "library",
    "description": "A simple PHP 5.4+ Proxmox API client.",
    "keywords": ["Proxmox", "API", "KVM", "OpenVZ", "Virtualization"],
    "homepage": "https://github.com/ZzAntares/ProxmoxVE",
    "license": "MIT",

    "authors": [
        {
            "name": "César Muñoz",
            "email": "[email protected]",
            "role": "Developer"
        }
    ],

    "support": {
        "issues": "https://github.com/ZzAntares/ProxmoxVE/issues",
        "source": "https://github.com/ZzAntares/ProxmoxVE"
    },

    "require": {
        "php": ">=5.3.0",
        "lib-curl": "*",
        "guzzlehttp/guzzle": "~4.0",
        "zzantares/proxmoxve": "~3.0"
    },

    "require-dev": {
        "phpunit/phpunit": "~4.1",
        "squizlabs/php_codesniffer": "1.*"
    },

    "autoload": {
        "psr-4": {
            "ProxmoxVE\\": "src/"
        }
    }

}

how can i fix this issue?

Thanks.

DELETE request crashes when passing optional parameters

I perform a DELETE request using the library (version 4.1.0 installed via composer) in order to delete an existing virtual machine on my proxmox environment.

This is the request I am trying to perform (the screenshot is from my proxmox VM API documentation):
image

When I try to pass optional parameters in the associative array to the request, cURL crashes.
If no optional parameters are passed to the function (I tried to pass an empty array), the function succeeds.
The API URI inside the sprintf() function is correctly built. When the script runs its value is '/nodes/proxmox4/qemu/883', so the issue is not here.

This is the PHP 7.4 code I written:

$this->logger->info('Deleting the virtual machine and its related disks...');
        
$this->proxmox->delete(sprintf('/nodes/%s/qemu/%d', $deleteVm['node'], $deleteVm['vmid']), [
            'destroy-unreferenced-disks' => 1,
            'purge' => 1,
        ]);

This is the RuntimeException caught by the parent class, displayed as warning in the console:
image

VNC Trough the API

Hi there,

Thanks for developing this nice API wrapper! I'm very pleased with this!

I want to show the VNC client out of the Proxmox environment but get a 401 No Ticket and I don't really see what i'm doing wrong around here.

Would you mind to take a look at my code?

if($proxmox->login()) {
    $config = $proxmox->create('/nodes/vm-1/lxc/100/vncproxy');
    $websock = $proxmox->get('/nodes/vm-1/lxc/100/vncwebsocket',
        [
            'vncticket' => $config['data']['ticket'],
            'port'      => $config['data']['port'],
        ]);
    
    return '<iframe  src="https://my-server:8006/?console=lxc&novnc=1&node=vm-1&resize=scale&vmid=100&path=' . urlencode("api2/json/nodes/vm-1/lxc/100/vncwebsocket?port=" . $config['data']['port'] . "&vncticket=" . $config['data']['ticket']) . ' frameborder="0" scrolling="no" width="1024px" height="100%"></iframe>';
}

Thanks in advance!
Cheers,
Ramon

Do not display the password on login failure

The credentials __toString method display the password as clear text. This is used by Proxmox.login() if the login fails.

Even though it might look nice for debugging purposes, this is very unsecure if used as is in a production environment since passwords will be stored in the server logs.

The credentials class should never display its password.

issue with novice console

I'm trying to implement a basic page to acces at the novnc console.
But when I used the API "/api2/json/nodes/{node}/qemu/{vmid}/vncwebsocket"
the result like this:

{
    data: {
        port: "xxxx"
    }
}

So what else I need to do to show the noVNC popup from a VM ?

error 401: no ticket

Hi

i have proble with ticket and cookie system


<?php

/*
For the first you need:
1. Create User group "VNC" –> Datacenter / Permissions / Group
2. Create new user -> Datacenter / Permissions / Users - select Group: "VNC", Realm: pve
3. Create new Role -> Datacenter / Permissions / Roles - select Name: "VNC", Privilegies: VM.Console (only)
3. Add permision to access VM -> Datacenter / Node / VM / Permissions / Add Group Permissions - select Group: "VNC", Role: "VNC"
*/

require_once 'vendor/autoload.php';
use ProxmoxVE\Proxmox;



$host = 'X.x.x.x';
$node = 'node';
$vmid = '102';

$credentials = [
    'hostname'  => $host,
    'username'  => 'root',
    'password'  => 'XXXX'
];

$proxmox = new Proxmox($credentials);

if($login = $proxmox->login()) {
    // Get and save ticket
    $ticket = $login->getTicket();
    $config = $proxmox->create('/nodes/'.$node.'/qemu/'.$vmid.'/vncproxy', [
        'websocket' => 1 // Start websocket
    ]);
    $websock = $proxmox->get('/nodes/'.$node.'/qemu/'.$vmid.'/vncwebsocket', [
        'vncticket' => $ticket,
        'port'      => $config['data']['port'],

    ]);
    // Set Cookies (domain must be in same space that pve. Example: pve – pve1.your.com, host – auth.your.com, Set cookies to your.com)
    setcookie('PVEAuthCookie', $ticket , 0, '/', 'localhost:4000', false);

    $src_href = 'https://'.$host.':8006/?console=kvm&novnc=1&node='.$node.'&resize=1&vmid='.$vmid.'&path=api2/json/nodes/'.$node.'/qemu/'.$vmid.'/vncwebsocket/port/'.$config['data']['port'].'/vncticket/'.$ticket;
    echo '<iframe src="'.$src_href.'" frameborder="0" scrolling="no" width="800px" height="600px"></iframe>';
}

?>

i got 401 error i think this happend because i used spicial port 4000 but i dont know how fix it

Post method

Hello,

i use your API, because i need the Post method. Thats not exist :/.

$proxmox->set('/nodes/'.$node.'/lxc/'.$ProductVServerLXCAction->VServerProduct[$ProductVServerLXCAction->ProductID]['containerid'].'/status/stop',array());

I want start and stop Vserver because i need post.
Can you add this? Or give it a other function for this?

Response type: object

Cheers for the library, working great in laravel using the guzzle6 branch. I saw you had a placeholder for an object return type. Any plans to still add that in?

How auth user with PHP

Hello guys!
I'm trying to authenticate a user in all possible ways but I can't ... can you help me please? This is my current configuration (I paste the code here because it is long): https://pastebin.com/uCJ5XgFd .
That is, the system detects that the user exists, but when I try to connect to the VNC it tells me that there is no connection :(

issue in creating a vm

I tried you api it works fine...But when i was creating a OpenVZ container using create function the data is displayed, but somehow it does not create CT...:(...Can you provide some help

$vps_creation = $proxmox->create('/nodes/'.$nodename.'/openvz -vmid '.$params['vmid'].' -hostname '.$params['hostname'].' -storage '.$params['storage'].' -password '.$params['password'].' -ostemplate '.$params['ostemplate'].' -memory '.$params['memory'].' -swap '.$params['swap'].' -disk '.$params['disk'].' -cpus '.$params['cpus'].' -ip_address '.$params['ip_address'], $params);

This is the command i tried...

issue with php7.1

When use with php7.1 this error appear

Fatal error: Cannot use lexical variable $eventName as a parameter name in /www/vendor/guzzlehttp/guzzle/src/Event/Emitter.php on line 49

Will upgrade guzzlehttp/guzzle to latest statble fix this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.