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.3.tar.gz (23.1 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.3-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xoadmin-1.2.3.tar.gz
  • Upload date:
  • Size: 23.1 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.3.tar.gz
Algorithm Hash digest
SHA256 1c1fc83a8e7fb48480c5737971b25b17b93b281978bd1bdafa2b003b1814d514
MD5 315ec3c23def83a739c39ff7a608c250
BLAKE2b-256 d34fa3167f2bb8579d26615c4e014cb12acd13e19a33ad323e80e4709afb8b1e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoadmin-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 30.5 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 26ed33f892828c6943eff001b21dc0d7bbe6b9c143b8f105aa48e323def3ab06
MD5 4020f851f7c8a2695a739ef334f3167e
BLAKE2b-256 8c1b7ba11648cba44c053cdce05ea13cfd5c1befd5415e7b2cdfce9bf349a2dd

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