ia64/xen-unstable

changeset 12368:272cd2dc7cdf

[XENAPI] Make xapi.py work with modules in /usr/lib/python.

Also Add host_set_name command.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Nov 10 12:44:47 2006 +0000 (2006-11-10)
parents 5a4517468f4f
children d243a33a6e51
files tools/python/scripts/xapi.py
line diff
     1.1 --- a/tools/python/scripts/xapi.py	Fri Nov 10 11:01:15 2006 +0000
     1.2 +++ b/tools/python/scripts/xapi.py	Fri Nov 10 12:44:47 2006 +0000
     1.3 @@ -16,12 +16,16 @@
     1.4  # Copyright (C) 2006 XenSource Ltd.
     1.5  #============================================================================
     1.6  
     1.7 +import sys
     1.8 +sys.path.append('/usr/lib/python')
     1.9 +
    1.10  from xen.util.xmlrpclib2 import ServerProxy
    1.11  from optparse import *
    1.12  from pprint import pprint
    1.13  from types import DictType
    1.14  from getpass import getpass
    1.15  
    1.16 +
    1.17  MB = 1024 * 1024
    1.18  
    1.19  HOST_INFO_FORMAT = '%-20s: %-50s'
    1.20 @@ -34,6 +38,7 @@ VDI_LIST_FORMAT = '%(name_label)-18s %(u
    1.21  
    1.22  COMMANDS = {
    1.23      'host-info': ('', 'Get Xen Host Info'),
    1.24 +    'host-set-name': ('', 'Set host name'),
    1.25      'sr-list':   ('', 'List all SRs'),
    1.26      'vbd-create': ('<domname> <pycfg> [opts]',
    1.27                     'Create VBD attached to domname'),
    1.28 @@ -51,7 +56,7 @@ COMMANDS = {
    1.29      'vm-name':   ('<uuid>', 'Name of UUID.'),
    1.30      'vm-shutdown': ('<name> [opts]', 'Shutdown VM with name'),
    1.31      'vm-start':  ('<name>', 'Start VM with name'),
    1.32 -    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),    
    1.33 +    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),
    1.34  }
    1.35  
    1.36  OPTIONS = {
    1.37 @@ -175,6 +180,17 @@ def xapi_host_info(*args):
    1.38          print HOST_INFO_FORMAT % ('VMs', len(hostinfo['resident_VMs']))
    1.39          print HOST_INFO_FORMAT % ('UUID', host)        
    1.40  
    1.41 +def xapi_host_set_name(*args):
    1.42 +    if len(args) < 1:
    1.43 +        raise OptionError("No hostname specified")
    1.44 +    
    1.45 +    server, session = _connect()
    1.46 +    hosts = execute(server.host.get_all, session)
    1.47 +    if len(hosts) > 0:
    1.48 +        execute(server.host.set_name_label, session, hosts[0], args[0])
    1.49 +        print 'Hostname: %s' % execute(server.host.get_name_label, session,
    1.50 +                                       hosts[0])
    1.51 +
    1.52  def xapi_vm_uuid(*args):
    1.53      if len(args) < 1:
    1.54          raise OptionError("No domain name specified")