Citrix DL385 - ProLiant - G5 User manual

1
XenServer Software Development Kit
Guide
4.1.0
Published March 2008
1.0 Edition

XenServer Software
Development Kit Guide
2
XenServer Software Development Kit Guide: Release 4.1.0
Published March 2008
Copyright © 2008 Citrix Systems, Inc.
Xen®, Citrix™, Enterprise Edition™, XenServer™, Express Edition™, XenCenter™ and logos are either registered trademarks or
trademarks of Citrix Systems, Inc. in the United States and/or other countries. Other company or product names are for informational
purposes only and may be trademarks of their respective owners.
This product contains an embodiment of the following patent pending intellectual property of Citrix Systems, Inc.:
1. United States Non-Provisional Utility Patent Application Serial Number 11/487,945, filed on July 17, 2006, and entitled “Using
Writeable Page Tables for Memory Address Translation in a Hypervisor Environment”.
2. United States Non-Provisional Utility Patent Application Serial Number 11/879,338, filed on July 17, 2007, and entitled “Tracking
Current Time on Multiprocessor Hosts and Virtual Machines”.

XenServer Software
Development Kit Guide
3

4
Table of Contents
1. Introduction .................................................................................................................. 1
2. Getting Started ............................................................................................................ 2
2.1. System Requirements and Preparation ............................................................... 2
2.2. Downloading ..................................................................................................... 2
2.3. Installation ........................................................................................................ 2
2.4. What's new ....................................................................................................... 2
2.5. Content Map ..................................................................................................... 2
2.6. Building Samples for the Linux Platform ............................................................. 3
2.7. Building Samples for the Windows Platform ........................................................ 3
2.8. Running the CLI ............................................................................................... 3
2.8.1. Tab Completion ...................................................................................... 3
2.9. Accessing SDK reference .................................................................................. 3
3. Overview of the XenServer API .................................................................................... 5
3.1. Getting Started with the API .............................................................................. 5
3.1.1. Authentication: acquiring a session reference ........................................... 5
3.1.2. Acquiring a list of templates to base a new VM installation on .................... 5
3.1.3. Installing the VM based on a template ..................................................... 6
3.1.4. Taking the VM through a start/suspend/resume/stop cycle ......................... 6
3.1.5. Logging out ............................................................................................ 6
3.1.6. "Install and start example": summary ....................................................... 7
3.2. Object Model Overview ..................................................................................... 7
3.3. Working with VIFs and VBDs ............................................................................. 9
3.3.1. Creating disks and attaching them to VMs ............................................... 9
3.3.2. Creating and attaching Network Devices to VMs ..................................... 11
3.3.3. Host configuration for networking and storage ........................................ 11
3.4. Exporting and Importing VMs ........................................................................... 12
3.5. Where to look next .......................................................................................... 13
4. Using the API ............................................................................................................ 14
4.1. Anatomy of a typical application ....................................................................... 14
4.1.1. Choosing a low-level transport .............................................................. 14
4.1.2. Authentication and session handling ...................................................... 14
4.1.3. Finding references to useful objects ....................................................... 15
4.1.4. Invoking synchronous operations on objects ........................................... 15
4.1.5. Using Tasks to manage asynchronous operations ................................... 16
4.1.6. Subscribing to and listening for events ................................................... 16
4.2. Language bindings .......................................................................................... 17
4.2.1. C ......................................................................................................... 17
4.2.2. C# ....................................................................................................... 18
4.2.3. Python ................................................................................................. 18
4.2.4. Command Line Interface (CLI) .............................................................. 19
4.3. Complete application examples ........................................................................ 19
4.3.1. Simultaneously migrating VMs using XenMotion ..................................... 19
4.3.2. Cloning a VM via the XE CLI ................................................................ 22
5. XenServer API extensions .......................................................................................... 24
5.1. VM console forwarding .................................................................................... 24
5.1.1. Retrieving VNC consoles via the API ..................................................... 24
5.1.2. Disabling VNC forwarding for Linux VM ................................................. 25
5.2. Paravirtual Linux installation ............................................................................. 26
5.2.1. Red Hat Enterprise Linux 4.1/4.4 ........................................................... 26
5.2.2. Red Hat Enterprise Linux 4.5/5.0 ........................................................... 26
5.2.3. SUSE Enterprise Linux 10 SP1 ............................................................. 27

