DevOps Team

Private

Posts

  • RE: DevOps Megathread: what you need and how we can help!

    @Tristis-Oris
    Hello, thanks for the report. I will try to fix and improve things, but before I have a few questions.

    • What is the template you are using? Is it one from XOA Hub?
    • Where did you found the cloud-init config snippets?

    For your information, the defaults cloud-init configs snippets come from here: https://github.com/vatesfr/xen-orchestra/blob/master/packages/xo-web/src/common/cloud-config.js#L78-L88

    For growpart it depends of the template used. Last time I tested it was working with a Debian 12 template from the XOA Hub.

  • RE: create a new vm using a iso setting cpu ram network via api

    @markxc said in create a new vm using a iso setting cpu ram network via api:

    Out of curiosity: how do you handle the Xen Orchestra appliance installation?

    We use Packer, a Debian iso and an Ansible playbook in the ansible provisioner. See https://developer.hashicorp.com/packer/integrations/hashicorp/ansible/latest/components/provisioner/ansible

    With this setup, we achieve these tasks:

    • Create VM, mount ISO, perform install, and detect when installation is complete
    • Shut down the VM
    • Export VM as an OVA template

    We also have a CI/CD pipeline doing this automatically.

  • RE: Python help

    Hi @Studmuffn1134,

    You’re right—some actions (like certain host operations) aren’t fully available in the REST API yet. Right now, most "GET" methods work, and some actions (like those for VMs and snapshots) are implemented. However, the REST API is still a work in progress.

    The Xen Orchestra team is currently focusing on:

    • Non-admin user management (coming soon).

    • Save/backup functionality (planned for the next few months).

    Since not everything is ready in REST yet, you might need to use both REST and JSON-RPC to access all operations.

    For JSON-RPC, check out:

    Official JSON-RPC Documentation

    Basic JSON-RPC Examples (Forum Discussion)

  • RE: Pulumi Xen Orchestra - News

    Release v1.5.2

    The provider is now available on the Pulumi official Registry 😎

    https://www.pulumi.com/registry/packages/xenorchestra/

    We added example for Yaml in the documentation.

    Full Release Note: https://github.com/vatesfr/pulumi-xenorchestra/releases/tag/v1.5.2

  • RE: Python help

    Hello @Studmuffn1134, welcome!

    The provided python code will resembled yes however the path will be specific to the type and actions you need to perform. Also the returned payload will also be different.
    You can find bellow some informations that can help you understand and use the Xen Orchestra API.

    Here is a summary provided when searching with google about REST APIs patterns:

    Understanding REST: A Guide to API Design Patterns

    REST (Representational State Transfer) is a widely-used software architectural style that defines how APIs should be designed. It emphasizes simplicity, scalability, and efficiency, making it a popular choice for building web services and applications. REST APIs use standard HTTP methods (such as GET, POST, PUT, and DELETE) to interact with resources, which are identified by URLs. This approach makes REST APIs intuitive and easy to work with.

    To get the most out of REST, it’s important to understand its patterns and conventions. These patterns will not only improve your foundational knowledge but also help you interact with APIs.

    REST API Path Structure

    A typical REST API path follows a structured format, often resembling this pattern:

    http://host_or_domain_name/<types>/<id>/<action_verb>
    

    Here’s a breakdown of the components:

    • <types>: Represents the type of resource you’re interacting with (e.g., vms, users, networks).

    • <id>: A unique identifier for a specific resource (e.g., a VM ID or user ID).

    • <action_verb>: Specifies the action to be performed on the resource (e.g., actions, start, stop).

    HTTP Methods in REST

    REST APIs use specific HTTP methods to perform operations on resources:

    • GET: Retrieves data. For example, fetching a list of resources or details of a specific resource.

    • POST: Creates a new resource.

    • PUT: Replaces or updates an entire resource.

    • PATCH: Updates specific parts of a resource.

    • DELETE: Removes a resource.

    Example: REST API Paths for Virtual Machines (VMs)
    Let’s look at some examples using a vms resource type:

    List all VMs:

    GET http://host/rest/v0/vms
    

    This returns a list of VM IDs.

    Get details of a specific VM:

    GET http://host/rest/v0/vms/<id>
    

    This returns detailed information about the VM with the specified ID.

    List available actions for a VM:

    GET http://host/rest/v0/vms/<id>/actions
    

    This returns all actions that can be performed on the specified VM (e.g., start, stop, reboot).

    Perform an action on a VM:

    POST http://host/rest/v0/vms/<id>/actions/<your-action>
    

    This performs the specified action (e.g., start, stop) on the VM.

    Exploring Available REST Endpoints
    If you’re working with a REST API like Xen Orchestra, you can explore the available endpoints by navigating to the base URL in your browser or using a tool like Postman. For example:

    GET http://host/rest/v0
    

    This will return a list of available resource types and operations, such as:

    [
      "/rest/v0/hosts",
      "/rest/v0/messages",
      "/rest/v0/networks",
      "/rest/v0/pifs",
      "/rest/v0/pools",
      "/rest/v0/srs",
      "/rest/v0/vbds",
      "/rest/v0/vdi-snapshots",
      "/rest/v0/vdis",
      "/rest/v0/vifs",
      "/rest/v0/vm-controllers",
      "/rest/v0/vm-snapshots",
      "/rest/v0/vm-templates",
      "/rest/v0/vms",
      "/rest/v0/backup",
      "/rest/v0/groups",
      "/rest/v0/restore",
      "/rest/v0/tasks",
      "/rest/v0/servers",
      "/rest/v0/users",
      "/rest/v0/dashboard",
      "/rest/v0/alarms",
      "/rest/v0/docs"
    ]
    

    From here, you can follow the REST patterns described above to query specific resources or perform actions.

    Hope this help! 🙂

  • RE: Python help

    Hi there @Studmuffn1134 ,

    I've looked at your code and identified a few issues:

    1. You're trying to use basic auth (username/password), but Xen Orchestra's API typically uses token authentication through cookies
    2. You're making a GET request to the base URL instead of a specific API endpoint
    3. You're not using the /vms/{vm_id}/actions/hard_shutdown or /vms/{vm_id}/actions/clean_shutdown endpoints

    I was able to call successfully the shutdown endpoints but with verify off. Also FYI, I was using a lab and I did not build it from source however if you are using the latest version the API should be available.

    Link for the swagger documentation is: http://host/rest/v0/docs/

    #!/usr/bin/env python3
    
    import requests
    import os
    import sys
    from urllib3.exceptions import InsecureRequestWarning
    
    # Disable insecure HTTPS warnings.
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    
    def shutdown_vm(vm_id, xo_url, auth_token, use_force=True):
        action = "hard_shutdown" if use_force else "clean_shutdown"
    
        endpoint = f"{xo_url}/rest/v0/vms/{vm_id}/actions/{action}"
        
        print(f"Sending {action} request for VM {vm_id}...")
        
        headers = {
            'Cookie': f'authenticationToken={auth_token}',
            'Content-Type': 'application/json'
        }
        
        try:
            response = requests.post(
                endpoint,
                headers=headers,
                verify=False
            )
            
            print(f"Status code: {response.status_code}")
            
            if response.status_code in [200, 202, 204]:
                print(f"✓ Successfully initiated {'force' if use_force else 'clean'} shutdown")
                return True
            else:
                print(f"Error: {response.text}")
                return False
                
        except requests.exceptions.RequestException as e:
            print(f"Request failed: {e}")
            return False
    
    VM_ID = 'your_vm_id_here'
    XO_URL = 'https://your_xo_url_here'
    # You can navigate to the XO GUI and in the user section create an auth token. 
    AUTH_TOKEN = 'your_auth_token_here'
    
    shutdown_vm(VM_ID, XO_URL, AUTH_TOKEN)
    

    I hope it will help you fix the issue on your side. Please let me know if I can help with anything else.

  • RE: DevOps Megathread: what you need and how we can help!

    Hello,
    If you want to discuss the Pulumi Provider in detail, let discuss here: https://xcp-ng.org/forum/topic/10592/pulumi-xen-orchestra-news

Member List