XEN Bridge
An object-oriented Xen API for python
Tested on XCP-ng, but should also work on XenServer
Install from pypi using pip install xen-bridge
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
Exceptions
While calling API methods, XEN might return an error. When this happens, a XenError is raised. When catching the exception, the error code can be accessed through the error_code attribute
# Assuming VM is already running:
try:
xoa_vm.start() # Should throw an error
except xenbridge.XenError as e:
print(e.error_code) # Prints 'VM_BAD_POWER_STATE'
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
Metadata
Release files for xen-bridge 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xen-bridge-0.2.tar.gz | 56.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xen_bridge-0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 157.1 kB
Release files / xen-bridge-0.2.tar.gz
| Download URL | xen-bridge-0.2.tar.gz |
|---|---|
| Size | 56.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26d9a3fa5303ef9a89e8225d761fd26eb28ff00790b4a1812528d6fc63f8fd33
|
|
BLAKE2b-256 checksum How to use checksums |
2247d0acfb389438bde3ae1d416b7a07e2e8aae0934118561582cbc5161e73c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / xen_bridge-0.2-py3-none-any.whl
| Download URL | xen_bridge-0.2-py3-none-any.whl |
|---|---|
| Size | 101.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37ea4b952f8e9447224d3143e5b1a5d1a9d1dc4aceea73ebb704635ea2f07587
|
|
BLAKE2b-256 checksum How to use checksums |
43c7f49d1f5681bf80c09ccacb1d5593bf6b154b054e12b9111525581ea6c286
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for xen-bridge 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.