XenServer Software
Development Kit Guide
5
5.2.4. CentOS 4.5/5.0 .................................................................................... 27
5.3. Adding Xenstore entries to VMs ....................................................................... 27
5.4. Security enhancements ................................................................................... 27
5.5. Advanced settings for network interfaces .......................................................... 28
5.5.1. ethtool settings ..................................................................................... 28
5.5.2. Miscellaneous settings .......................................................................... 29
5.6. Internationalization for SR names ..................................................................... 29
5.7. Hiding objects from XenCenter ......................................................................... 30
Index ............................................................................................................................. 31

6
List of Figures
3.1. Graphical overview of API classes for managing VMs, Hosts, Storage and Network-
ing .................................................................................................................................. 9
3.2. A VM object with 2 associated VDIs ......................................................................... 11

1
Chapter 1. Introduction
Welcome to the developer’s guide for XenServer. Here you will find the information you need in order to
understand and use the Software Development Kit (SDK) that XenServer provides. This information will
provide you with some of the architectural background and thinking that underpins the APIs, the tools that
have been provided, and how to quickly get off the ground.

2
Chapter 2. Getting Started
2.1. System Requirements and Preparation
The XenServer SDK is packaged as a Linux VM that must be imported into a XenServer Host. This document
refers to the SDK virtual machine interchangeably as an SDK and an SDK VM. The first step towards
working with the SDK is to install XenServer. A free version, Express Edition, is available to download at
http://www.xensource.com/. Please refer to the XenServer Installation Guide for detailed instructions on
how to set up your development host. When the installation is complete, please note the host IP address
and the host password..
Once you have installed your XenServer Host, install XenCenter on a Windows PC. Launch the application
and connect to your new XenServer Host using its IP address and the password.
2.2. Downloading
The SDK is available for download as a ZIP file at http://www.xensource.com/ of around 250MB.
2.3. Installation
Ensure that your XenServer Host is up and running. In XenCenter, right-click on the XenServer Host and
select Import VM from the context menu, or select Import... from the VM menu, then double-click on the sdk
directory and click the Import button. When the import has completed, the SDK VM is installed and ready
to go. Click on the Overview tab of the SDK VM and inspect the networking configuration. If the SDK is to
be accessed remotely, then ensure that it has an interface connected to the correct network. Note that the
SDK VM will attempt to acquire an IP address via DHCP each time it boots.
2.4. What's new
Starting with version 4.0, we now provide a rich management infrastructure consisting of a comprehensive
object model together with an application program interface (API) to install, monitor and manage various
aspects of virtual machine infrastructure.
This is the first version of a supported Software Development Kit that Citrix has published. Prior to this
version, the primary means of integrating Citrix products into the existing IT infrastructure was through
command line interface tools.
The XenServer 4.1.0 SDK provides the API with C and Python language bindings, and C# language binding
compatible with .NET 2.0. The SDK also provides a new and improved CLI that provides a comprehensive
set of commands to manage your XenServer Hosts. The CLI is available for both Linux and Windows
platforms.
2.5. Content Map
The following is an overview of the contents of the /SDK directory. Where necessary, subdirectories have
their own individual README files.
Directory Description
/SDK/ Contains README.txt, a brief text overview
/SDK/docs/pdf/ Contains api.pdf , the PDF version of the reference
for the API

