aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python/scripts
diff options
context:
space:
mode:
authorAlastair Tse <atse@xensource.com>2006-10-06 16:30:35 +0100
committerAlastair Tse <atse@xensource.com>2006-10-06 16:30:35 +0100
commitfde78b356e9d80668bd0d1365ee5ab9e1dfee716 (patch)
treed4728b0ed5ca32584a22d730fb167e003e03ead2 /tools/python/scripts
parent943f4e6d268ba2a8c0f7904701b6d5e678b57a5f (diff)
downloadxen-fde78b356e9d80668bd0d1365ee5ab9e1dfee716.tar.gz
xen-fde78b356e9d80668bd0d1365ee5ab9e1dfee716.tar.bz2
xen-fde78b356e9d80668bd0d1365ee5ab9e1dfee716.zip
[XENAPI] Support for VBD/VIF info listing in vm-list --long
Signed-off-by: Alastair Tse <atse@xensource.com>
Diffstat (limited to 'tools/python/scripts')
-rw-r--r--tools/python/scripts/README49
-rw-r--r--tools/python/scripts/xapi.py47
2 files changed, 81 insertions, 15 deletions
diff --git a/tools/python/scripts/README b/tools/python/scripts/README
new file mode 100644
index 0000000000..a5d87592ae
--- /dev/null
+++ b/tools/python/scripts/README
@@ -0,0 +1,49 @@
+Xen API Test
+============
+
+xapi.py is a simple command line tool to test the functionality of a
+domain lifecycle supporting, Xen API talking version of Xend.
+
+Creating a VM is slightly more work under the Xen API. The differences
+with this and xm is:
+
+1. None of the devices are created during vm-create. You must use
+ vbd-create and vif-create to attach a new device to the VM.
+
+2. VM's that are created using vm-create will not start by
+ default. You must use vm-start to "start" the domain.
+
+3. VM's that are created using vm-create will not be removed on
+ shutdown. You must remove it using vm-delete.
+
+Example Configuration Files
+---------------------------
+
+xapi.py uses a simple python configuration file similar to xm in the
+face of the lack of any other reasonable format.
+
+All the fields are directly mapped to the arguments that are in the
+Xen API constructore for the respective classes.
+
+xapi.domcfg.py: example configuration for a paravirtualised domain.
+xapi.vbdcfg.py: example configuration for a file based block device.
+xapi.vifcfg.py: example configuration for a simple bridged network
+ device.
+
+Example Session
+---------------
+
+xapi.py vm-list
+xapi.py vm-create xapi.domcfg.py
+xapi.py vbd-create <DomainName> xapi.vbdcfg.py
+xapi.py vif-create <DomainName> xapi.vifcfg.py
+
+Notes
+-----
+
+Currently lacking:
+
+1. Any real authentication. XendAuthSessions need to be filled in with
+ a proper authentication implementation either using PAM or other
+ means.
+
diff --git a/tools/python/scripts/xapi.py b/tools/python/scripts/xapi.py
index 4e12dc97b5..5c5dddc196 100644
--- a/tools/python/scripts/xapi.py
+++ b/tools/python/scripts/xapi.py
@@ -36,7 +36,7 @@ COMMANDS = {
'vm-delete': ('<domname>', 'Delete VM'),
'vm-destroy': ('<name>', 'Hard shutdown a VM with name'),
- 'vm-list': ('', 'List all domains.'),
+ 'vm-list': ('[--long]', 'List all domains.'),
'vm-name': ('<uuid>', 'Name of UUID.'),
'vm-shutdown': ('<name>', 'Shutdown VM with name'),
'vm-start': ('<name>', 'Start VM with name'),
@@ -62,13 +62,15 @@ class XenAPIError(Exception):
#
def parse_args(cmd_name, args):
+ argstring, desc = COMMANDS[cmd_name]
+ parser = OptionParser(usage = 'xapi %s %s' % (cmd_name, argstring),
+ description = desc)
if cmd_name in OPTIONS:
- parser = OptionParser()
for optargs, optkwds in OPTIONS[cmd_name]:
parser.add_option(*optargs, **optkwds)
- (opts, extraargs) = parser.parse_args(list(args))
- return opts, extraargs
- return None, []
+
+ (opts, extraargs) = parser.parse_args(list(args))
+ return opts, extraargs
def execute(fn, *args):
result = fn(*args)
@@ -141,6 +143,18 @@ def xapi_vm_list(*args):
for uuid in vm_uuids:
vm_info = execute(server.VM.get_record, session, uuid)
if is_long:
+ vbds = vm_info['vbds']
+ vifs = vm_info['vifs']
+ vif_infos = []
+ vbd_infos = []
+ for vbd in vbds:
+ vbd_info = execute(server.VBD.get_record, session, vbd)
+ vbd_infos.append(vbd_info)
+ for vif in vifs:
+ vif_info = execute(server.VIF.get_record, session, vif)
+ vif_infos.append(vif_info)
+ vm_info['vbds'] = vbd_infos
+ vm_info['vifs'] = vif_infos
pprint(vm_info)
else:
print VM_LIST_FORMAT % _stringify(vm_info)
@@ -234,15 +248,18 @@ def xapi_vif_create(*args):
#
def usage(command = None):
- print 'Usage: xapi <subcommand> [options] [args]'
- print
- print 'Subcommands:'
- print
- sorted_commands = sorted(COMMANDS.keys())
- for command in sorted_commands:
- args, description = COMMANDS[command]
- print '%-16s %-40s' % (command, description)
- print
+ if not command:
+ print 'Usage: xapi <subcommand> [options] [args]'
+ print
+ print 'Subcommands:'
+ print
+ sorted_commands = sorted(COMMANDS.keys())
+ for command in sorted_commands:
+ args, description = COMMANDS[command]
+ print '%-16s %-40s' % (command, description)
+ print
+ else:
+ parse_args(command, ['-h'])
def main(args):
@@ -267,7 +284,7 @@ def main(args):
subcmd_func(*args[1:])
except XenAPIError, e:
print 'Error: %s' % str(e.args[1])
- sys.exit(1)
+ sys.exit(2)
sys.exit(0)