Skip to main content

bindings and wrappers to manage an XOA instance

Project description

xoadmin

xoadmin is an asynchronous Python client for interacting with Xen Orchestra's REST API and WebSocket. It enables the management of VMs, users, storage, and more, through Xen Orchestra.

  • Authenticate via WebSocket.
  • Perform operations on VMs.
  • Manage users, including creating and deleting users.
  • Handle storage operations like listing storage repositories (SRs) and managing Virtual Disk Images (VDIs).

Installation

To use the XO Admin Library, ensure you have Python 3.9+ installed.

  1. From Source: Clone and install the package from source
git clone https://github.com/elnissi-io/xoadmin.git
pip install .
  1. From pip: Simple pip install
pip install xoadmin

Quick Start

  1. Initialize the XOAManager with the base URL of your Xen Orchestra instance:
from xoadmin.api.manager import XOAManager

manager = XOAManager(host="your-xo-instance-host", verify_ssl=False)
  1. Authenticate using your Xen Orchestra credentials:
await manager.authenticate(username="your-username", password="your-password")
  1. Now, you can perform various operations through the manager:
vms = await manager.list_all_vms()
print(vms)

Ensure you run your script in an environment that supports asynchronous execution, like:

import asyncio

asyncio.run(main())

Documentation

Currently a work in progress.

For more detailed information on available methods and their usage, refer to the source code in the src/xoadmin directory. Each module (vm.py, user.py, storage.py) contains classes with methods corresponding to the Xen Orchestra functionalities they manage.

Command Line Interface (CLI)

Usage: xoadmin [OPTIONS] COMMAND [ARGS]...

  XOA Admin CLI tool for managing Xen Orchestra instances.

Options:
  --help  Show this message and exit.

Commands:
  apply    Apply configuration to Xen Orchestra instances.
  auth     Authentication management commands.
  config   Configuration management commands.
  host     Manage hosts.
  storage  Storage management commands.
  user     Manage users.
  vm       VM management commands.

The XO Admin Library provides a Command Line Interface (CLI) to simplify interaction with Xen Orchestra. Here's how you can use it:

  1. Installation: Install either from source or using pip:

  2. Authentication: Initialize the XOAManager with the base URL of your Xen Orchestra instance and authenticate using your credentials:

    In a container environment for instance:

    xoadmin config generate
    

    This will display a copyable config file you could manually create in ~/.xoadmin/config.

    Alternatively, you could tell it to write it to a file using --output <filepath>

    xoadmin config generate --output ~/.xoadmin/config
    

    xoadmin config generate will tell you which environment variables were not defined, you could then manually define the values needed under the config file

    ➜ xoadmin git:(main) ✗ xoadmin config generate -o test.yml
    XOA configuration generated and saved to test.yml.
    # No environment variables were found.
    # Environment variables not defined (using defaults):
    # - XOA_HOST
    # - XOA_REST_API
    # - XOA_WEBSOCKET
    # - XOA_USERNAME
    # - XOA_PASSWORD
    # - XOA_VERIFY_SSL
    
  3. Performing Operations: You can now perform various operations using the CLI.

    The cli utilizes a config file under ~/.xoadmin/config

    xoa:
      host: localhost
      ws_url: ws://localhost
      rest_api: http://localhost:80
      verify_ssl: false
      password: admin
      username: admin@admin.net
    

    List vms

    xoadmin vm list
    

    List users

    xoadmin user list
    

    List hosts

    xoadmin host list
    

Applying a Configuration

xoadmin allows you to quickly add hosts and users to an XOA instance using a YAML file:

  1. Create a YAML file with your desired configuration settings. For example:

    hypervisors:
      - host: 192.168.0.1
        username: root
        password: password
        allowUnauthorized: true
    
    users:
      - username: user
        password: password
        permission: admin
    
  2. Apply the configuration using the apply command:

    xoadmin apply -f config.yaml
    

Module Usage

You can also integrate the XO Admin Library directly into your Python scripts for more customized usage. Here's an example of how you can do this:

import asyncio
from xoadmin.api.manager import XOAManager

async def main():
    # Initialize XOAManager
    manager = XOAManager(
        host="localhost",
        rest_api="http://localhost:80",
        websocket="ws://localhost",
        verify_ssl=False
    )
    
    # Authenticate
    await manager.authenticate(username="admin@admin.net", password="admin")

    # Perform operations
    vms = await manager.list_all_vms()
    print(vms)

    # Close session
    await manager.close()
import asyncio
from xoadmin.api.api import XOAPI

async def main():
    api = XOAPI(
                rest_base_url="http://localhost:80", # without /rest
                ws_url="ws://localhost",
                verify_ssl=True,
            )

    await api.authenticate_with_websocket(
        "admin@admin.net",
        "admin",
    )

Contributing and License

Contributions to the XO Admin Library are welcome! Please feel free to submit pull requests or open issues to discuss new features or improvements. This project is licensed under the Apache 2.0 License. For more details, refer to the LICENSE file.

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

xoadmin-1.2.2.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xoadmin-1.2.2-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file xoadmin-1.2.2.tar.gz.

File metadata

  • Download URL: xoadmin-1.2.2.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.8.18 Linux/6.5.0-1016-azure

File hashes

Hashes for xoadmin-1.2.2.tar.gz
Algorithm Hash digest
SHA256 1ae91ce79404979e318e0a73afb58c2227606e602c17b18d424ea9f85d73bbdb
MD5 63f7931208b9f2f0e32fbdbdbcf5cf29
BLAKE2b-256 fe8b20374e0da98d55b2066f9ac3019305d49659a0fadc4e605a29dc40ba05ba

See more details on using hashes here.

File details

Details for the file xoadmin-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: xoadmin-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.8.18 Linux/6.5.0-1016-azure

File hashes

Hashes for xoadmin-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d04801324e592399f1ecd0a1891da956ac2db71386ee56c5c1ef19f53df22d09
MD5 efa8f3ead3109842c46e2af9dbfc54e2
BLAKE2b-256 93dbc2cc13ee58ea5bf13ee9f8c092cdbbf4b19760b1b50e6488d0616b2bd2d9

See more details on using hashes here.

Supported by

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