# HG changeset patch
# User Alastair Tse <atse@xxxxxxxxxxxxx>
# Node ID 029e04982e9439ad651f95eb97b306a52e726ff7
# Parent c88a78f8bed98c705aa2300d6d4ded13479e6986
[XENAPI] Support for VBD/VIF info listing in vm-list --long
Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx>
---
tools/python/scripts/README | 49 +++++++++++++++++++++++++++++++++++++++++++
tools/python/scripts/xapi.py | 47 ++++++++++++++++++++++++++++-------------
2 files changed, 81 insertions(+), 15 deletions(-)
diff -r c88a78f8bed9 -r 029e04982e94 tools/python/scripts/xapi.py
--- a/tools/python/scripts/xapi.py Fri Oct 06 16:27:06 2006 +0100
+++ b/tools/python/scripts/xapi.py Fri Oct 06 16:30:35 2006 +0100
@@ -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)
diff -r c88a78f8bed9 -r 029e04982e94 tools/python/scripts/README
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/python/scripts/README Fri Oct 06 16:30:35 2006 +0100
@@ -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.
+
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|