Getting Started
3
Directory Description
/SDK/docs/html/ Contains index.html, the HTML version of the
reference for the API
/SDK/windows-cli a Windows version of the CLI xe.exe
/SDK/client-examples/c C examples and a Makefile to build them
/SDK/client-examples/c/src C source for the language bindings
/SDK/client-examples/csharp/XenSdk.net Microsoft Visual Studio 2005 solution which
includes the C# language bindings (which compile
to a .dll) and several example projects
/SDK/client-examples/bash-cli Simple bash scripts which use the xe CLI
/SDK/client-examples/python Several example python programs
2.6. Building Samples for the Linux Platform
The SDK VM comes complete with the tools necessary to build the C samples. Looking at the content
map, the directory /SDK/client-examples/c has a Makefile at the top level which builds the language
bindings, as well as the C language samples that are included as part of the SDK VM.
2.7. Building Samples for the Windows Platform
The C# examples in /SDK/client-examples/csharp/XenSdk.net must first be copied to a Windows
machine with Visual Studio and .NET 2.0 installed. The C# bindings and the samples directories each have
the appropriate solution (.sln) files generated by Microsoft Visual Studio 2005. Launching them via the
Windows Explorer and rebuilding at the top level will build the language bindings as well as the applications.
The IP address of the host is passed in as a parameter to each of the sample applications. This needs to
be set/changed to ensure that the applications work against the right XenServer Host.
2.8. Running the CLI
The CLI for Linux is called xe, and for Windows is called xe.exe. The Windows version is under /SDK/
windows-cli. This needs to be copied onto a PC running Windows XP or higher, and must have .Net 2.0
installed. When running in the SDK VM, the Linux CLI is already installed and in the default path. Typing
xe in the SDK VM console launches the CLI.
2.8.1. Tab Completion
The CLI has comprehensive tab completion that allows discovery of the commands and parameters. On
launching xe, hitting tab twice shows all the commands that the CLI has.
2.9. Accessing SDK reference
The SDK VM has a built-in web server that allows access to the samples and the complete reference
documentation.
Procedure 2.1. To access this information
1. From the command prompt type ifconfig and hit ENTER.
2. Note down the IP address for the eth0 interface for this VM. If there is no eth0 interface, please add
a virtual NIC.

Getting Started
4
3. From any other machine, fire up a web browser and type http://<SDK IP address>/
The full URL you need is also displayed in the “Message of the Day” in the SDK VM console after it has
completed booting.

