• How to return all data with xo-cli without limits

    Solved
    5
    0 Votes
    5 Posts
    49 Views
    olivierlambertO
    On it. Thanks
  • How to expand a VM disk using xo-cli?

    7
    0 Votes
    7 Posts
    56 Views
    E
    @Gurve Oh wow that's neat! It works! very cool we can use the same query search from the GUI. Thank you.
  • Python help

    26
    0 Votes
    26 Posts
    460 Views
    G
    @Studmuffn1134 should be available in XO vm, it was atleast for me, I just used the XO installer script from github. I did a quick search with xo cli now xo-cli list-commands | egrep 'host.' in case it looks weird "\." is just to escape the "." which just tells regex I am looking for an actual "." import aiohttp import asyncio from jsonrpc_websocket import Server async def routine(): async with aiohttp.ClientSession() as client: server = Server('ws://[yourXO]/api/', client) await server.ws_connect() # signIn required result = await server.session.signIn(username='[yourXOusername]', password='[yourXOPassword]') # email attribute is working in place of username #hard shutdown VM #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(1))) #clean Shutdown VM #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(0))) #bypassbackup and bypassevacuate set off by default but include for wholeness of parameters result = await server.host.stop(id=[hostUUID],bypassBackupCheck=(bool(0)),bypassEvacuate=bool(0)) print (result) asyncio.get_event_loop().run_until_complete(routine()) I just built all examples into one, here in the end is the host.stop example also
  • Delete VM Snapshot over REST

    Solved
    7
    0 Votes
    7 Posts
    93 Views
    R
    @Danp Thanks! Finally I was able to get my script working. Also some contribution to "GROK" who assisted quite well! It allows a VM to Snapshot itself, before running automated maintenance over cron. And it allows minimalistic retention of the snapshots created this way. Happy to share it with the community: #!/bin/bash : <<'END' Snapshot Management Script for Xen Orchestra Usage: ./snapshot-vm.sh [OPTIONS] Options: -v Enable verbose output (detailed logging) -s Silent mode (suppress all non-error output) -r <number> Set retention limit (delete oldest snapshots beyond this number) -n No-snapshot mode (skip snapshot creation, only manage retention) Examples: ./snapshot-vm.sh # Create a snapshot, no retention ./snapshot-vm.sh -v -r 3 # Create a snapshot, keep latest 3, verbose ./snapshot-vm.sh -r 5 -n # Skip snapshot, keep latest 5 ./snapshot-vm.sh -v -s -r 2 # Create a snapshot, keep latest 2, verbose but silent Configuration: Edit XO_URL, TOKEN, and SNAPSHOT_PREFIX at the top of the script. END # Configuration variables XO_URL="http://your-xen-orchestra-server" TOKEN="your-authentication-token" VM_UUID=$(dmidecode -s system-uuid | tr '[:upper:]' '[:lower:]') SNAPSHOT_PREFIX="AutoMaintenance" # Prefix for snapshot names # Default retention (no deletion if not specified) RETENTION=-1 # Flags VERBOSE=0 SILENT=0 NOSNAPSHOT=0 # Parse command-line options while getopts "vsr:n" opt; do case $opt in v) VERBOSE=1;; s) SILENT=1;; r) RETENTION="$OPTARG";; n) NOSNAPSHOT=1;; esac done # Function to print messages based on mode print_msg() { if [ $SILENT -eq 0 ]; then if [ $VERBOSE -eq 1 ]; then echo "$1" else echo -e "$1" fi fi } # Check if we got the UUID if [ -z "$VM_UUID" ]; then echo "Error: Could not retrieve system UUID" exit 1 fi # Function to check if jq is installed check_jq() { if ! command -v jq &> /dev/null; then echo "Error: jq is required but not installed" exit 1 fi } # Function to get VM name get_vm_name() { local vm_info=$(curl -s -X GET \ -b "authenticationToken=$TOKEN" \ -H "Accept: application/json" \ "$XO_URL/rest/v0/vms/$VM_UUID") vm_name=$(echo "$vm_info" | jq -r '.name_label // "Unknown"') } # Function to trigger snapshot trigger_snapshot() { local SNAPSHOT_NAME="${SNAPSHOT_PREFIX}-$(date +%Y%m%d-%H%M%S)" if [ $VERBOSE -eq 1 ]; then local curl_cmd="curl -s -X POST \ -b \"authenticationToken=$TOKEN\" \ -H \"Content-Type: application/json\" \ -H \"Accept: application/json\" \ -d '{\"name_label\": \"$SNAPSHOT_NAME\"}' \ \"$XO_URL/rest/v0/vms/$VM_UUID/actions/snapshot\"" print_msg "Executing snapshot trigger command:" print_msg "$curl_cmd" print_msg "-----" fi response=$(curl -s -X POST \ -b "authenticationToken=$TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d "{\"name_label\": \"$SNAPSHOT_NAME\"}" \ "$XO_URL/rest/v0/vms/$VM_UUID/actions/snapshot") if [ $VERBOSE -eq 1 ]; then print_msg "Snapshot trigger response: $response" print_msg "-----" fi if [[ "$response" =~ /rest/v0/tasks/([a-z0-9]+) ]]; then task_id="${BASH_REMATCH[1]}" if [ $VERBOSE -eq 1 ]; then print_msg "Snapshot triggered (Task ID: $task_id)" fi return 0 elif [[ "$response" =~ ^[a-z0-9]+$ ]]; then task_id="$response" if [ $VERBOSE -eq 1 ]; then print_msg "Snapshot triggered (Task ID: $task_id)" fi return 0 else print_msg "Error: Failed to get task ID. Response: $response" exit 1 fi } # Function to monitor task status monitor_task() { local task_id=$1 local max_attempts=30 local attempt=1 if [ $VERBOSE -eq 1 ]; then print_msg "Monitoring task $task_id..." fi while [ $attempt -le $max_attempts ]; do status_response=$(curl -s -X GET \ -b "authenticationToken=$TOKEN" \ -H "Accept: application/json" \ "$XO_URL/rest/v0/tasks/$task_id") if [ $VERBOSE -eq 1 ]; then print_msg "Attempt $attempt - Raw response: $status_response" fi if [ -n "$status_response" ] && echo "$status_response" | jq -e . >/dev/null 2>&1; then status=$(echo "$status_response" | jq -r '.status') if [ $VERBOSE -eq 1 ]; then print_msg "Status: $status" else print_msg "Taking Snapshot of VM: $vm_name... Status: $status" fi case "$status" in "pending"|"running") if [ $VERBOSE -eq 1 ]; then print_msg "Task still in progress" fi sleep 5 ((attempt++)) ;; "success") if [ $VERBOSE -eq 1 ]; then print_msg "Snapshot completed successfully" else print_msg "Taking Snapshot of VM: $vm_name... Status: Completed" fi return 0 ;; "failure") error=$(echo "$status_response" | jq -r '.result.message // "Unknown error"') print_msg "Task failed: $error" exit 1 ;; *) if [ $VERBOSE -eq 1 ]; then print_msg "Unknown status: $status" fi sleep 5 ((attempt++)) ;; esac else if [ $VERBOSE -eq 1 ]; then print_msg "Invalid or empty response" fi sleep 5 ((attempt++)) fi done print_msg "Timeout waiting for task completion" exit 1 } # Function to manage snapshot retention manage_retention() { if [ $RETENTION -lt 0 ]; then print_msg "Retention not specified, skipping cleanup" return 0 fi # Get VM data with snapshot UUIDs vm_data=$(curl -s -X GET \ -b "authenticationToken=$TOKEN" \ -H "Accept: application/json" \ "$XO_URL/rest/v0/vms/$VM_UUID") if [ $VERBOSE -eq 1 ]; then print_msg "Raw VM data response: $vm_data" print_msg "-----" fi if ! echo "$vm_data" | jq -e . >/dev/null 2>&1; then print_msg "Error: Invalid JSON response from VM endpoint" print_msg "Response: $vm_data" exit 1 fi # Extract snapshot UUIDs snapshot_uuids=$(echo "$vm_data" | jq -r '.snapshots[]') # Fetch details for each snapshot, verify existence, and filter by prefix auto_snapshots="" for uuid in $snapshot_uuids; do # Check existence with a HEAD request to avoid full body download http_status=$(curl -s -o /dev/null -w "%{http_code}" -I \ -b "authenticationToken=$TOKEN" \ "$XO_URL/rest/v0/vm-snapshots/$uuid") if [ "$http_status" -eq 404 ]; then if [ $VERBOSE -eq 1 ]; then print_msg "Snapshot $uuid does not exist (HTTP 404), skipping" print_msg "-----" fi continue elif [ "$http_status" -ne 200 ]; then if [ $VERBOSE -eq 1 ]; then print_msg "Unexpected HTTP status $http_status for snapshot $uuid, skipping" print_msg "-----" fi continue fi # Fetch full snapshot data if it exists snapshot_data=$(curl -s -X GET \ -b "authenticationToken=$TOKEN" \ -H "Accept: application/json" \ "$XO_URL/rest/v0/vm-snapshots/$uuid") if [ $VERBOSE -eq 1 ]; then print_msg "Snapshot $uuid data: $snapshot_data" print_msg "-----" fi # Verify it’s a valid JSON response if ! echo "$snapshot_data" | jq -e . >/dev/null 2>&1; then print_msg "Error: Invalid JSON response for snapshot $uuid" print_msg "Response: $snapshot_data" continue fi # Filter for snapshots with the specified prefix if echo "$snapshot_data" | jq -e ".name_label | startswith(\"$SNAPSHOT_PREFIX\")" >/dev/null 2>&1; then snapshot_line=$(echo "$snapshot_data" | jq -r '[.id, .name_label, .snapshot_time] | join("\t")') auto_snapshots="$auto_snapshots$snapshot_line\n" fi done # Sort by snapshot_time auto_snapshots=$(echo -e "$auto_snapshots" | sort -k3 -n | grep -v '^$') if [ $VERBOSE -eq 1 ]; then print_msg "Filtered and sorted $SNAPSHOT_PREFIX snapshots:" print_msg "$auto_snapshots" print_msg "-----" fi # Count current snapshots snapshot_count=$(echo "$auto_snapshots" | wc -l) print_msg "Current $SNAPSHOT_PREFIX snapshot count: $snapshot_count" # If over retention limit, delete oldest if [ $snapshot_count -gt $RETENTION ]; then excess=$((snapshot_count - RETENTION)) print_msg "Excess snapshots to delete: $excess" # Get IDs of oldest snapshots to delete delete_ids=$(echo "$auto_snapshots" | head -n $excess | cut -f1) for id in $delete_ids; do if [ $VERBOSE -eq 1 ]; then print_msg "Deleting snapshot $id" print_msg "Delete command: curl -s -X DELETE -b \"authenticationToken=$TOKEN\" \"$XO_URL/rest/v0/vm-snapshots/$id\"" fi delete_response=$(curl -s -X DELETE \ -b "authenticationToken=$TOKEN" \ "$XO_URL/rest/v0/vm-snapshots/$id") if [ $VERBOSE -eq 1 ]; then print_msg "Delete response: $delete_response" print_msg "-----" fi # Treat empty response, {"status": "success"}, or "OK" as success if [ -z "$delete_response" ] || echo "$delete_response" | jq -e '.status == "success"' >/dev/null 2>&1 || [ "$delete_response" = "OK" ]; then print_msg "Successfully deleted snapshot $id" else print_msg "Warning: Failed to delete snapshot $id. Response: $delete_response" fi done else if [ $VERBOSE -eq 1 ]; then print_msg "No excess snapshots to delete" fi fi } # Main execution check_jq get_vm_name if [ $VERBOSE -eq 1 ]; then print_msg "Using VM UUID: $VM_UUID" fi if [ $NOSNAPSHOT -eq 0 ]; then trigger_snapshot monitor_task "$task_id" else if [ $VERBOSE -eq 1 ]; then print_msg "Skipping snapshot creation due to --nosnapshot flag" fi fi manage_retention exit 0 Cheers!
  • 0 Votes
    4 Posts
    51 Views
    lsouai-vatesL
    @arckhox Hello! I don't know if it is what you are looking for but in REST API doc I founded this: https://github.com/vatesfr/xen-orchestra/blob/master/packages/xo-server/docs/rest-api.md#task-monitoring "A watch mode is available when fetching the collection as NDJSON by using both ndjson and watch query strings. Instead of sending the objects directly, each entry will be an array [event, object]. event can be either remove to mean that an object has been removed from the collection or update to mean that an object has been added to the collection or updated. In case of the remove event, only the id properties of the deleted object is available. The fields and filter parameters are supported."
  • create a new vm using a iso setting cpu ram network via api

    6
    0 Votes
    6 Posts
    76 Views
    M
    @nathanael-h thanks for info i used https://github.com/ddelnano/packer-plugin-xenserver but because of lack of ssh key support i changed the code a bit. now i can use ssh keys. (not ready for a PR) my problem is that inside the auto iso i use a shell script doing a reboot within the install. the reason is that i use this iso also on bare metal installations, some software i cant install without doing a reboot. i will now focus on the ansible integratian an fire the commands after the reboot using ansible. this might work. br Mark
  • 0 Votes
    14 Posts
    113 Views
    J
    @jcharles said in How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?: Thanks that worked. I give that a go thanks Your welcome.
  • VM Console Access

    15
    2
    0 Votes
    15 Posts
    465 Views
    olivierlambertO
    Hi, No, there's only one console, which is the "virtual screen" of the VM. If you want multi user thing, check VDI solution, like UDS Enterprise https://docs.xcp-ng.org/project/ecosystem/#uds-enterprise
  • vm-templates query param support

    6
    1
    0 Votes
    6 Posts
    92 Views
    I
    @MathieuRA @Danp Thank you so much
  • REST API for simple User

    Solved
    2
    3
    0 Votes
    2 Posts
    75 Views
    MathieuRAM
    Hi @irtaza9. The REST API is only available for admin users. It is planned to handle other types of users in a few months
  • User specific data

    Solved
    19
    0 Votes
    19 Posts
    346 Views
    I
    @MathieuRA user-id bg: when you call session.signIn you get the user-id and that id is used to fetch user specific vms. { "id": -9007199254740991, "jsonrpc": "2.0", "result": { "id": "f2858952-b02a-403a-98ca-d94e4cdaa57e", "email": "testirtaza1", "groups": [], "permission": "none", "preferences": {} } } [image: 1739959932713-f4b361d6-6944-4cf4-96c2-7f79c9735ebe-image.png] @olivierlambert yes, issue is resolved. Thanks to @MathieuRA and @Danp
  • Dynamically Pool Selection criteria

    12
    0 Votes
    12 Posts
    211 Views
    B
    @irtaza9 OK so you have VLANs per DC. That means VLAN5 in KPK-DC1 and VLAN5 in RWP-DC4 are unrelated and machines in those VLANs cannot communicate directly without going trough some router? This goes back to my original answer. You have to take into account network connectivity when deciding what DC/pool to select for VM provisioning. If you have a few VMs in VLAN5 in KPK-DC1 and you decide to provision some more VMs at latter time that require direct connectivity with existing VMs, you have no choice but to provision them in VLAN5 in KPK-DC1. Regarding VLANs in general, this is all fine except you can scale it up to a few thousand of VLANs per DC so it will impose a hard limit on the number of isolated network segments (i.e. users/customers). Some weapon of choice among most cloud providers is to use some kind of network overlay like VX-LANs, GRE tunnels and such but this has issues of it's own. For a start, these kinds of networks are software defined in nature (SDN), require an orchestrator and network nodes that run in software. You can leverage some hardware acceleration here and there but it will still be software oriented and have scaling and latency issues. There is no silver bullet and most providers hide their network implementation details. All in all, a good, scalable and fast networking i probably the toughest thing to implement in any large scale cloud provider... and I'm definitely not a network engineer so I can't say much about it .
  • VM creation progress

    9
    0 Votes
    9 Posts
    193 Views
    I
    @bufanda yes I have checked that feature too. Let me dig further to make it useable for my use case.
  • XOA Lose connection to entire pool

    4
    0 Votes
    4 Posts
    92 Views
    C
    @benutop - We see that all the time, its purely cosmetic it seems. I think it has to do with XO recognizing your permissions as a user. We have other users constantly using our environment so we know XO is not actually disconnecting.
  • REST auth in Postman

    Solved
    3
    1
    0 Votes
    3 Posts
    113 Views
    J
    @Danp Yup, that will do it. Thanks. No longer pulling out my hair.
  • VIF via REST API?

    8
    0 Votes
    8 Posts
    148 Views
    olivierlambertO
    Ping @julien-f
  • Network creation on the pool using xo-cli

    2
    0 Votes
    2 Posts
    170 Views
    DanpD
    @Pix FYI, I was just doing some testing on this exact function and I was able to add a network to the pool when using the UUID for the host's matching PIF. The UUID you were using is from the pool's network, which won't work here. For example -- Networks [17:29 xenserver-slnqfzrh ~]# xe network-list uuid ( RO) : a379a6e7-f099-f838-6514-486de4d56e80 name-label ( RW): Pool-wide network associated with eth0 name-description ( RW): bridge ( RO): xenbr0 uuid ( RO) : b14a0bdd-2f77-25f7-3a76-b830ff971624 name-label ( RW): Pool-wide network associated with eth2 name-description ( RW): bridge ( RO): xenbr2 uuid ( RO) : 00b6604f-9098-023b-5880-0ef9f8e1b437 name-label ( RW): Pool-wide network associated with eth1 name-description ( RW): bridge ( RO): xenbr1 uuid ( RO) : e3be0e1a-9872-4b90-c851-35eb30a86920 name-label ( RW): Pool-wide network associated with eth3 name-description ( RW): bridge ( RO): xenbr3 uuid ( RO) : c54ecffe-9467-5d5f-cb73-ec10dedef2b9 name-label ( RW): Host internal management network name-description ( RW): Network on which guests will be assigned a private link-local IP address which can be used to talk XenAPI bridge ( RO): xenapi PIFs [17:49 xenserver-slnqfzrh ~]# xe pif-list network-uuid=00b6604f-9098-023b-5880-0ef9f8e1b437 uuid ( RO) : ea3edc31-9b23-402c-a65e-2316c88febb5 device ( RO): eth1 currently-attached ( RO): true VLAN ( RO): -1 network-uuid ( RO): 00b6604f-9098-023b-5880-0ef9f8e1b437 uuid ( RO) : 3a1ef416-787f-45b4-ace9-0147c2f3ca07 device ( RO): eth1 currently-attached ( RO): true VLAN ( RO): -1 network-uuid ( RO): 00b6604f-9098-023b-5880-0ef9f8e1b437 Adding a VLAN [18:27 21] xoa:xoa$ xo-cli network.create pool=63b7154a-1a6c-8642-525e-c6abb0acc941 name="VLAN20 - On Eth1" pif=ea3edc31-9b23-402c-a65e-2316c88febb5 vlan=json:20 52d18dc6-8078-a7ce-4bc5-d4337d2fb970 HTH, Dan
  • Grafana Xen Orchestra

    2
    0 Votes
    2 Posts
    131 Views
    olivierlambertO
    Hi, Can you describe the target/objective you want to achieve/expect?
  • 0 Votes
    6 Posts
    314 Views
    S
    @pxn said in Java SDK, XmlRpcClientException: Failed to parse server's response: Duplicate name: restrict_vtpm: If you still encounter this issue - I found the way to bypass it. You can create your own mapper by extending on RecursiveTypeParserImpl and just copy-paste logic from MapParser (package org.apache.xmlrpc.parser;), except that logic of checking duplication, then you can inject custom parser to your custom factory (Extend TypeFactoryImpl and override getParser method). And inject this Factory to your client new XmlRpcClient().setTypeFactory(new CustomFactory(client)); This works fine for me, I hope this could help you. Alex
  • how to query users and there vms there own

    11
    0 Votes
    11 Posts
    207 Views
    olivierlambertO
    Yes, you can have a list of all available calls by doing xo-cli list-commands