[XENAPI] Make xapi.py work with modules in /usr/lib/python.
authorAlastair Tse <atse@xensource.com>
Fri, 10 Nov 2006 12:44:47 +0000 (12:44 +0000)
committerAlastair Tse <atse@xensource.com>
Fri, 10 Nov 2006 12:44:47 +0000 (12:44 +0000)
Also Add host_set_name command.

Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/scripts/xapi.py

index 8dc7a4012f0144b3effde76e857693d3889d599a..387ad0a487d260b793d845247a54f938549a15f6 100644 (file)
 # Copyright (C) 2006 XenSource Ltd.
 #============================================================================
 
+import sys
+sys.path.append('/usr/lib/python')
+
 from xen.util.xmlrpclib2 import ServerProxy
 from optparse import *
 from pprint import pprint
 from types import DictType
 from getpass import getpass
 
+
 MB = 1024 * 1024
 
 HOST_INFO_FORMAT = '%-20s: %-50s'
@@ -34,6 +38,7 @@ VDI_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(virtual_size)-8s '\
 
 COMMANDS = {
     'host-info': ('', 'Get Xen Host Info'),
+    'host-set-name': ('', 'Set host name'),
     'sr-list':   ('', 'List all SRs'),
     'vbd-create': ('<domname> <pycfg> [opts]',
                    'Create VBD attached to domname'),
@@ -51,7 +56,7 @@ COMMANDS = {
     'vm-name':   ('<uuid>', 'Name of UUID.'),
     'vm-shutdown': ('<name> [opts]', 'Shutdown VM with name'),
     'vm-start':  ('<name>', 'Start VM with name'),
-    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),    
+    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),
 }
 
 OPTIONS = {
@@ -175,6 +180,17 @@ def xapi_host_info(*args):
         print HOST_INFO_FORMAT % ('VMs', len(hostinfo['resident_VMs']))
         print HOST_INFO_FORMAT % ('UUID', host)        
 
+def xapi_host_set_name(*args):
+    if len(args) < 1:
+        raise OptionError("No hostname specified")
+    
+    server, session = _connect()
+    hosts = execute(server.host.get_all, session)
+    if len(hosts) > 0:
+        execute(server.host.set_name_label, session, hosts[0], args[0])
+        print 'Hostname: %s' % execute(server.host.get_name_label, session,
+                                       hosts[0])
+
 def xapi_vm_uuid(*args):
     if len(args) < 1:
         raise OptionError("No domain name specified")