5
Chapter 3. Overview of the XenServer
API
In this chapter we introduce the XenServer API (hereafter referred to as just "the API") and its associated
object model. The API has the following key features:
•Management of all aspects of XenServer Host: Through the API one can manage VMs, storage,
networking, host configuration and pools. Performance and status metrics can also be queried via the API.
•Persistent Object Model: The results of all side-effecting operations (e.g. object creation, deletion
and parameter modifications) are persisted in a server-side database that is managed by the XenServer
installation.
•An event mechanism: Through the API, clients can register to be notified when persistent (serv-
er-side) objects are modified. This enables applications to keep track of datamodel modifications per-
formed by concurrently executing clients.
•Synchronous and asynchronous invocation: All API calls can be invoked synchronously (i.e. block
until completion); any API call that may be long-running can also be invoked asynchronously. Asyn-
chronous calls return immediately with a reference to a task object. This task object can be queried
(through the API) for progress and status information. When an asynchronously invoked operation com-
pletes, the result (or error code) is available via the task object.
•Remotable and Cross-Platform: The client issuing the API calls does not have to be resident on the
host being managed; nor does it have to be connected to the host via ssh in order to execute the API.
API calls make use of the XML-RPC protocol to transmit requests and responses over the network.
•Secure and Authenticated Access: The XML-RPC API server executing on the host accepts secure
socket connections. This allows a client to execute the APIs over the https protocol. Further, all the API
calls execute in the context of a login session generated through username and password validation at
the server. This provides secure and authenticated access to the XenServer installation.
3.1. Getting Started with the API
We will start our tour of the API by describing the calls required to create a new VM on a XenServer instal-
lation, and take it through a start/suspend/resume/stop cycle. This is done without reference to code in any
specific language; at this stage we just describe the informal sequence of RPC invocations that accomplish
our "install and start" task.
3.1.1. Authentication: acquiring a session reference
The first step is to call Session.login(username, password). The API is session based, so before you
can make other calls you need to authenticate with the server. Assuming the username and password are
authenticated correctly, the result of this call is a session reference. Subsequent API calls take the session
reference as a parameter. In this way we ensure that only API users who are suitably authorized can perform
operations on a XenServer installation.
3.1.2. Acquiring a list of templates to base a new VM installation on
The next step is to query the list of "templates" on the host. Templates are specially-marked VM objects
that specify suitable default parameters for a variety of supported guest types. (If you want to see a quick

Overview of the XenServer API
6
enumeration of the templates on a XenServer installation for yourself then you can execute the "xe tem-
plate-list" CLI command.) To get a list of templates via the API, we need to find the VM objects on the server
that have their "is_a_template" field set to true. One way to do this by calling VM.get_all_records(session)
where the session parameter is the reference we acquired from our Session.login_with_password call
earlier. This call queries the server, returning a snapshot (taken at the time of the call) containing all the VM
object references and their field values.
(Remember that at this stage we are not concerned about the particular mechanisms by which the returned
object references and field values can be manipulated in any particular client language: that detail is dealt
with by our language-specific API bindings and described concretely in the following chapter. For now it
suffices just to assume the existence of an abstract mechanism for reading and manipulating objects and
field values returned by API calls.)
Now that we have a snapshot of all the VM objects' field values in the memory of our client application we
can simply iterate through them and find the ones that have their "is_a_template" set to true. At this stage
let's assume that our example application further iterates through the template objects and remembers the
reference corresponding to the one that has its "name_label" set to "Debian Etch 4.0" (one of the default
Linux templates supplied with XenServer).
3.1.3. Installing the VM based on a template
Continuing through our example, we must now install a new VM based on the template we selected. The
installation process requires 2 API calls:
• First we must now invoke the API call VM.clone(session, t_ref, "my first VM"). This tells the server to
clone the VM object referenced by t_ref in order to make a new VM object. The return value of this call
is the VM reference corresponding to the newly-created VM. Let's call this new_vm_ref.
• At this stage the object referred to by new_vm_ref is still a template (just like the VM object re-
ferred to by t_ref, from which it was cloned). To make new_vm_ref into a VM object we need to call
VM.provision(session, new_vm_ref). When this call returns the new_vm_ref object will have had its
is_a_template field set to false, indicating that new_vm_ref now refers to a regular VM ready for starting.
Note that the provision operation may take a few minutes, as it is as during this call that the template's disk
images are created. In the case of the Debian template, the newly created disks are actually populated with
a Debian root filesystem at this stage too.
3.1.4. Taking the VM through a start/suspend/resume/stop cycle
Now we have an object reference representing our newly-installed VM, it is trivial to take it through a few
lifecycle operations:
• To start our VM we can just call VM.start(session, new_vm_ref)
• After it's running, we can suspend it by calling VM.suspend(session, new_vm_ref);
• and then resume it by calling VM.resume(session, new_vm_ref).
• We can call VM.shutdown(session, new_vm_ref) to shutdown the VM cleanly.
3.1.5. Logging out
Once an application is finished interacting with a XenServer Host it is good practice to call
Session.logout(session). This invalidates the session reference (so it can not be used in subsequent API
calls) and simultaneously deallocates server-side memory used to store the session object.

Overview of the XenServer API
7
Although inactive sessions will timeout eventually, the server has a hardcoded limit of 200 concurrent ses-
sions. Once this limit has been reached fresh logins will evict the oldest session objects, causing their as-
sociated session references to become invalid. So if you want your applications to play nice with others
accessing the server concurrently, then the best policy is to create a single session at start-of-day, use this
throughout the applications (note that sessions can be used across multiple separate client-server network
connections) and then explicitly logout when possible.
3.1.6. "Install and start example": summary
We have seen how the API can be used to install a VM from a XenServer template and perform a number
of lifecycle operations on it. You will note that the number of calls we had to make in order to affect these
operations was small:
• One call to acquire a session: Session.login_with_password(...)
• One call to query the VM (and template) objects present on the XenServer installation:
VM.get_all_records(...). Recall that we used the information returned from this call to select a suitable
template to install from.
• Two calls to install a VM from our chosen template: VM.clone(...), followed by VM.provision(...).
• One call to start the resultant VM: VM.start(...) (and similarly other single calls to suspend, resume and
shutdown accordingly)
• And then one call to logout Session.logout(...)
The take-home message here is that, although the API as a whole is complex and fully featured, common
tasks (such as creating and performing lifecycle operations on VMs) are very straightforward to perform,
requiring only a small number of simple API calls. Keep this in mind while you study the next section which
may, on first reading, appear a little daunting!
3.2. Object Model Overview
This section gives a high-level overview of the object model of the API. A more detailed description of the
parameters and methods of each class outlined here can be found in the XenEnterprise Management API
document. Python, C and C# sample programs that demonstrate how the API can be used practice to
accomplish a variety of tasks are available in the SDK VM and described in the following Chapter.
We start by giving a brief outline of some of the core classes that make up the API. (Don't worry if these
definitions seem somewhat abstract in their initial presentation; the textual description in subsequent sec-
tions, and the code-sample walk through in the next Chapter will help make these concepts concrete.)
VM A VM object represents a particular virtual machine instance on a XenServer
Host or Resource Pool. Example methods include "start", "suspend",
"pool_migrate"; example fields include "power_state", "memory_static_max",
"name_label". (In the previous section we saw how the VM class is used to
represent both templates and regular VMs)
Host A host object represents a physical host in a XenServer pool. Example
methods include "reboot" and "shutdown". Example fields include
"software_version", "hostname" and [IP] "address".
VDI A VDI object represents a Virtual Disk Image. Virtual Disk Images can be
attached to VMs, in which case a block device appears inside the VM through
which the bits encapsulated by the Virtual Disk Image can be read and written.
Example methods of the VDI class include "resize" and "clone". Example

Overview of the XenServer API
8
fields include "virtual_size" and "sharable". (When we called VM.provision
on the VM template in our previous example, some VDI objects were
automatically created to represent the newly created disks, and attached to
the VM object.)
SR An SR (Storage Repository) aggregates a collection of VDIs and encapsulates
the properties of physical storage on which the VDIs' bits reside. Example
fields include "type" (which determines the storage-specific driver a XenServer
installation uses to read/write the SR's VDIs) and "physical_utilisation";
example methods include "scan" (which invokes the storage-specific driver to
acquire a list of the VDIs contained with the SR and the properties of these
VDIs) and "create" (which initializes a block of physical storage so it is ready
to store VDIs).
Network A network object represents a layer-2 network that exists in the environment in
which the XenServer Host instance lives. Since XenServer does not manage
networks directly this is a lightweight class that serves merely to model
physical and virtual network topology. VM and Host objects that are attached
to a particular Network object (by virtue of VIF and PIF instances -- see below)
can send network packets to each other.
At this point, readers who are finding this enumeration of classes rather terse may wish to skip to the code
walk-throughs of the next chapter: there are plenty of useful applications that can be written using only a
subset of the classes already described! For those who wish to continue this description of classes in the
abstract, read on.
On top of the classes listed above, there are 4 more that act as connectors, specifying relationships between
VMs and Hosts, and Storage and Networks. The first 2 of these classes that we will consider, VBD and VIF,
determine how VMs are attached to virtual disks and network objects respectively:
VBD A VBD (Virtual Block Device) object represents an attachment between a VM
and a VDI. When a VM is booted its VBD objects are queried to determine
which disk images (i.e. VDIs) should be attached. Example methods of the
VBD class include "plug" (which hot plugs a disk device into a running VM,
making the specified VDI accessible therein) and "unplug" (which hot unplugs
a disk device from a running guest); example fields include "device" (which
determines the device name inside the guest under which the specified VDI
will be made accessible).
VIF A VIF (Virtual network InterFace) object represents an attachment between a
VM and a Network object. When a VM is booted its VIF objects are queried to
determine which network devices should be create. Example methods of the
VIF class include "plug" (which hot plugs a network device into a running VM)
and "unplug" (which hot unplugs a network device from a running guest).
The second set of "connector classes" that we will consider determine how Hosts are attached to Networks
and Storage.
PIF A PIF (Physical InterFace) object represents an attachment between a
Host and a Network object. If a host is connected to a Network (via a PIF)
then packets from the specified host can be transmitted/received by the
corresponding host. Example fields of the PIF class include "device" (which
specifies the device name to which the PIF corresponds -- e.g. eth0) and
"MAC" (which specifies the MAC address of the underlying NIC that a PIF
represents). Note that PIFs abstract both physical interfaces and VLANs (the
latter distinguished by the existence of a positive integer in the "VLAN" field).

Overview of the XenServer API
9
PBD A PBD (Physical Block Device) object represents an attachment between
a Host and a SR (Storage Repository) object. Fields include "currently-
attached" (which specifies whether the chunk of storage represented
by the specified SR object) is currently available to the host; and
"device_config" (which specifies storage-driver specific parameters that
determines how the low-level storage devices are configured on the specified
host -- e.g. in the case of an SR rendered on an NFS filer, device_config may
specify the host-name of the filer and the path on the filer in which the SR files
live.)
Figure 3.1. Graphical overview of API classes for managing VMs, Hosts, Storage
and Networking
Figure 3.1, “Graphical overview of API classes for managing VMs, Hosts, Storage and Networking” presents
a graphical overview of the API classes involved in managing VMs, Hosts, Storage and Networking. From
this diagram, the symmetry between storage and network configuration, and also the symmetry between
virtual machine and host configuration is plain to see.
3.3. Working with VIFs and VBDs
In this section we walk through a few more complex scenarios, describing informally how various tasks
involving virtual storage and network devices can be accomplished using the API.
3.3.1. Creating disks and attaching them to VMs
Let's start by considering how to make a new blank disk image and attach it to a running VM. We will assume
that we already have ourselves a running VM, and we know its corresponding API object reference (e.g.
we may have created this VM using the procedure described in the previous section, and had the server
return its reference to us.) We will also assume that we have authenticated with the XenServer installation

Overview of the XenServer API
10
and have a corresponding session reference. Indeed in the rest of this chapter, for the sake of brevity, we
will stop mentioning sessions altogether.
3.3.1.1. Creating a new blank disk image
The first step is to instantiate the disk image on physical storage. We do this via a call to VDI.create(...).
The VDI.create call takes a number of parameters, including:
•name_label and name_description: a human-readable name/description for the disk (e.g. for convenient
display in the UI etc.). These fields can be left blank if desired.
•SR: the object reference of the Storage Repository representing the physical storage in which the VDI's
bits will be placed.
•read_only: setting this field to true indicates that the VDI can only be attached to VMs in a read-only
fashion. (Attempting to attach a VDI with its read_only field set to true in a read/write fashion results
in error.)
Invoking the VDI.create call causes the XenServer installation to create a blank disk image on physical
storage, create an associated VDI object (the datamodel instance that refers to the disk image on physical
storage) and return a reference to this newly created VDI object.
The way in which the disk image is represented on physical storage depends on the type of the SR in which
the created VDI resides. For example, if the SR is of type "lvm" then the new disk image will be rendered
as an LVM volume; if the SR is of type "nfs" then the new disk image will be a sparse VHD file created on
an NFS filer. (You can query the SR type through the API using the SR.get_type(..) call.)
3.3.1.2. Attaching the disk image to a VM
So far we have a running VM (that we assumed the existence of at the start of this example) and a fresh
VDI that we just created. Right now, these are both independent objects that exist on the XenServer Host,
but there is nothing linking them together. So our next step is to create such a link, associating the VDI
with our VM.
The attachment is formed by creating a new "connector" object called a VBD (Virtual Block Device). To
create our VBD we invoke the VBD.create(...) call. The VBD.create(..) call takes a number of parameters
including:
•VM: the object reference of the VM to which the VDI is to be attached
•VDI: the object reference of the VDI that is to be attached
•mode: specifies whether the VDI is to be attached in a read-only or a read-write fashion
•userdevice: specifies the block device inside the guest through which applications running inside the VM
will be able to read/write the VDI's bits.
•type: specifies whether the VDI should be presented inside the VM as a regular disk or as a CD. (Note that
this particular field has more meaning for Windows VMs than it does for Linux VMs, but will not explore
this level of detail in this chapter.)
Invoking VBD.create makes a VBD object on the XenServer installation and returns its object reference.
However, this call in itself does not have any side-effects on the running VM (i.e. if you go and look inside
the running VM you will see that the block device has not been created). The fact that the VBD object
exists but that the block device in the guest is not active, is reflected by the fact that the VBD object's
currently_attached field is set to false.

Overview of the XenServer API
11
Figure 3.2. A VM object with 2 associated VDIs
For expository purposes, Figure 3.2, “A VM object with 2 associated VDIs” presents a graphical example
that shows the relationship between VMs, VBDs, VDIs and SRs. In this instance a VM object has 2 attached
VDIs: there are 2 VBD objects that form the connections between the VM object and its VDIs; and the VDIs
reside within the same SR.
3.3.1.3. Hotplugging the VBD
If we rebooted the VM at this stage then, after rebooting, the block device corresponding to the VBD would
appear: on boot, XenServer queries all VBDs of a VM and actively attaches each of the corresponding VDIs.
Rebooting the VM is all very well, but recall that we wanted to attach a newly created blank disk to a
running VM. This can be achieved by invoking the plug method on the newly created VBD object. When
the plug call returns successfully, the block device to which the VBD relates will have appeared inside the
running VM -- i.e. from the perspective of the running VM, the guest operating system is lead to believe
that a new disk device has just been hot plugged. Mirroring this fact in the managed world of the API, the
currently_attached field of the VBD is set to true.
Unsurprisingly, the VBD plug method has a dual called "unplug". Invoking the unplug method on a
VBD object causes the associated block device to be hot unplugged from a running VM, setting the
currently_attached field of the VBD object to false accordingly.
3.3.2. Creating and attaching Network Devices to VMs
The API calls involved in configuring virtual network interfaces in VMs are similar in many respects to the
calls involved in configuring virtual disk devices. For this reason we will not run through a full example of
how one can create network interfaces using the API object-model; instead we will use this section just to
outline briefly the symmetry between virtual networking device and virtual storage device configuration.
The networking analogue of the VBD class is the VIF class. Just as a VBD is the API representation of a
block device inside a VM, a VIF (Virtual Network Device) is the API representation of a network device inside
a VM. Whereas VBDs associate VM objects with VDI objects, VIFs associate VM objects with Network
objects. Just like VBDs, VIFs have a currently_attached field that determines whether or not the network
device (inside the guest) associated with the VIF is currently active or not. And as we saw with VBDs, at
VM boot-time the VIFs of the VM are queried and a corresponding network device for each created inside
the booting VM. Similarly, VIFs also have plug and unplug methods for hot plugging/unplugging network
devices in/out of running VMs.
3.3.3. Host configuration for networking and storage
We have seen that the VBD and VIF classes are used to manage configuration of block devices and network
devices (respectively) inside VMs. To manage host configuration of storage and networking there are two
analogous classes: PBD (Physical Block Device) and PIF (Physical [network] InterFace).

Overview of the XenServer API
12
3.3.3.1. Host storage configuration: PBDs
Let us start by considering the PBD class. A PBD_create(...) call takes a number of parameters including:
Parameter Description
host physical machine on which the PBD is available
SR the Storage Repository that the PBD connects to
device_config a string-to-string map that is provided to the host's SR-backend-driver,
containing the low-level parameters required to configure the physical storage
device(s) on which the SR is to be realized. The specific contents of the
device_config field depend on the type of the SR to which the PBD
is connected. (Executing xe sm-list will show a list of possible SR types;
the configuration field in this enumeration specifies the device_config
parameters that each SR type expects.)
For example, imagine we have an SR object s of type "nfs" (representing a directory on an NFS filer within
which VDIs are stored as VHD files); and let's say that we want a host, h, to be able to access s. In this
case we invoke PBD.create(...) specifying host h, SR s, and a value for the device_config parameter that
is the following map:
("server", "my_nfs_server.example.com"), ("serverpath", "/scratch/mysrs/sr1")
This tells the XenServer Host that SR s is accessible on host h, and further that to access SR s, the host
needs to mount the directory "/scratch/mysrs/sr1" on the NFS server named "my_nfs_server.example.com."
Like VBD objects, PBD objects also have a field called currently_attached. Storage repositories can be
attached and detached from a given host by invoking PBD.plug and PBD.unplug methods respectively.
3.3.3.2. Host networking configuration: PIFs
Host network configuration is specified by virtue of PIF objects. If a PIF object connects a network object,
n, to a host object h, then the network corresponding to n is bridged onto a physical interface (or a physical
interface plus a VLAN tag) specified by the fields of the PIF object.
For example, imagine a PIF object exists connecting host h to a network n, and that device field of the
PIF object is set to "eth0." This means that all packets on network n are bridged to the NIC in the host
corresponding to host network device "eth0."
3.4. Exporting and Importing VMs
VMs can be exported to a file and later imported to any XenServer Host. The export protocol is a simple
HTTP(S) GET, which should be performed on the master. Authorization is either standard HTTP basic
authentication, or if a session has already been obtained, this can be used. The VM to export is specified
either by UUID or by reference. To keep track of the export, a task can be created and passed in via its
reference. The request might result in a redirect if the VM's disks are only accessible on a slave.
The followwing arguments are passed on the command line:
Argument Description
session_id the reference of the session being used to authenticate; required only
when not using HTTP basic authentication
task_id the reference of the task object with which to keep track of the operation
ref the reference of the VM; required only if not using the UUID

Overview of the XenServer API
13
Argument Description
uuid the uuid of the VM; required only if not using the reference
For example:
curl http://root:foo@xenserver/export&uuid=[VM UUID]&task_id= [task ID] -o export
To export just the metadata, use the URI http://server/export_metadata
The import protocol is similar, using HTTP(S) PUT. The [session_id] and [task_id] arguments are as for the
export. The [ref] and [uuid] are not used; a new reference and uuid will be generated for the VM. There are
some additional parameters:
Argument Description
restore if this parameter is true, the import is treated as replacing the original VM -
the implication of this currently is that the MAC addresses on the VIFs are
exactly as the export was, which will lead to conflicts if the original VM is
still being run.
force if this parameter is true, any checksum failures will be ignored (the default
is to destroy the VM if a checksum error is detected)
sr_id The reference of an SR into which the VM should be imported. The default
behaviour is to import into the Pool.default_SR.
To import just the metadata, use the URI http://server/import_metadata
3.5. Where to look next
In this chapter we have presented a brief high-level overview of the API and its object-model. The aim here
is not to present the detailed semantics of the API, but just to provide enough background for you to start
reading the code samples of the next chapter and to find your way around the more detailed XenEnterprise
Management API reference document.
There are a number of places you can find more information:
• The Administrators Guide contains an overview of the xe CLI. Since a good deal of xe commands are a
thin veneer over the API, playing with xe is a good way to start finding your way around the API object
model described in this chapter.
• The code samples in the next chapter provide some concrete instances of API coding in a variety of client
languages.
• The XenEnterprise Management API reference document provides a more detailed description of the API
semantics as well as describing the the format of XML/RPC messages on the wire. and
• There are a few scripts that use the API in the XenServer Host dom0 itself. For example, "/opt/xen-
source/libexec/shutdown" is a python program that cleanly shuts VMs down. This script is invoked when
the host itself is shutdown.

14
Chapter 4. Using the API
This chapter describes how to use the XenServer Management API from real programs to manage XenServ-
er Hosts and VMs. The chapter begins with a walk-through of a typical client application and demonstrates
how the API can be used to perform common tasks. Example code fragments are given in python syntax
but equivalent code in C and C# would look very similar. The language bindings themselves are discussed
afterwards and the chapter finishes with walk-throughs of two complete examples included in the SDK.
4.1. Anatomy of a typical application
This section describes the structure of a typical application using the XenServer Management API. Most
client applications begin by connecting to a XenServer Host and authenticating (e.g. with a username and
password). Assuming the authentication succeeds, the server will create a "session" object and return a
reference to the client. This reference will be passed as an argument to all future API calls. Once authenti-
cated, the client may search for references to other useful objects (e.g. XenServer Hosts, VMs, etc.) and
invoke operations on them. Operations may be invoked either synchronously or asynchronously; special
task objects represent the state and progress of asynchronous operations. These application elements are
all described in detail in the following sections.
4.1.1. Choosing a low-level transport
API calls can be issued over two transports:
• SSL-encrypted TCP on port 443 (https) over an IP network
• plaintext over a local Unix domain socket: /var/xapi/xapi
The SSL-encrypted TCP transport is used for all off-host traffic while the Unix domain socket can be used
from services running directly on the XenServer Host itself. In the SSL-encrypted TCP transport, all API calls
should be directed at the Resource Pool master; failure to do so will result in the error HOST_IS_SLAVE,
which includes the IP address of the master as an error parameter.
Note
As a special-case, all messages sent through the Unix domain socket are transparently forwarded
to the correct node.
4.1.2. Authentication and session handling
The vast majority of API calls take a session reference as their first parameter; failure to supply a valid
reference will result in a SESSION_INVALID error being returned. A session reference is acquired by sup-
plying a username and password to the login_with_password function.
Note
As a special-case, if this call is executed over the local Unix domain socket then the username and
password are ignored and the call always succeeds.
Every session has an associated "last active" timestamp which is updated on every API call. The server
software currently has a built-in limit of 200 active sessions and will remove those with the oldest "last active"
field if this limit is exceeded. In addition all sessions whose "last active" field is older than 24 hours are also
removed. Therefore it is important to:
Other manuals for DL385 - ProLiant - G5
2
This manual suits for next models
3
Table of contents
Other Citrix Software manuals
Popular Software manuals by other brands

ACRONIS
ACRONIS TRUE IMAGE CORPORATE WORKSTATION 9.1 user guide

Lucid
Lucid Fatal1ty Z77 Professional installation guide

Allworx
Allworx 24x brochure

ZyXEL Communications
ZyXEL Communications VANTAGE REPORT 2.3 - user guide

Sun Microsystems
Sun Microsystems GlassFish Enterprise Server installation guide

Adobe
Adobe DEVICE CENTRAL CS4 - READ ME Using