[XENAPI] Support for VBD/VIF info listing in vm-list --long

Signed-off-by: Alastair Tse <atse@xensource.com>
This commit is contained in:
Alastair Tse committed 2006-10-06 16:30:35 +01:00
1 parent 943f4e6d26
commit fde78b356e
2 files changed
+81 -15

No files matched your search

+49
View File
@@ -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.
+32 -15
View File
@@ -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)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.