Skip to main content

an object-oriented Xen API for python

Project description

XEN Bridge

An object-oriented Xen API for python

Tested on XCP-ng, but should also work on XenServer

Usage

from xenbridge import XenConnection

xen = XenConnection('http://XEN_HOSTNAME', 'root', 'password')

xoa_vm = xen.VM.get_by_uuid('UUID_OF_VM')
# Or by name-label:
# xoa_vm = xen.VM.get_by_name_label('XOA')[0]

print(f'{xoa_vm.name_label} ({xoa_vm.uuid})')
print(f'VM is a template: {xoa_vm.is_a_template}')
xoa_vm.name_description = 'This is a VM'
xoa_vm.start()      # Spin up the VM

How it works

Firstly, xenboject.py defines some helper functions and baseclasses for the endpoints that do the actual work of calling the XMLRPC API and casting the data to the corresponding types.

For each class, there is a file corresponding to that class - for example, vm.py. In here, a class that defines the methods and properties can be found. All methods are wrapped using the @XenMethod decorator that copies the function's signature and replaces its functionality.

class VM(XenObject):
    @XenMethod
    def start(self, start_paused: bool, force: bool) -> None:
        """Start the specified VM.  This function can only be called with the VM is in the
        Halted State."""
    power_state: VmPowerState = XenProperty(XenProperty.READONLY)

As the API responds with a string for numbers, enums and Xen objects, the return type annotations are used to cast the objects to the correct type.

The XenConnection class is the object that is used to interact with the API

Missing methods

All API methods are generated from the XenAPI documentation using docscraper.py. If there is a method that is missing, you can either:

  • Add it to the corresponding class in the module yourself
  • Call it using the class's call(methodname, *args) method and manually cast it to the correct data type

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

xen-bridge-0.1.tar.gz (52.6 kB view details)

Uploaded Source

File details

Details for the file xen-bridge-0.1.tar.gz.

File metadata

  • Download URL: xen-bridge-0.1.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for xen-bridge-0.1.tar.gz
Algorithm Hash digest
SHA256 df201b09cd0aa749d7d6ce125165b0cc9ec684bfaa68b91bb7ef7f9fa542859a
MD5 a2488d343380ed42515aa4f2491c0c5b
BLAKE2b-256 08a0ffb7101bf4073c21af8d3324af013fddde63daf2fc084ef7f042edec1d92

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