• View Communities
    • Citrix Developer Network
      The place for unfiltered straight talk on Citrix products. Blogs, code downloads, best practices, APIs, and more can all be found here.
    • Citrix Ready Community Verified
      Does it work with Citrix? Application compatibility questions are a thing of the past with the new Citrix Community Verified site.
    • Blogs
      Learn the latest from the Citrix employees who are building application delivery infrastructure technologies.
    • Blogosphere
      The Citrix Blogosphere is a window into the thousands of conversations taking place about Citrix and Application Delivery.
  •  Sign In
XenServer Developer Network

XenServer Python API Samples

XenAPI python examples

Note the examples all make use of the library XenAPI.py ([cdn:download] [cdn:Browse]) and provision.py ([cdn:download] [cdn:Browse]).

install.py

[cdn:download] [cdn:Browse]

This example chooses a Debian template and installs a VM from it, placing disks on the Pool's default SR. It adds a VIF connecting the VM to a network on the host and boots the VM. The script blocks until the guest agent has reported both the OS version and eth0's IP address.

powercycle.py

[cdn:download] [cdn:Browse]

This example lists all existing VMs, shuts them down and then performs some aggressive power-cycling on each one.

permute.py

[cdn:download] [cdn:Browse]

This example finds a set of running VMs, finds the hosts on which the VMs are running, permutes the list of hosts and then simultaneously migrates each VM to the chosen new host. The program waits for all parallel migration tasks to complete before continuing. NB this program requires an extra argument: an integer number of iterations.

vm_start_async.py

[cdn:download] [cdn:Browse]

This example demonstrates the asyncronous operation support by starting a VM named "new" (which must already exist and be halted), retrieving a task reference and displaying the instantaneous task status

watch-all-events.py

[cdn:download] [cdn:Browse]

This example demonstrates using the event system by registering for events on all classes and pretty-printing them as they are received.

fixpbds.py

[cdn:download] [cdn:Browse]

This example shows how to alter the device config parameters of PBD objects, useful if your storage server configuration has changed.

shell.py

[cdn:download] [cdn:Browse]
This example creates a python interactive shell with access to the bindings for experimentation.

license.py

[cdn:download] [cdn:Browse]

This example demonstrates how to upload a license file to a server. It expects the license to be contained within the file "license" in the current directory.

Invoking the examples

Each program takes 3 commandline arguments:

  • url - an https or http URL pointing at the server
  • username - a valid user on the server (eg root)
  • password

For example:./install.py https://localhost:443/ root letmein

Enter tags to add to this page:
Please wait 
Looking for a tag? Just start typing.
Related Links