Skip to main content

Python Wrapper for the Proxmox 2.x API (HTTP and SSH)

Project description

What does it do and what’s different?

Proxmoxer is a wrapper around the Proxmox REST API v2.

It was inspired by slumber, but it dedicated only to Proxmox. It allows to use not only REST API over HTTPS, but the same api over ssh and pvesh utility.

Like Proxmoxia it dynamically creates attributes which responds to the attributes you’ve attempted to reach.

Installation

pip install proxmoxer

For ‘https’ backend install requests

pip install requests

For ‘ssh_paramiko’ backend install paramiko

pip install paramiko

Short usage information

The first thing to do is import the proxmoxer library and create ProxmoxAPI instance.

from proxmoxer import ProxmoxAPI
proxmox = ProxmoxAPI('proxmox_host', user='admin@pam',
                     password='secret_word', verify_ssl=False)

This will connect by default through the ‘https’ backend.

It is possible to use already prepared public/private key authentication. It is possible to use ssh-agent also.

from proxmoxer import ProxmoxAPI
proxmox = ProxmoxAPI('proxmox_host', user='proxmox_admin', backend='ssh_paramiko')

Please note, https-backend needs ‘requests’ library, and ssh_paramiko-backend needs ‘paramiko’ library installed.

Queries are exposed via the access methods get, post, put and delete. For convenience added two synonyms: create for post, and set for put.

for node in proxmox.nodes.get():
    for vm in proxmox.nodes(node['node']).openvz.get()):
        print "{0}. {1} => {2}" .format(vm['vmid'], vm['name'], vm['status'])

>>> 141. puppet-2.london.baseblack.com => running
    101. munki.london.baseblack.com => running
    102. redmine.london.baseblack.com => running
    140. dns-1.london.baseblack.com => running
    126. ns-3.london.baseblack.com => running
    113. rabbitmq.london.baseblack.com => running

same code can be rewritten in the next way:

for node in proxmox.get('nodes'):
    for vm in proxmox.get('nodes/%s/openvz' % node['node']):
        print "%s. %s => %s" %  (vm['vmid'], vm['name'], vm['status'])

for example next lines do the same job:

proxmox.nodes(node['node']).openvz.get()
proxmox.nodes(node['node']).get('openvz')
proxmox.get('nodes/%s/openvz' % node['node'])
proxmox.get('nodes', node['node'], 'openvz')

Some more examples:

node = proxmox.nodes('proxmox_node')
pprint(node.storage('local').content.get())

or the with same results

node = proxmox.nodes.proxmox_node()
pprint(node.storage.local.content.get())

Example of creation of openvz container:

node = proxmox.nodes('proxmox_node')
node.openvz.create(vmid=202,
                   ostemplate='local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz',
                   hostname='turnkey',
                   storage='local',
                   memory=512,
                   swap=512,
                   cpus=1,
                   disk=4,
                   password='secret',
                   ip_address='10.0.0.202')

Example of template upload:

local_storage = proxmox.nodes('proxmox_node').storage('local')
local_storage.upload.create(content='vztmpl',
    filename=open(os.path.expanduser('~/templates/debian-6-my-core_1.0-1_i386.tar.gz'))))

Example of rrd download:

response = proxmox.nodes('proxmox').rrd.get(ds='cpu', timeframe='hour')
with open('cpu.png', 'wb') as f:
    f.write(response['image'].encode('raw_unicode_escape'))

Roadmap

  • write tests

  • add optional validation of requests

  • add some shortcuts for convenience

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proxmoxer-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file proxmoxer-0.1.1.tar.gz.

File metadata

  • Download URL: proxmoxer-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for proxmoxer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6e1c45593223adf3c0120f91be4e7b117574bad445a81fbcca82232c4775aeac
MD5 a8cd2cb8f47e806e05cb86dd0393d2b2
BLAKE2b-256 d22d3a25d610cf71b84e72a2f01fbeddbeab5fb6f68c6e9236a30b796af4e7ca

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page