aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python/scripts
diff options
context:
space:
mode:
authorAlastair Tse <atse@xensource.com>2006-10-12 18:51:17 +0100
committerAlastair Tse <atse@xensource.com>2006-10-12 18:51:17 +0100
commit25563684509394ce813e74634850b2392e2b9cc1 (patch)
tree9a0389270f568efcef923405c1024abaf170faf2 /tools/python/scripts
parent6450b246e10e16be2515dca0fd80b53d9155ab73 (diff)
downloadxen-25563684509394ce813e74634850b2392e2b9cc1.tar.gz
xen-25563684509394ce813e74634850b2392e2b9cc1.tar.bz2
xen-25563684509394ce813e74634850b2392e2b9cc1.zip
[XEND] Adding API stub generation to XendAPI + SR implementation for
Xen API. Fixed *get_by_label functions to return a Set rather than only one result. Signed-off-by: Alastair Tse <atse@xensource.com>
Diffstat (limited to 'tools/python/scripts')
-rw-r--r--tools/python/scripts/xapi.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/tools/python/scripts/xapi.py b/tools/python/scripts/xapi.py
index 6b4c40df6d..6ba6e19893 100644
--- a/tools/python/scripts/xapi.py
+++ b/tools/python/scripts/xapi.py
@@ -96,6 +96,13 @@ def _read_python_cfg(filename):
execfile(filename, {}, cfg)
return cfg
+def resolve_vm(server, session, vm_name):
+ vm_uuid = execute(server.VM.get_by_label, session, vm_name)
+ if not vm_uuid:
+ return None
+ else:
+ return vm_uuid[0]
+
#
# Actual commands
#
@@ -116,7 +123,7 @@ def xapi_vm_uuid(*args):
raise OptionError("No domain name specified")
server, session = _connect()
- vm_uuid = execute(server.VM.get_by_label, session, args[0])
+ vm_uuid = resolve_vm(server, session, args[0])
print vm_uuid
def xapi_vm_name(*args):
@@ -177,7 +184,7 @@ def xapi_vm_delete(*args):
raise OptionError("No domain name specified.")
server, session = _connect()
- vm_uuid = execute(server.VM.get_by_label, session, args[0])
+ vm_uuid = resolve_vm(server, session, args[0])
print 'Destroying VM %s (%s)' % (args[0], vm_uuid)
success = execute(server.VM.destroy, session, vm_uuid)
print 'Done.'
@@ -198,7 +205,7 @@ def xapi_vm_shutdown(*args):
raise OptionError("No Domain name specified.")
server, session = _connect()
- vm_uuid = execute(server.VM.get_by_label, session, args[0])
+ vm_uuid = resolve_vm(server, session, args[0])
print 'Shutting down VM %s (%s)' % (args[0], vm_uuid)
success = execute(server.VM.clean_shutdown, session, vm_uuid)
print 'Done.'
@@ -208,7 +215,7 @@ def xapi_vm_destroy(*args):
raise OptionError("No Domain name specified.")
server, session = _connect()
- vm_uuid = execute(server.VM.get_by_label, session, args[0])
+ vm_uuid = resolve_vm(server, session, args[0])
print 'Shutting down VM with force %s (%s)' % (args[0], vm_uuid)
success = execute(server.VM.hard_shutdown, session, vm_uuid)
print 'Done.'
@@ -222,7 +229,7 @@ def xapi_vbd_create(*args):
cfg = _read_python_cfg(filename)
print 'Creating VBD from %s ..' % filename
server, session = _connect()
- vm_uuid = execute(server.VM.get_by_label, session, domname)
+ vm_uuid = resolve_vm(server, session, domname)
cfg['VM'] = vm_uuid
vbd_uuid = execute(server.VBD.create, session, cfg)
print 'Done. (%s)' % vbd_uuid
@@ -236,7 +243,7 @@ def xapi_vif_create(*args):
cfg = _read_python_cfg(filename)
print 'Creating VIF from %s ..' % filename
server, session = _connect()
- vm_uuid = execute(server.VM.get_by_label, session, domname)
+ vm_uuid = resolve_vm(server, session, domname)
cfg['VM'] = vm_uuid
vif_uuid = execute(server.VIF.create, session, cfg)
print 'Done. (%s)' % vif_uuid