### Install Hugo and Go on Ubuntu Source: https://github.com/xapi-project/xen-api/blob/master/doc/README.md Instructions for installing Hugo and Go on Ubuntu systems. It recommends using the snap package for Hugo and provides commands for installing a specific Go version and Hugo from source. ```bash sudo snap install hugo ``` ```bash sudo apt install golang-1.23-go # Add it to your path, assuming your .local/bin/ is early in your PATH: ln -s /usr/lib/go-1.23/bin/go ~/.local/bin/go go version go install github.com/gohugoio/hugo@v0.127.0 ``` -------------------------------- ### XenServer SDK Examples Repository Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/powershell/autogen/README_51.md Links to a GitHub repository containing examples to help users get started with the XenServer SDK, which can be applied to the PowerShell module. ```APIDOC XenServer SDK Examples: Repository: https://github.com/xenserver/xenserver-samples ``` -------------------------------- ### Python VM Start Operation Example Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xen-api/wire-protocol.md Provides an example of attempting to start a VM using the 'VM.start' method. It includes error handling to catch exceptions, such as when trying to start a VM that is a template. ```python try: jsonrpccall("VM.start", (session, next(all_templates), False, False)) except Exception as e: e ``` -------------------------------- ### XenAPI Example Script Requirements Source: https://github.com/xapi-project/xen-api/blob/master/python3/examples/README.md Explains the prerequisites for running example scripts. The scripts require either the XenAPI.py file in the same directory or the XenAPI package installed via pip. ```text The [examples](https://github.com/xapi-project/xen-api/tree/master/scripts/examples/python) will not work unless they have been placed in the same directory as `XenAPI.py` or `XenAPI` package from PyPI has been installed (`pip install XenAPI`) ``` -------------------------------- ### Install Debian Etch VM using Xen API Source: https://github.com/xapi-project/xen-api/blob/master/scripts/examples/bash-cli/README.md Demonstrates a simple example of installing Debian Etch 4.0 from a pre-existing VM template using the Xen API. ```bash # Example for installing Debian Etch 4.0 VM # Assumes a VM template named 'Debian Etch 4.0' exists xen-create-vm --template "Debian Etch 4.0" --name "MyDebianVM" ``` -------------------------------- ### XenAPI SDK Examples Repository Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/README.md A repository containing examples for the XenAPI SDK in multiple programming languages is available to help users get started. ```general # Examples repository: # https://github.com/xenserver/xenserver-samples ``` -------------------------------- ### Install XenAPI Package Source: https://github.com/xapi-project/xen-api/blob/master/python3/examples/README.md Installs the XenAPI Python package. Ensure you have a virtual environment enabled before running the command. ```bash pip install XenAPI ``` -------------------------------- ### Install and Run Pre-commit Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/python/_index.md Commands to install the pre-commit framework and run all configured hooks for testing and code quality checks. This ensures a consistent development environment. ```Bash pip3 install pre-commit pre-commit run -av # Or, to just run the pytest hook: pre-commit run -av pytest ``` -------------------------------- ### Run Local Hugo Development Server Source: https://github.com/xapi-project/xen-api/blob/master/doc/README.md Commands to start a local Hugo development server and access the documentation in a web browser. Also includes instructions for cleaning the public directory before regeneration. ```bash hugo server ``` ```bash rm -r docs/public ``` -------------------------------- ### XenOpsd VM Configuration Example Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Illustrates the typical configuration file format for a virtual machine managed by XenOpsd, including its unique identifier and name. This configuration is stored in a non-persistent filesystem location. ```json { "id": "7b719ce6-0b17-9733-e8ee-dbc1e6e7b701", "name": "fedora", ... } ``` -------------------------------- ### OCaml: XenOps VM Start Micro-operations Sequence Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Defines the sequence of micro-operations executed during a VM_start operation, including running pre-start scripts, creating the VM, and building the VM. ```ocaml dequarantine_ops vgpus ; [ VM_hook_script (id, Xenops_hooks.VM_pre_start, Xenops_hooks.reason__none) ; VM_create (id, None, None, no_sharept) ; VM_build (id, force) ] ``` -------------------------------- ### OCaml: XenOps VM Start Operation Handling Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Shows the XenOps server's logic for handling a VM.start request, including checking the VM's current power state and initiating atomic operations. ```ocaml | VM_start (id, force) -> ( debug "VM.start %s (force=%b)" id force ; let power = (B.VM.get_state (VM_DB.read_exn id)).Vm.power_state in match power with | Running -> info "VM %s is already running" | _ -> perform_atomics (atomics_of_operation op) t ; VM_DB.signal id "^^^^^^^^^^^^^^^^^^^^^-------- ) ``` -------------------------------- ### Clone VM and Manage State with Xen API Source: https://github.com/xapi-project/xen-api/blob/master/scripts/examples/bash-cli/README.md An example that clones a VM, handling both running and halted states. If the original VM is running, it's shut down, cloned, and then both the original and clone are started. ```bash # Example for cloning a VM ORIGINAL_VM_UUID="" CLONED_VM_NAME="MyClonedVM" # Check if original VM is running and shut it down if necessary VM_STATE=$(xe vm-list uuid=$ORIGINAL_VM_UUID --minimal) if [[ "$VM_STATE" == *"Running"* ]]; then xe vm-shutdown uuid=$ORIGINAL_VM_UUID fi # Clone the VM CLONED_VM_UUID=$(xe vm-clone vm=$ORIGINAL_VM_UUID new-name-label=$CLONED_VM_NAME --minimal) # Start both original and cloned VMs if original was running if [[ "$VM_STATE" == *"Running"* ]]; then xe vm-start uuid=$ORIGINAL_VM_UUID xe vm-start uuid=$CLONED_VM_UUID fi ``` -------------------------------- ### Install XenServer.NET NuGet Package Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/csharp/autogen/README.md Installs the XenServer.NET NuGet package from a configured NuGet source. ```PowerShell nuget install XenServer.NET ``` -------------------------------- ### XenOpsd VM Management APIs (OCaml) Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Details key XenOpsd API functions for managing virtual machines, including checking existence, starting operations, and retrieving status. These functions interact with Xenstore for configuration and state. ```ocaml (* VM.add: Checks if VM exists and ensures Xenstore configuration is intact. *) (* VM.stat: Queries the state of a VM, relying on Xenstore keys. *) (* VM.start: Initiates the VM start operation, returning a Task ID. *) ``` -------------------------------- ### XenAPI Extension Example Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xapi/guides/howtos/add-api-extension.md Provides a link to a basic example implementation of a XenAPI extension. ```link https://github.com/xapi-project/xen-api/blob/07056d661bbf58b652e1da59d9adf67a778a5626/scripts/extensions/Test.test ``` -------------------------------- ### OCFS2 Storage Setup Walk-through Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/design/ocfs2/index.md A guide for setting up OCFS2 storage within an existing Pool, including O2CB cluster configuration, global heartbeat volume placement, and verification of I/O paths with bonding and multipath. ```APIDOC Walk-through: Adding OCFS2 Storage: Prerequisites: Existing Pool of 2 hosts. Steps: 1. Client sets up the O2CB cluster. 2. Client chooses the location for the global heartbeat volume. 3. Client checks that I/O paths are correctly set up with bonding and multipath. 4. Client prompts the user to fix any obvious I/O path problems. Example Scenario: - Client enables O2CB. - Client creates an SR. ``` -------------------------------- ### Handling Non-Persistent Disks Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Details the process for handling non-persistent disks, which are reset on each VM start. The VBD_epoch_begin signal is used to perform any necessary reset operations for these disks. ```APIDOC VBD.epoch_begin(vbd_uuid: string) - Signals the start of an epoch for a Virtual Block Device (VBD). - Used to perform necessary resets for non-persistent disks. ``` -------------------------------- ### Install VM from Template using Xen API Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xen-api/overview/index.md Installs a new virtual machine based on a selected template. This involves cloning the template, configuring storage repository, and provisioning the VM. ```Python # Assuming 'session' is a valid login session and 't_ref' is the reference to the template VM new_vm_ref = VM.clone(session, t_ref, "my first VM") # Get current other_config other_config = VM.get_other_config(session, new_vm_ref) # Update other_config to specify the Storage Repository (sr) # Replace 'your_sr_uuid' with the actual UUID of your Storage Repository other_config['disks'] = other_config.get('disks', '[]').replace('"sr": ""', '"sr": "your_sr_uuid"') VM.set_other_config(session, new_vm_ref, other_config) # Provision the VM to make it a regular VM VM.provision(session, new_vm_ref) ``` -------------------------------- ### Suspend and Resume VM using Xen API Source: https://github.com/xapi-project/xen-api/blob/master/scripts/examples/bash-cli/README.md Provides a straightforward example of how to suspend and then resume a virtual machine using the Xen API. ```bash # Example for suspending and resuming a VM VM_UUID="" xen-vm-suspend $VM_UUID # Wait for VM to suspend xen-vm-resume $VM_UUID ``` -------------------------------- ### Get XenServer Module Help and Cmdlets Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/powershell/autogen/README_51.md Provides commands to get general help about the XenServer module and list all available cmdlets within the module. ```PowerShell PS> Get-Help about_XenServer PS> Get-Command -Module XenServerPSModule ``` -------------------------------- ### XenOpsd Restart Guarantees Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Describes XenOpsd's behavior upon restart during a VM start operation, ensuring the VM state is either shut down or intact and running. ```text If Xenopsd restarts during a start operation, on restart the VM state shall be "fixed" by either (i) shutting down the VM; or (ii) ensuring the VM is intact and running. ``` -------------------------------- ### XenServer Software Development Kit Guide Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/powershell/autogen/README_51.md Directs users to the XenServer Software Development Kit Guide, a valuable resource for understanding and utilizing the XenServer SDK, including the PowerShell module. ```APIDOC XenServer Software Development Kit Guide: URL: https://docs.xenserver.com/en-us/xenserver/8/developer/sdk-guide ``` -------------------------------- ### XenServer Software Development Kit Guide Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/powershell/autogen/README.md The XenServer SDK Guide offers comprehensive information for developers working with XenServer. It covers the SDK's functionalities, best practices, and how to integrate with XenServer programmatically, which is directly applicable to using the PowerShell module. ```APIDOC XenServer Software Development Kit Guide: URL: https://docs.xenserver.com/en-us/xenserver/8/developer/sdk-guide This guide provides in-depth knowledge for developers utilizing the XenServer SDK. It is highly recommended for users of the XenServer PowerShell Module as it explains the underlying API concepts and usage patterns. ``` -------------------------------- ### XenOpsd Backend Implementations Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Lists the different backend systems that XenOpsd can interface with to manage virtual machines. These include various Xen configurations and KVM. ```text - Xen via libxc, libxenguest and xenstore - Xen via libxl, libxc and xenstore - Xen via libvirt - KVM by direct invocation of qemu - Simulation for testing ``` -------------------------------- ### VIF Plugging Logic Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Details the steps for plugging a Virtual Network Interface (VIF) into a VM. This includes computing and writing port locking configuration, adding Xenstore frontend/backend directories for network device info, updating the Xenopsd database, and creating frontend devices for QEMU. ```ocaml (* Function VIF.plug_exn in xc/xenops_server_xen.ml *) ``` ```ocaml (* Computes and writes port locking configuration *) ``` ```ocaml (* Adds Xenstore frontend/backend directories for network device info *) ``` ```ocaml (* Writes VIF information to Xenopsd database *) ``` ```ocaml (* Creates frontend device in QEMU domain if necessary *) ``` -------------------------------- ### VBD Plugging Logic Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Details the steps involved in plugging a Virtual Block Device (VBD) into a VM. This includes attaching and activating the VDI, managing Xenstore entries for block device info and SCSI ID passthrough, updating the Xenopsd database, and creating frontend devices for QEMU in different domains. ```ocaml (* Function VBD.plug in xc/xenops_server_xen.ml *) ``` ```ocaml (* Calls VDI.attach and VDI.activate *) ``` ```ocaml (* Adds Xenstore frontend/backend directories *) ``` ```ocaml (* Adds extra Xenstore keys for SCSIid passthrough *) ``` ```ocaml (* Writes VBD information to Xenopsd database *) ``` ```ocaml (* Creates frontend device in QEMU domain if necessary *) ``` -------------------------------- ### Create Device Model for Xen VM Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Creates a QEMU device model for a Xen VM if the VM is HVM or uses a PV keyboard/mouse. This involves creating and building the QEMU domain and computing necessary arguments. ```ocaml (* Function to create device model, potentially using a stubdom *) let create_device_model_exn ~xc ~xs vm = (* Logic to create and build QEMU domain *) (* Compute QEMU arguments and launch *) (); ``` -------------------------------- ### Xen Domain Creation (VM.create) Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Details the micro-operation VM_create which calls the backend VM.create function. It outlines the steps for creating a Xen domain, including memory reservation, domain creation via libxc hypercall, platform data generation, memory transfer, balloon target setting, and vCPU hotplugging. ```ocaml (* Xenopsd backend VM.create_exn function *) ``` ```APIDOC VM.create_exn(vm_uuid: string, config: vm_config) - Creates a Xen domain for a VM. - Handles fresh VM creation or resuming existing ones. - Interacts with squeezed for memory reservations. - Uses Xenctrl.domain_create hypercall. - Generates platform data for Xenstore. - Manages memory reservation transfer. - Sets initial balloon target. - Applies 'suppress spurious page faults' workaround if requested. - Sets 'machine address size'. - Hotplugs vCPUs. ``` -------------------------------- ### Start VM with Trace Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/design/backtraces.md Initiates a VM start operation with tracing enabled. The `--trace` flag provides detailed execution information, useful for debugging. The output shows an example of a `SR_BACKEND_FAILURE_202` error with its parameters and a detailed backtrace. ```bash # xe vm-start vm=hvm --trace Error code: SR_BACKEND_FAILURE_202 Error parameters: , General backend error [opterr=exceptions must be old-style classes or derived from BaseException, not str], Raised Server_error(SR_BACKEND_FAILURE_202, [ ; General backend error [opterr=exceptions must be old-style classes or derived from BaseException, not str]; ]) Backtrace: 0/50 EXT @ st30 Raised at file /opt/xensource/sm/SRCommand.py, line 110 1/50 EXT @ st30 Called from file /opt/xensource/sm/SRCommand.py, line 159 2/50 EXT @ st30 Called from file /opt/xensource/sm/SRCommand.py, line 263 3/50 EXT @ st30 Called from file /opt/xensource/sm/blktap2.py, line 1486 4/50 EXT @ st30 Called from file /opt/xensource/sm/blktap2.py, line 83 5/50 EXT @ st30 Called from file /opt/xensource/sm/blktap2.py, line 1519 6/50 EXT @ st30 Called from file /opt/xensource/sm/blktap2.py, line 1567 7/50 EXT @ st30 Called from file /opt/xensource/sm/blktap2.py, line 1065 8/50 EXT @ st30 Called from file /opt/xensource/sm/EXTSR.py, line 221 9/50 xenopsd-xc @ st30 Raised by primitive operation at file "lib/storage.ml", line 32, characters 3-26 10/50 xenopsd-xc @ st30 Called from file "lib/task_server.ml", line 176, characters 15-19 11/50 xenopsd-xc @ st30 Raised at file "lib/task_server.ml", line 184, characters 8-9 12/50 xenopsd-xc @ st30 Called from file "lib/storage.ml", line 57, characters 1-156 13/50 xenopsd-xc @ st30 Called from file "xc/xenops_server_xen.ml", line 254, characters 15-63 14/50 xenopsd-xc @ st30 Called from file "xc/xenops_server_xen.ml", line 1643, characters 15-76 15/50 xenopsd-xc @ st30 Called from file "lib/xenctrl.ml", line 127, characters 13-17 16/50 xenopsd-xc @ st30 Re-raised at file "lib/xenctrl.ml", line 127, characters 56-59 17/50 xenopsd-xc @ st30 Called from file "lib/xenops_server.ml", line 937, characters 3-54 18/50 xenopsd-xc @ st30 Called from file "lib/xenops_server.ml", line 1103, characters 4-71 19/50 xenopsd-xc @ st30 Called from file "list.ml", line 84, characters 24-34 20/50 xenopsd-xc @ st30 Called from file "lib/xenops_server.ml", line 1098, characters 2-367 21/50 xenopsd-xc @ st30 Called from file "lib/xenops_server.ml", line 1203, characters 3-46 22/50 xenopsd-xc @ st30 Called from file "lib/xenops_server.ml", line 1441, characters 3-9 23/50 xenopsd-xc @ st30 Raised at file "lib/xenops_server.ml", line 1452, characters 9-10 24/50 xenopsd-xc @ st30 Called from file "lib/xenops_server.ml", line 1458, characters 48-60 25/50 xenopsd-xc @ st30 Called from file "lib/task_server.ml", line 151, characters 15-26 26/50 xapi @ st30 Raised at file "xapi_xenops.ml", line 1719, characters 11-14 27/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 28/50 xapi @ st30 Raised at file "xapi_xenops.ml", line 2005, characters 13-14 29/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 30/50 xapi @ st30 Raised at file "xapi_xenops.ml", line 1785, characters 15-16 31/50 xapi @ st30 Called from file "message_forwarding.ml", line 233, characters 25-44 32/50 xapi @ st30 Called from file "message_forwarding.ml", line 915, characters 15-67 33/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 34/50 xapi @ st30 Raised at file "lib/pervasiveext.ml", line 26, characters 9-12 35/50 xapi @ st30 Called from file "message_forwarding.ml", line 1205, characters 21-199 36/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 37/50 xapi @ st30 Raised at file "lib/pervasiveext.ml", line 26, characters 9-12 38/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 39/50 xapi @ st30 Raised at file "rbac.ml", line 236, characters 10-15 40/50 xapi @ st30 Called from file "server_helpers.ml", line 75, characters 11-41 41/50 xapi @ st30 Raised at file "cli_util.ml", line 78, characters 9-12 42/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 43/50 xapi @ st30 Raised at file "lib/pervasiveext.ml", line 26, characters 9-12 44/50 xapi @ st30 Called from file "cli_operations.ml", line 1889, characters 2-6 45/50 xapi @ st30 Re-raised at file "cli_operations.ml", line 1898, characters 10-11 46/50 xapi @ st30 Called from file "cli_operations.ml", line 1821, characters 14-18 47/50 xapi @ st30 Called from file "cli_operations.ml", line 2109, characters 7-526 48/50 xapi @ st30 Called from file "xapi_cli.ml", line 113, characters 18-56 49/50 xapi @ st30 Called from file "lib/pervasiveext.ml", line 22, characters 3-9 ``` -------------------------------- ### Xenopsd VM.add Function Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Demonstrates the Xenopsd 'VM.add' function, which stores VM configuration in the database and notifies the backend. It shows the interaction with the database and the backend's VM add operation. ```ocaml let add' x = debug "VM.add %s" (Jsonrpc.to_string (rpc_of_t x)); DB.write x.id x; let module B = (val get_backend () : S) in B.VM.add x; x.id ``` -------------------------------- ### Connect to XenServer and Get VMs Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/powershell/autogen/README_51.md An example of connecting to a XenServer instance, retrieving a list of virtual machines, and disconnecting. ```PowerShell PS> Connect-XenServer -Url https:// PS> Get-XenVM PS> Disconnect-XenServer ``` -------------------------------- ### with_many Function Example Usage Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xapi/storage/sxm/index.md This OCaml example demonstrates the usage of the `with_many` helper function. It defines a sample `withfn` that prints messages upon starting and handling exceptions, then applies it to a list of integers. The output illustrates how `with_many` processes the list sequentially, passing results through continuations and handling potential exceptions. ```ocaml let withfn x c = Printf.printf "Starting withfn: x=%d\n" x; try c (string_of_int x) with e -> Printf.printf "Handling exception for x=%d\n" x; raise e;; (* applying this gives the output: *) (* utop # with_many withfn [1;2;3;4] (String.concat ",");; Starting with fn: x=1 Starting with fn: x=2 Starting with fn: x=3 Starting with fn: x=4 - : string = "4,3,2,1" *) ``` -------------------------------- ### RRD Deltas XML Structure Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xen-api/topics/metrics.md An example of the XML structure returned by the rrd_updates endpoint, showing metadata like start time, step, and legend, followed by data rows. ```xml 1213578000 3600 1213617600 12 12 AVERAGE:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu1 AVERAGE:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu0 AVERAGE:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:memory MIN:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu1 MIN:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu0 MIN:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:memory MAX:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu1 MAX:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu0 MAX:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:memory LAST:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu1 LAST:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:cpu0 LAST:vm:ecd8d7a0-1be3-4d91-bd0e-4888c0e30ab3:memory 1213617600 0.0 0.0282 209715200.0000 0.0 0.0201 209715200.0000 0.0 0.0445 209715200.0000 0.0 0.0243 209715200.0000 ... ``` -------------------------------- ### Add Field to SM Class in Records Module Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xapi/guides/howtos/add-field.md Example of adding a new field, 'versioned-capabilities', to the SM class in the `ocaml/xapi-cli-server/records.ml` file. This demonstrates the use of `make_field` with `get`, `get_map`, and `hidden` parameters. ```ocaml make_field ~name:"versioned-capabilities" ~get:(fun () -> get_from_map (x ()).API.sM_versioned_capabilities) ~get_map:(fun () -> (x ()).API.sM_versioned_capabilities) ~hidden:true (); ``` -------------------------------- ### Xen Domain Build Phase Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Describes the build phase of a Xen domain, which involves waiting for memory reclamation, NUMA placement, vCPU affinity setting, and invoking xenguest to construct the domain's memory layout. ```ocaml (* Walk-through of the VM_build μ-op *) ``` ```APIDOC VM.build(vm_uuid: string) - Waits for Xen memory scrubber to catch up. - Performs NUMA placement. - Sets vCPU affinity. - Invokes xenguest to build the system memory layout. ``` -------------------------------- ### Python VM Test Implementation Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/xapi-idl/designs/interprocesscomms.md An example Python implementation for VM testing. This class provides a 'start' method that returns a successful response with a 'task' key, facilitating simple component testing. ```Python class Vm_test: """Types used to represent a VM configuration""" def __init__(self): pass def start(self, dbg, id): """Types used to represent a VM configuration""" result = {} result["task"] = "string" return result ``` -------------------------------- ### XenServer API Object Model Overview Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xen-api/overview/index.md Provides a high-level overview of the core classes within the XenServer API, detailing their purpose, example methods, and parameters. This section serves as a guide to understanding the API's structure. ```APIDOC VM: Represents a virtual machine instance on a XenServer Host or Resource Pool. Example Methods: start, suspend, pool_migrate Example Parameters: power_state, memory_static_max, name_label Host: Represents a physical host in a XenServer pool. Example Methods: reboot, shutdown Example Parameters: software_version, hostname, address VDI: Represents a Virtual Disk Image. Example Methods: resize, clone Example Parameters: virtual_size, sharable SR: Represents a Storage Repository, aggregating VDIs and storage properties. Example Methods: scan, create Example Parameters: type, physical_utilisation ``` -------------------------------- ### Pre-commit Configuration for Pytest Hook Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/python/_index.md An example of a pytest hook configuration within a .pre-commit-config.yaml file. It specifies how to run tests, generate coverage reports, and perform diff analysis against a base branch. ```YAML hooks: - id: pytest files: python3/ name: check that the Python3 test suite in passes entry: sh -c 'coverage run && coverage xml && coverage html && coverage report && diff-cover --ignore-whitespace --compare-branch=origin/master --show-uncovered --format html:.git/coverage-diff.html --fail-under 50 .git/coverage3.11.xml' require_serial: true pass_filenames: false language: python types: [python] additional_dependencies: - coverage - diff-cover - future - opentelemetry-api - opentelemetry-exporter-zipkin-json - opentelemetry-sdk - pytest-mock - mock - wrapt - XenAPI ``` -------------------------------- ### VBD Xenstore Key Management Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Explains how Xenstore keys are written for VBDs using Device.Vbd.add_async and Device.Vbd.add_wait. It also describes the Linux udev process for creating backend devices, firing UEVENTS, and updating Xenstore with major/minor numbers and hotplug status. ```ocaml (* Xenstore keys written by Device.Vbd.add_async and Device.Vbd.add_wait *) ``` ```bash # In Linux domain (dom0): # Kernel creates 'backend device' when backend directory is created. # Kernel UEVENT fires, picked up by udev. # udev rules run script to stat(2) device and write major/minor to Xenstore. # Script also writes 'hotplug-status=connected' to Xenstore. ``` ```ocaml (* Xenopsd waits for 'hotplug-status=connected' key for VBD.stat *) ``` -------------------------------- ### Xen API Synchronous Operations Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xen-api/usage.md Explains how to invoke synchronous operations on Xen objects once references have been acquired. All API calls are synchronous by default and return upon completion or failure. An example of starting a VM is provided. ```APIDOC Xen API Synchronous Operations: Invoke operations on acquired object references. Example: Start a VM session.xenapi.VM.start(vm, False, False) Note: The VM.start call returns when the VM begins booting. To confirm boot completion, monitor VM_guest_metrics. ``` -------------------------------- ### Go Project Build Commands for XenServer SDK Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/sdk-gen/go/README.md Essential Go commands to run before building a project that utilizes the XenServer SDK for Go, ensuring dependencies are up-to-date. ```Go go get -u all go mod tidy ``` -------------------------------- ### XenServer/XCP Custom Service API Interaction Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/xapi-idl/xen-api-plugin/service.md This API allows clients to interact with custom services installed on XenServer/XCP. Requests are authenticated via XenAPI session IDs and forwarded to a Unix domain socket. Supports HTTP GET, PUT, and POST methods. ```APIDOC API Description: The custom service should be installed into domain 0 and configured to start on system boot. It should accept connections on the unix domain socket: /var/xapi/plugin/ Client Interaction: 1. Acquire a valid session_id using XenAPI (e.g., session.login_with_password). 2. Issue HTTP requests (GET, PUT, POST) to the URI: /services/plugin/ 3. Include the session_id as a query parameter or cookie: session_id= HTTP Error Codes: - HTTP 403 Forbidden: Invalid or missing session_id. - HTTP 404 Not Found: Valid session_id, but the named service is not running. - HTTP 302 Redirect: Service is running on a different IP/URI; clients should follow the redirect. Custom Service Response: The custom service may return any valid HTTP response (success or failure) after authentication and forwarding. ``` -------------------------------- ### Example: Creating a Bond in XenAPI CLI Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xapi/cli/_index.md Demonstrates a typical XenAPI CLI command implementation for creating a bond. It shows how to extract parameters, perform XenAPI calls to get references (e.g., network, PIFs), create the bond using `Client.Bond.create`, and output the new bond's UUID. ```OCaml let bond_create printer rpc session_id params = let network = List.assoc "network-uuid" params in let mac = List.assoc_default "mac" params "" in let network = Client.Network.get_by_uuid rpc session_id network in let pifs = List.assoc "pif-uuids" params in let uuids = String.split ',' pifs in let pifs = List.map (fun uuid -> Client.PIF.get_by_uuid rpc session_id uuid) uuids in let mode = Record_util.bond_mode_of_string (List.assoc_default "mode" params "") in let properties = read_map_params "properties" params in let bond = Client.Bond.create rpc session_id network pifs mac mode properties in let uuid = Client.Bond.get_uuid rpc session_id bond in printer (Cli_printer.PList [ uuid]) ``` -------------------------------- ### XenOpsd Event Handling (OCaml) Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Explains the event-driven model in XenOpsd, where clients use UPDATES.get with a token to receive notifications about state changes, similar to the XenAPI event system. ```ocaml (* UPDATES.get token: Represents the point in time of the last update. *) (* The call blocks until state changes occur, returning object IDs. *) (* Clients then use relevant 'stat' functions (e.g., TASK.stat) to get current states. *) ``` -------------------------------- ### Create Device Model Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.migrate.md Details the process of creating a device model, which involves configuring and starting qemu-dm to manage PCI devices. ```APIDOC create_device_model - Configures and starts qemu-dm. - Enables management of PCI devices. ``` -------------------------------- ### Install xcp-rrdd using opam Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/xcp-rrdd/README.markdown This snippet shows the steps to install the xcp-rrdd package using the opam package manager. It involves creating a new switch, removing the default repository, adding the xs-opam repository, and then installing the xcp-rrdd package. ```bash opam switch create new-env opam repo remove default opam repo add xs-opam https://github.com/xapi-project/xs-opam.git opam install xcp-rrdd ``` -------------------------------- ### xl info outstanding claims example Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/lib/xenctrl/xc_domain_claim_pages.md Shows an example of how to retrieve host-wide outstanding claims using 'xl info'. ```js outstanding_claims : 0 ``` -------------------------------- ### Xen CLI hostdriver-variant-list Example Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/toolstack/features/MVD/index.md An example of using the Xen CLI to list details of a specific host driver variant using its UUID. ```bash [root@lcy2-dt110 log]# xe hostdriver-variant-list uuid=abf5997b-f2ad-c0ef-b27f-3f8a37bf58a6 uuid ( RO) : abf5997b-f2ad-c0ef-b27f-3f8a37bf58a6 name ( RO): generic version ( RO): 1.2 status ( RO): beta active ( RO): false selected ( RO): true driver-uuid ( RO): c0fe459d-5f8a-3fb1-3fe5-3c602fafecc0 driver-name ( RO): cisco-fnic host-uuid ( RO): 6de288e7-0f82-4563-b071-bcdc083b0ffd hw-present ( RO): false ``` -------------------------------- ### VIF Xenstore Key Management and Hotplug Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Describes how Xenstore keys are written for VIFs using Device.Vif.add, which waits for the 'hotplug-status=connected' key. This ensures port locking rules are applied before the VM executes, preventing misconfiguration. ```ocaml (* Function Device.Vif.add writes Xenstore keys *) ``` ```bash # Xenopsd waits for 'hotplug-status=connected' key for VIFs. # This ensures port locking rules are applied after backend device creation and udev script execution. ``` -------------------------------- ### OCaml: XenOps Task Queue Operation Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Illustrates how XenOps queues operations, creates tasks, and redirects them for processing. It highlights the role of tasks in holding operation metadata and execution functions. ```ocaml let queue_operation_int dbg id op = let task = Xenops_task.add tasks dbg (fun t -> perform op t; None) in Redirector.push id (op, task); task ``` -------------------------------- ### XenOpsd Task Handling APIs (OCaml) Source: https://github.com/xapi-project/xen-api/blob/master/doc/content/xenopsd/walkthroughs/VM.start.md Describes the XenOpsd APIs for managing asynchronous tasks, including polling task status, receiving updates via an event system, and cancelling ongoing tasks. These are crucial for UI feedback and control. ```ocaml (* TASK.stat: Polls the status of a task. *) (* UPDATES.get: Blocks until objects change state, returning object IDs. *) (* TASK.cancel: Cancels an ongoing task. *) ``` -------------------------------- ### Profiling and Coverage Setup Source: https://github.com/xapi-project/xen-api/blob/master/ocaml/xenopsd/COVERAGE.md References the OCaml code file responsible for the run-time setup of coverage profiling. This code has no effect when profiling is not active during execution. ```ocaml profiling/coverage.ml ```