HP BL680c XenServer Software Development Kit Guide 4.1.0 - Page 25

Command Line Interface (CLI), 4.3. Complete application examples

Page 25 highlights

Using the API • permute.py: selects a set of VMs and uses XenMotion to move them simultaneously between hosts; • powercycle.py: selects a set of VMs and powercycles them; • shell.py: a simple interactive shell for testing; • vm_start_async.py: demonstrates how to invoke operations asynchronously; and • watch-all-events.py: registers for all events and prints details when they occur. 4.2.4. Command Line Interface (CLI) Rather than using raw XML-RPC or one of the supplied language bindings, third-party software developers may instead integrate with XenServer Hosts by using the XE CLI xe.exe. CLI dependencies Platform supported: Linux and Windows Library: None Binary: xe[.exe] Dependencies:None The CLI allows almost every API call to be directly invoked from a script or other program, silently taking care of the required session management. The XE CLI syntax and capabilities are described in detail in Chapter 5 of the XenServer Administrator's Guide. The SDK contains 3 example bash shell scripts which demonstrate CLI usage. These are: • install-debian: installs a Debian Etch 4.0 VM, adds a network interface, starts it booting and waits for the IP address to be reported; • clone-vms: shuts down a VM if it is running, clones it and starts it up again; and • suspend-resume: suspends a running VM and then resumes it. Note When running the CLI from a XenServer Host console, tab-completion of both command names and arguments is available. 4.3. Complete application examples This section describes two complete examples of real programs using the API. The application source code is contained within the SDK. 4.3.1. Simultaneously migrating VMs using XenMotion This python example (contained in /SDK/client-examples/python/permute.py) demonstrates how to use XenMotion to move VMs simultaneously between hosts in a Resource Pool. The example makes use of asynchronous API calls and shows how to wait for a set of tasks to complete. The program begins with some standard boilerplate and imports the API bindings module 19

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

Using the API
19
permute.py
: selects a set of VMs and uses XenMotion to move them simultaneously between hosts;
powercycle.py
: selects a set of VMs and powercycles them;
shell.py
: a simple interactive shell for testing;
vm_start_async.py
: demonstrates how to invoke operations asynchronously; and
watch-all-events.py
: registers for all events and prints details when they occur.
4.2.4. Command Line Interface (CLI)
Rather than using raw XML-RPC or one of the supplied language bindings, third-party software developers
may instead integrate with XenServer Hosts by using the XE CLI
xe.exe
.
CLI dependencies
Platform
supported:
Linux and Windows
Library:
None
Binary:
xe[.exe]
Dependencies:
None
The CLI allows almost every API call to be directly invoked from a script or other program, silently taking
care of the required session management. The XE CLI syntax and capabilities are described in detail in
Chapter 5 of the XenServer Administrator's Guide. The SDK contains 3 example
bash
shell scripts which
demonstrate CLI usage. These are:
install-debian
: installs a Debian Etch 4.0 VM, adds a network interface, starts it booting and waits for
the IP address to be reported;
clone-vms
: shuts down a VM if it is running, clones it and starts it up again; and
suspend-resume
: suspends a running VM and then resumes it.
Note
When running the CLI from a XenServer Host console, tab-completion of both command names
and arguments is available.
4.3. Complete application examples
This section describes two complete examples of real programs using the API. The application source code
is contained within the SDK.
4.3.1. Simultaneously migrating VMs using XenMotion
This python example (contained in
/SDK/client-examples/python/permute.py
) demonstrates how
to use XenMotion to move VMs simultaneously between hosts in a Resource Pool. The example makes
use of asynchronous API calls and shows how to wait for a set of tasks to complete.
The program begins with some standard boilerplate and imports the API bindings module