XenServer SDK - Code Examples Shipped with the SDK

The XenServer SDK is available in 5 language bindings: C, C#, Python, PowerShell and Java. Providing API functionality broadly equivalent to the xe command line interface (CLI). As such it is often possible to directly translate/port xe CLI examples into the desired language.


The SDK contains a large number of code examples intended to demonstrate the syntax of the API for each language. The SDK when downloaded will contain all the language bindings, the names are transparent apart from the C-language binding (libxenserver)

Directory of C:\XenServer-SDK

18/03/2013  17:35<dir>          .
18/03/2013  17:35<dir>          ..
18/03/2013  17:35<dir>          libxenserver
18/03/2013  17:34<dir>          XenServer.NET
18/03/2013  17:35<dir>          XenServerJava
18/03/2013  17:34<dir>          XenServerPSSnapIn
18/03/2013  17:34<dir>          XenServerPSSnapIn_old
18/03/2013  17:34<dir>          XenServerPython

Each binding contains a directory named test or sample that will contain some code examples in that language.


NOTE: The number of samples and functionality they cover is DIFFERENT for all the bindings. This is to maximise coverage of language syntax and API functionality usage. We advise users to review the code-examples in all languages and regard them as pseudo-code for API usage.



Language Specific Information

C Bindings (libxenserver)

In addition to the code examples, a library of auxillary functions is available from

https://github.com/xenserver/xs-cim/blob/master/src/xen_utils.c this is provided as is demonstrator code. This library contains functions demonstrating not only API usage but manipulation of structures necessary to utilise the C language binding including:

  • use of the curl.h library
  • handling of structures such as xen_string_string_map
  • connection and session handling
  • error handling

Python Bindings

Within Python a few reserved keywords correspond to the underlying naming convention with the XenServer API. As such those functions deviate from the convention by the use of "_" rather than "." in the syntax

  • e.g. the reserved word from; means that the API call is session.xenapi.event_from and not session.xenapi.event.from


C# Bindings

The C# Bindings are used by our own XenCenter code. XenCenter code is fully open source and as such developers often find the answers to many questions by searching the XenCenter solution for an example of the API or error they are trying to use or interpret.

The XenCenter code is available at: https://github.com/xenserver/xenadmin




About XenServer

XenServer is the leading open source virtualization platform, powered by the Xen Project hypervisor and the XAPI toolstack. It is used in the world's largest clouds and enterprises.
Technical support for XenServer is available from Citrix.