ia64/xen-unstable

changeset 1708:05488465ed73

bitkeeper revision 1.1041.15.4 (40ec223eOnMe3ErIY1RnrUzk0Wz5QQ)

Fix calls to opts.err().
author mjw@wray-m-3.hpl.hp.com
date Wed Jul 07 16:18:06 2004 +0000 (2004-07-07)
parents 6235d9c48836
children bae23a1177c6
files tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xm/create.py	Wed Jul 07 15:59:16 2004 +0000
     1.2 +++ b/tools/python/xen/xm/create.py	Wed Jul 07 16:18:06 2004 +0000
     1.3 @@ -193,45 +193,45 @@ def strip(pre, s):
     1.4      else:
     1.5          return s
     1.6  
     1.7 -def configure_image(config, opts):
     1.8 +def configure_image(config, vals):
     1.9      """Create the image config.
    1.10      """
    1.11 -    config_image = [ opts.builder ]
    1.12 -    config_image.append([ 'kernel', os.path.abspath(opts.kernel) ])
    1.13 -    if opts.ramdisk:
    1.14 -        config_image.append([ 'ramdisk', os.path.abspath(opts.ramdisk) ])
    1.15 -    if opts.cmdline_ip:
    1.16 -        cmdline_ip = strip('ip=', opts.cmdline_ip)
    1.17 +    config_image = [ vals.builder ]
    1.18 +    config_image.append([ 'kernel', os.path.abspath(vals.kernel) ])
    1.19 +    if vals.ramdisk:
    1.20 +        config_image.append([ 'ramdisk', os.path.abspath(vals.ramdisk) ])
    1.21 +    if vals.cmdline_ip:
    1.22 +        cmdline_ip = strip('ip=', vals.cmdline_ip)
    1.23          config_image.append(['ip', cmdline_ip])
    1.24 -    if opts.root:
    1.25 -        cmdline_root = strip('root=', opts.root)
    1.26 +    if vals.root:
    1.27 +        cmdline_root = strip('root=', vals.root)
    1.28          config_image.append(['root', cmdline_root])
    1.29 -    if opts.extra:
    1.30 -        config_image.append(['args', opts.extra])
    1.31 +    if vals.extra:
    1.32 +        config_image.append(['args', vals.extra])
    1.33      config.append(['image', config_image ])
    1.34      
    1.35 -def configure_disks(config_devs, opts):
    1.36 +def configure_disks(config_devs, vals):
    1.37      """Create the config for disks (virtual block devices).
    1.38      """
    1.39 -    for (uname, dev, mode) in opts.disk:
    1.40 +    for (uname, dev, mode) in vals.disk:
    1.41          config_vbd = ['vbd',
    1.42                        ['uname', uname],
    1.43                        ['dev', dev ],
    1.44                        ['mode', mode ] ]
    1.45          config_devs.append(['device', config_vbd])
    1.46  
    1.47 -def configure_pci(config_devs, opts):
    1.48 +def configure_pci(config_devs, vals):
    1.49      """Create the config for pci devices.
    1.50      """
    1.51 -    for (bus, dev, func) in opts.pci:
    1.52 +    for (bus, dev, func) in vals.pci:
    1.53          config_pci = ['pci', ['bus', bus], ['dev', dev], ['func', func]]
    1.54          config_devs.append(['device', config_pci])
    1.55  
    1.56 -def configure_vifs(config_devs, opts):
    1.57 +def configure_vifs(config_devs, vals):
    1.58      """Create the config for virtual network interfaces.
    1.59      """
    1.60 -    vifs = opts.vif
    1.61 -    vifs_n = max(opts.nics, len(vifs))
    1.62 +    vifs = vals.vif
    1.63 +    vifs_n = max(vals.nics, len(vifs))
    1.64  
    1.65      for idx in range(0, vifs_n):
    1.66          if idx < len(vifs):
    1.67 @@ -248,65 +248,65 @@ def configure_vifs(config_devs, opts):
    1.68              config_vif.append(['bridge', bridge])
    1.69          config_devs.append(['device', config_vif])
    1.70  
    1.71 -def configure_vfr(config, opts):
    1.72 -     if not opts.ipaddr: return
    1.73 +def configure_vfr(config, vals):
    1.74 +     if not vals.ipaddr: return
    1.75       config_vfr = ['vfr']
    1.76       idx = 0 # No way of saying which IP is for which vif?
    1.77 -     for ip in opts.ipaddr:
    1.78 +     for ip in vals.ipaddr:
    1.79           config_vfr.append(['vif', ['id', idx], ['ip', ip]])
    1.80       config.append(config_vfr)
    1.81  
    1.82  
    1.83 -def make_config(opts):
    1.84 +def make_config(vals):
    1.85      """Create the domain configuration.
    1.86      """
    1.87      
    1.88      config = ['vm',
    1.89 -              ['name', opts.name ],
    1.90 -              ['memory', opts.memory ] ]
    1.91 -    if opts.cpu:
    1.92 -        config.append(['cpu', opts.cpu])
    1.93 -    if opts.blkif:
    1.94 +              ['name', vals.name ],
    1.95 +              ['memory', vals.memory ] ]
    1.96 +    if vals.cpu:
    1.97 +        config.append(['cpu', vals.cpu])
    1.98 +    if vals.blkif:
    1.99          config.append(['backend', ['blkif']])
   1.100 -    if opts.netif:
   1.101 +    if vals.netif:
   1.102          config.append(['backend', ['netif']])
   1.103 -    if opts.autorestart:
   1.104 +    if vals.autorestart:
   1.105          config.append(['autorestart'])
   1.106      
   1.107 -    configure_image(config, opts)
   1.108 +    configure_image(config, vals)
   1.109      config_devs = []
   1.110 -    configure_disks(config_devs, opts)
   1.111 -    configure_pci(config_devs, opts)
   1.112 -    configure_vifs(config_devs, opts)
   1.113 +    configure_disks(config_devs, vals)
   1.114 +    configure_pci(config_devs, vals)
   1.115 +    configure_vifs(config_devs, vals)
   1.116      config += config_devs
   1.117      return config
   1.118  
   1.119 -def preprocess_disk(opts):
   1.120 -    if not opts.disk: return
   1.121 +def preprocess_disk(opts, vals):
   1.122 +    if not vals.disk: return
   1.123      disk = []
   1.124 -    for v in opts.disk:
   1.125 +    for v in vals.disk:
   1.126          d = v.split(',')
   1.127          if len(d) != 3:
   1.128              opts.err('Invalid disk specifier: ' + v)
   1.129          disk.append(d)
   1.130 -    opts.disk = disk
   1.131 +    vals.disk = disk
   1.132  
   1.133 -def preprocess_pci(opts):
   1.134 -    if not opts.pci: return
   1.135 +def preprocess_pci(opts, vals):
   1.136 +    if not vals.pci: return
   1.137      pci = []
   1.138 -    for v in opts.pci:
   1.139 +    for v in vals.pci:
   1.140          d = v.split(',')
   1.141          if len(d) != 3:
   1.142              opts.err('Invalid pci specifier: ' + v)
   1.143          # Components are in hex: add hex specifier.
   1.144          hexd = map(lambda v: '0x'+v, d)
   1.145          pci.append(hexd)
   1.146 -    opts.pci = pci
   1.147 +    vals.pci = pci
   1.148  
   1.149 -def preprocess_vifs(opts):
   1.150 -    if not opts.vif: return
   1.151 +def preprocess_vifs(opts, vals):
   1.152 +    if not vals.vif: return
   1.153      vifs = []
   1.154 -    for vif in opts.vif:
   1.155 +    for vif in vals.vif:
   1.156          d = {}
   1.157          a = vif.split(',')
   1.158          for b in a:
   1.159 @@ -317,43 +317,42 @@ def preprocess_vifs(opts):
   1.160                  opts.err('Invalid vif specifier: ' + vif)
   1.161              d[k] = v
   1.162          vifs.append(d)
   1.163 -    opts.vif = vifs
   1.164 +    vals.vif = vifs
   1.165  
   1.166 -def preprocess_ip(opts):
   1.167 -    setip = (opts.hostname or opts.netmask
   1.168 -             or opts.gateway or opts.dhcp or opts.interface)
   1.169 +def preprocess_ip(opts, vals):
   1.170 +    setip = (vals.hostname or vals.netmask
   1.171 +             or vals.gateway or vals.dhcp or vals.interface)
   1.172      if not setip: return
   1.173 -    #if not opts
   1.174 -    ip = (opts.ip
   1.175 +    ip = (vals.ip
   1.176            + ':'
   1.177 -          + ':' + opts.gateway
   1.178 -          + ':' + opts.netmask
   1.179 -          + ':' + opts.hostname
   1.180 -          + ':' + opts.interface
   1.181 -          + ':' + opts.dhcp)
   1.182 -    opts.cmdline_ip = ip
   1.183 +          + ':' + vals.gateway
   1.184 +          + ':' + vals.netmask
   1.185 +          + ':' + vals.hostname
   1.186 +          + ':' + vals.interface
   1.187 +          + ':' + vals.dhcp)
   1.188 +    vals.cmdline_ip = ip
   1.189  
   1.190 -def preprocess_nfs(opts):
   1.191 -    if (opts.nfs_root or opts.nfs_server):
   1.192 -        if (not opts.nfs_root) or (not opts.nfs_server):
   1.193 +def preprocess_nfs(opts, vals):
   1.194 +    if (vals.nfs_root or vals.nfs_server):
   1.195 +        if (not vals.nfs_root) or (not vals.nfs_server):
   1.196              opts.err('Must set nfs root and nfs server')
   1.197      else:
   1.198          return
   1.199 -    nfs = 'nfsroot=' + opts.nfs_server + ':' + opts.nfs_root
   1.200 -    opts.extra = nfs + ' ' + opts.extra
   1.201 +    nfs = 'nfsroot=' + vals.nfs_server + ':' + vals.nfs_root
   1.202 +    vals.extra = nfs + ' ' + vals.extra
   1.203      
   1.204 -def preprocess(opts):
   1.205 -    if not opts.kernel:
   1.206 +def preprocess(opts, vals):
   1.207 +    if not vals.kernel:
   1.208          opts.err("No kernel specified")
   1.209 -    preprocess_disk(opts)
   1.210 -    preprocess_pci(opts)
   1.211 -    preprocess_vifs(opts)
   1.212 -    preprocess_ip(opts)
   1.213 -    preprocess_nfs(opts)
   1.214 +    preprocess_disk(opts, vals)
   1.215 +    preprocess_pci(opts, vals)
   1.216 +    preprocess_vifs(opts, vals)
   1.217 +    preprocess_ip(opts, vals)
   1.218 +    preprocess_nfs(opts, vals)
   1.219           
   1.220  def make_domain(opts, config):
   1.221      """Create, build and start a domain.
   1.222 -    Returns: [int] the ID of the new domain.
   1.223 +    Returns: pair: [int] the ID of the new domain, [int] console port
   1.224      """
   1.225      if opts.vals.load:
   1.226          filename = os.path.abspath(opts.vals.load)
   1.227 @@ -393,7 +392,7 @@ def main(argv):
   1.228          pass
   1.229      else:
   1.230          opts.load_defaults()
   1.231 -    preprocess(opts.vals)
   1.232 +    preprocess(opts, opts.vals)
   1.233      config = make_config(opts.vals)
   1.234      if opts.vals.dryrun:
   1.235          PrettyPrint.prettyprint(config)