ia64/xen-unstable

changeset 8330:55d464295da3

Deprecate the nics option from the xm create configuration. Instead, we use the
entries in vif to guide the configuration. This is much less confusing.

Closes bug #440.

Change the example configuration files to match. Also change them to use the
XenSource OUI in the MAC addresses. Also change xm-test to match.

Remove the obsolete ipaddr configuration entry, and the backend_mac vif config
option.

Remove the preprocess_vifs function, folding it into the configure_vifs
function, and creating a simple comma_sep_kv_to_dict helper.

Remove the configure_vfr method, as it is unused.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Dec 13 00:15:53 2005 +0000 (2005-12-13)
parents fa5dddabda0c
children d80066fa2dc2
files docs/src/user.tex tools/examples/xmexample.nbd tools/examples/xmexample.vmx tools/examples/xmexample.vti tools/examples/xmexample1 tools/examples/xmexample2 tools/examples/xmexample3 tools/python/xen/xm/create.py tools/xm-test/lib/XmTestLib/XenDomain.py tools/xm-test/tests/create/13_create_multinic_pos.py tools/xm-test/tests/network/02_network_local_ping_pos.py tools/xm-test/tests/network/05_network_dom0_ping_pos.py tools/xm-test/tests/network/11_network_domU_ping_pos.py tools/xm-test/tests/restore/04_restore_withdevices_pos.py
line diff
     1.1 --- a/docs/src/user.tex	Tue Dec 13 00:10:19 2005 +0000
     1.2 +++ b/docs/src/user.tex	Tue Dec 13 00:15:53 2005 +0000
     1.3 @@ -1087,16 +1087,17 @@ for concrete examples.
     1.4  \item[vcpus] The number of virtual CPUs. 
     1.5  \item[console] Port to export the domain console on (default 9600 +
     1.6    domain ID).
     1.7 -\item[nics] Number of virtual network interfaces.
     1.8 -\item[vif] List of MAC addresses (random addresses are assigned if not
     1.9 -  given) and bridges to use for the domain's network interfaces, e.g.\ 
    1.10 +\item[vif] Network interface configuration.  This may simply contain
    1.11 +an empty string for each desired interface, or may override various
    1.12 +settings, e.g.\ 
    1.13  \begin{verbatim}
    1.14  vif = [ 'mac=00:16:3E:00:00:11, bridge=xen-br0',
    1.15          'bridge=xen-br1' ]
    1.16  \end{verbatim}
    1.17    to assign a MAC address and bridge to the first interface and assign
    1.18    a different bridge to the second interface, leaving \xend\ to choose
    1.19 -  the MAC address.
    1.20 +  the MAC address.  The settings that may be overridden in this way are
    1.21 +  type, mac, bridge, ip, script, backend, and vifname.
    1.22  \item[disk] List of block devices to export to the domain e.g. 
    1.23    \verb_disk = [ 'phy:hda1,sda1,r' ]_ 
    1.24    exports physical device \path{/dev/hda1} to the domain as
     2.1 --- a/tools/examples/xmexample.nbd	Tue Dec 13 00:10:19 2005 +0000
     2.2 +++ b/tools/examples/xmexample.nbd	Tue Dec 13 00:15:53 2005 +0000
     2.3 @@ -12,9 +12,7 @@ kernel = "/boot/vmlinuz-2.6.13-15b-xen"
     2.4  ramdisk = "/boot/initrd-2.6.13-15b-xen"
     2.5  memory = 128
     2.6  name = "nbd4"
     2.7 -nics=1
     2.8 -# Please change MAC
     2.9 -vif = [ 'mac=aa:cc:10:10:00:a0, bridge=xenbr0' ]
    2.10 +vif = [ '' ]
    2.11  # Please change PORT
    2.12  disk = [ 'nbd:134.100.233.115 20004,hda1,w' ]
    2.13  dhcp = "dhcp"
     3.1 --- a/tools/examples/xmexample.vmx	Tue Dec 13 00:10:19 2005 +0000
     3.2 +++ b/tools/examples/xmexample.vmx	Tue Dec 13 00:15:53 2005 +0000
     3.3 @@ -37,9 +37,7 @@ vcpus=1
     3.4  
     3.5  # Optionally define mac and/or bridge for the network interfaces.
     3.6  # Random MACs are assigned if not given.
     3.7 -# nics default is 1
     3.8 -#vif = [ 'type=ioemu, mac=aa:00:00:00:00:11, bridge=xenbr0' ]
     3.9 -nics=1 
    3.10 +#vif = [ 'type=ioemu, mac=00:16:3e:00:00:11, bridge=xenbr0' ]
    3.11  # type=ioemu specify the NIC is an ioemu device not netfront
    3.12  vif = [ 'type=ioemu, bridge=xenbr0' ]
    3.13  
     4.1 --- a/tools/examples/xmexample.vti	Tue Dec 13 00:10:19 2005 +0000
     4.2 +++ b/tools/examples/xmexample.vti	Tue Dec 13 00:15:53 2005 +0000
     4.3 @@ -28,12 +28,9 @@ name = "ExampleVMXDomain"
     4.4  #cpus = "0"        # all vcpus run on CPU0
     4.5  #cpus = "0-3,5,^1" # run on cpus 0,2,3,5
     4.6  
     4.7 -# Disable vif for now
     4.8 -nics=0
     4.9 -
    4.10  # Optionally define mac and/or bridge for the network interfaces.
    4.11  # Random MACs are assigned if not given.
    4.12 -#vif = [ 'mac=aa:00:00:00:00:11, bridge=xen-br0' ]
    4.13 +#vif = [ 'mac=00:16:3e:00:00:11, bridge=xen-br0' ]
    4.14  
    4.15  #----------------------------------------------------------------------------
    4.16  # Define the disk devices you want the domain to have access to, and
     5.1 --- a/tools/examples/xmexample1	Tue Dec 13 00:10:19 2005 +0000
     5.2 +++ b/tools/examples/xmexample1	Tue Dec 13 00:15:53 2005 +0000
     5.3 @@ -33,12 +33,20 @@ name = "ExampleDomain"
     5.4  #----------------------------------------------------------------------------
     5.5  # Define network interfaces.
     5.6  
     5.7 -# Number of network interfaces. Default is 1.
     5.8 -#nics=1
     5.9 +# By default, no network interfaces are configured.  You may have one created
    5.10 +# with sensible defaults using an empty vif clause:
    5.11 +#
    5.12 +# vif = [ '' ]
    5.13 +#
    5.14 +# or optionally override backend, bridge, ip, mac, script, type, or vifname:
    5.15 +#
    5.16 +# vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ]
    5.17 +#
    5.18 +# or more than one interface may be configured:
    5.19 +#
    5.20 +# vif = [ '', 'bridge=xenbr1' ]
    5.21  
    5.22 -# Optionally define mac and/or bridge for the network interfaces.
    5.23 -# Random MACs are assigned if not given.
    5.24 -#vif = [ 'mac=aa:00:00:00:00:11, bridge=xenbr0' ]
    5.25 +vif = [ '' ]
    5.26  
    5.27  #----------------------------------------------------------------------------
    5.28  # Define the disk devices you want the domain to have access to, and
     6.1 --- a/tools/examples/xmexample2	Tue Dec 13 00:10:19 2005 +0000
     6.2 +++ b/tools/examples/xmexample2	Tue Dec 13 00:15:53 2005 +0000
     6.3 @@ -64,12 +64,20 @@ vcpus = 4 # make your domain a 4-way
     6.4  #----------------------------------------------------------------------------
     6.5  # Define network interfaces.
     6.6  
     6.7 -# Number of network interfaces. Default is 1.
     6.8 -#nics=1
     6.9 +# By default, no network interfaces are configured.  You may have one created
    6.10 +# with sensible defaults using an empty vif clause:
    6.11 +#
    6.12 +# vif = [ '' ]
    6.13 +#
    6.14 +# or optionally override backend, bridge, ip, mac, script, type, or vifname:
    6.15 +#
    6.16 +# vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ]
    6.17 +#
    6.18 +# or more than one interface may be configured:
    6.19 +#
    6.20 +# vif = [ '', 'bridge=xenbr1' ]
    6.21  
    6.22 -# Optionally define mac and/or bridge for the network interfaces.
    6.23 -# Random MACs are assigned if not given.
    6.24 -#vif = [ 'mac=aa:00:00:00:00:11, bridge=xenbr0' ]
    6.25 +vif = [ '' ]
    6.26  
    6.27  #----------------------------------------------------------------------------
    6.28  # Define the disk devices you want the domain to have access to, and
     7.1 --- a/tools/examples/xmexample3	Tue Dec 13 00:10:19 2005 +0000
     7.2 +++ b/tools/examples/xmexample3	Tue Dec 13 00:15:53 2005 +0000
     7.3 @@ -60,9 +60,6 @@ cpus = "%s" % vmid # set based on vmid (
     7.4  #----------------------------------------------------------------------------
     7.5  # Define network interfaces.
     7.6  
     7.7 -# Number of network interfaces. Default is 1.
     7.8 -#nics=1
     7.9 -
    7.10  # Optionally define mac and/or bridge for the network interfaces.
    7.11  # Random MACs are assigned if not given.
    7.12  
     8.1 --- a/tools/python/xen/xm/create.py	Tue Dec 13 00:10:19 2005 +0000
     8.2 +++ b/tools/python/xen/xm/create.py	Tue Dec 13 00:15:53 2005 +0000
     8.3 @@ -253,17 +253,12 @@ gopts.var('usb', val='PATH',
     8.4            use="""Add a physical USB port to a domain, as specified by the path
     8.5            to that port.  This option may be repeated to add more than one port.""")
     8.6  
     8.7 -gopts.var('ipaddr', val="IPADDR",
     8.8 -          fn=append_value, default=[],
     8.9 -          use="Add an IP address to the domain.")
    8.10 -
    8.11 -gopts.var('vif', val="type=TYPE,mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME",
    8.12 +gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT,backend=DOM,vifname=NAME",
    8.13            fn=append_value, default=[],
    8.14            use="""Add a network interface with the given MAC address and bridge.
    8.15            The vif is configured by calling the given configuration script.
    8.16            If type is not specified, default is netfront not ioemu device.
    8.17            If mac is not specified a random MAC address is used.
    8.18 -          The MAC address of the backend interface can be selected with be_mac.
    8.19            If not specified then the network backend chooses it's own MAC address.
    8.20            If bridge is not specified the first bridge found is used.
    8.21            If script is not specified the default script is used.
    8.22 @@ -284,8 +279,10 @@ gopts.var('vtpm', val="instance=INSTANCE
    8.23            given domain.""")
    8.24  
    8.25  gopts.var('nics', val="NUM",
    8.26 -          fn=set_int, default=1,
    8.27 -          use="""Set the number of network interfaces.
    8.28 +          fn=set_int, default=-1,
    8.29 +          use="""DEPRECATED.  Use empty vif entries instead.
    8.30 +
    8.31 +          Set the number of network interfaces.
    8.32            Use the vif option to define interface parameters, otherwise
    8.33            defaults are used. Specifying vifs will increase the
    8.34            number of interfaces as needed.""")
    8.35 @@ -487,58 +484,38 @@ def configure_vtpm(config_devs, vals):
    8.36                  config_vtpm.append(['backend', backend])
    8.37              config_devs.append(['device', config_vtpm])
    8.38  
    8.39 +
    8.40  def configure_vifs(config_devs, vals):
    8.41      """Create the config for virtual network interfaces.
    8.42      """
    8.43 -    vifs = vals.vif
    8.44 -    vifs_n = max(vals.nics, len(vifs))
    8.45  
    8.46 -    for idx in range(0, vifs_n):
    8.47 -        if idx < len(vifs):
    8.48 -            d = vifs[idx]
    8.49 -            mac = d.get('mac')
    8.50 -            be_mac = d.get('be_mac')
    8.51 -            bridge = d.get('bridge')
    8.52 -            script = d.get('script')
    8.53 -            backend = d.get('backend')
    8.54 -            ip = d.get('ip')
    8.55 -            vifname = d.get('vifname')
    8.56 -            type = d.get('type')
    8.57 -        else:
    8.58 -            mac = None
    8.59 -            be_mac = None
    8.60 -            bridge = None
    8.61 -            script = None
    8.62 -            backend = None
    8.63 -            ip = None
    8.64 -            vifname = None
    8.65 -            type = None
    8.66 +    vifs = vals.vif
    8.67 +    vifs_n = len(vifs)
    8.68 +
    8.69 +    if hasattr(vals, 'nics'):
    8.70 +        if vals.nics > 0:
    8.71 +            warn("The nics option is deprecated.  Please use an empty vif "
    8.72 +                 "entry instead:\n\n  vif = [ '' ]\n")
    8.73 +            for _ in range(vifs_n, vals.nics):
    8.74 +                vifs.append('')
    8.75 +            vifs_n = len(vifs)
    8.76 +        elif vals.nics == 0:
    8.77 +            warn("The nics option is deprecated.  Please remove it.")
    8.78 +
    8.79 +    for c in vifs:
    8.80 +        d = comma_sep_kv_to_dict(c)
    8.81          config_vif = ['vif']
    8.82 -        if mac:
    8.83 -            config_vif.append(['mac', mac])
    8.84 -        if vifname:
    8.85 -            config_vif.append(['vifname', vifname])
    8.86 -        if be_mac:
    8.87 -            config_vif.append(['be_mac', be_mac])
    8.88 -        if bridge:
    8.89 -            config_vif.append(['bridge', bridge])
    8.90 -        if script:
    8.91 -            config_vif.append(['script', script])
    8.92 -        if backend:
    8.93 -            config_vif.append(['backend', backend])
    8.94 -        if ip:
    8.95 -            config_vif.append(['ip', ip])
    8.96 -        if type:
    8.97 -            config_vif.append(['type', type])
    8.98 +
    8.99 +        def f(k):
   8.100 +            if k not in ['backend', 'bridge', 'ip', 'mac', 'script', 'type',
   8.101 +                         'vifname']:
   8.102 +                err('Invalid vif option: ' + k)
   8.103 +
   8.104 +            config_vif.append([k, d[k]])
   8.105 +
   8.106 +        map(f, d.keys())
   8.107          config_devs.append(['device', config_vif])
   8.108  
   8.109 -def configure_vfr(config, vals):
   8.110 -     if not vals.ipaddr: return
   8.111 -     config_vfr = ['vfr']
   8.112 -     idx = 0 # No way of saying which IP is for which vif?
   8.113 -     for ip in vals.ipaddr:
   8.114 -         config_vfr.append(['vif', ['id', idx], ['ip', ip]])
   8.115 -     config.append(config_vfr)
   8.116  
   8.117  def configure_vmx(config_image, vals):
   8.118      """Create the config for VMX devices.
   8.119 @@ -649,22 +626,6 @@ def preprocess_ioports(vals):
   8.120          ioports.append(hexd)
   8.121      vals.ioports = ioports
   8.122          
   8.123 -def preprocess_vifs(vals):
   8.124 -    if not vals.vif: return
   8.125 -    vifs = []
   8.126 -    for vif in vals.vif:
   8.127 -        d = {}
   8.128 -        a = vif.split(',')
   8.129 -        for b in a:
   8.130 -            (k, v) = b.strip().split('=', 1)
   8.131 -            k = k.strip()
   8.132 -            v = v.strip()
   8.133 -            if k not in ['type', 'mac', 'be_mac', 'bridge', 'script', 'backend', 'ip', 'vifname']:
   8.134 -                err('Invalid vif specifier: ' + vif)
   8.135 -            d[k] = v
   8.136 -        vifs.append(d)
   8.137 -    vals.vif = vifs
   8.138 -
   8.139  def preprocess_vtpm(vals):
   8.140      if not vals.vtpm: return
   8.141      vtpms = []
   8.142 @@ -766,12 +727,30 @@ def preprocess(vals):
   8.143      preprocess_disk(vals)
   8.144      preprocess_pci(vals)
   8.145      preprocess_ioports(vals)
   8.146 -    preprocess_vifs(vals)
   8.147      preprocess_ip(vals)
   8.148      preprocess_nfs(vals)
   8.149      preprocess_vnc(vals)
   8.150      preprocess_vtpm(vals)
   8.151 -         
   8.152 +
   8.153 +
   8.154 +def comma_sep_kv_to_dict(c):
   8.155 +    """Convert comma-separated, equals-separated key-value pairs into a
   8.156 +    dictionary.
   8.157 +    """
   8.158 +    d = {}
   8.159 +    c = c.strip()
   8.160 +    if len(c) > 0:
   8.161 +        a = c.split(',')
   8.162 +        for b in a:
   8.163 +            if b.find('=') == -1:
   8.164 +                err("%s should be a pair, separated by an equals sign." % b)
   8.165 +            (k, v) = b.split('=', 1)
   8.166 +            k = k.strip()
   8.167 +            v = v.strip()
   8.168 +            d[k] = v
   8.169 +    return d
   8.170 +
   8.171 +
   8.172  def make_domain(opts, config):
   8.173      """Create, build and start a domain.
   8.174  
     9.1 --- a/tools/xm-test/lib/XmTestLib/XenDomain.py	Tue Dec 13 00:10:19 2005 +0000
     9.2 +++ b/tools/xm-test/lib/XmTestLib/XenDomain.py	Tue Dec 13 00:15:53 2005 +0000
     9.3 @@ -203,7 +203,6 @@ class XmTestVmxDomain(XenDomain):
     9.4          # Defaults
     9.5          self.defaults = {"memory"    : 64,
     9.6                           "vcpus"     : 1,
     9.7 -                         "nics"      : 0,
     9.8                           "kernel"    : "/usr/lib/xen/boot/vmxloader",
     9.9                           "builder"   : "\'vmx\'",
    9.10                           "name"      : name or self.getUniqueName()
    9.11 @@ -264,7 +263,6 @@ class XmTestPvDomain(XenDomain):
    9.12          # Defaults
    9.13          self.defaults = {"memory"  : 64,
    9.14                           "vcpus"   : 1,
    9.15 -                         "nics"    : 0,
    9.16                           "kernel"  : getDefaultKernel(),
    9.17                           "root"    : "/dev/ram0",
    9.18                           "name"    : name or self.getUniqueName(),
    10.1 --- a/tools/xm-test/tests/create/13_create_multinic_pos.py	Tue Dec 13 00:10:19 2005 +0000
    10.2 +++ b/tools/xm-test/tests/create/13_create_multinic_pos.py	Tue Dec 13 00:15:53 2005 +0000
    10.3 @@ -6,7 +6,8 @@
    10.4  from XmTestLib import *
    10.5  
    10.6  for i in range(0,10):
    10.7 -    domain = XmTestDomain(extraOpts={"nics":"%i" % i})
    10.8 +    domain = XmTestDomain()
    10.9 +    domain.configSetVar('vif', str(['' for _ in range(0, i)]))
   10.10  
   10.11      try:
   10.12          domain.start()
    11.1 --- a/tools/xm-test/tests/network/02_network_local_ping_pos.py	Tue Dec 13 00:10:19 2005 +0000
    11.2 +++ b/tools/xm-test/tests/network/02_network_local_ping_pos.py	Tue Dec 13 00:15:53 2005 +0000
    11.3 @@ -28,7 +28,7 @@ ip   = Net.ip("dom1", "eth0")
    11.4  mask = Net.mask("dom1", "eth0")
    11.5  
    11.6  # Fire up a guest domain w/1 nic
    11.7 -domain = XmTestDomain(extraOpts={ 'nics' : 1 })
    11.8 +domain = XmTestDomain()
    11.9  try:
   11.10      domain.configSetVar('vif', " [ 'ip=" + ip + "' ]")
   11.11      domain.start()
    12.1 --- a/tools/xm-test/tests/network/05_network_dom0_ping_pos.py	Tue Dec 13 00:10:19 2005 +0000
    12.2 +++ b/tools/xm-test/tests/network/05_network_dom0_ping_pos.py	Tue Dec 13 00:15:53 2005 +0000
    12.3 @@ -31,7 +31,7 @@ except NetworkError, e:
    12.4          FAIL(str(e))
    12.5  
    12.6  # Fire up a guest domain w/1 nic
    12.7 -domain = XmTestDomain(extraOpts={ 'nics' : 1 })
    12.8 +domain = XmTestDomain()
    12.9  try:
   12.10      domain.configSetVar('vif', " [ 'ip=" + ip + "' ]")
   12.11      domain.start()
    13.1 --- a/tools/xm-test/tests/network/11_network_domU_ping_pos.py	Tue Dec 13 00:10:19 2005 +0000
    13.2 +++ b/tools/xm-test/tests/network/11_network_domU_ping_pos.py	Tue Dec 13 00:15:53 2005 +0000
    13.3 @@ -21,7 +21,7 @@ from XmTestLib import *
    13.4  
    13.5  
    13.6  def netDomain(ip):
    13.7 -    dom = XmTestDomain(extraOpts={ 'nics' : 1 })
    13.8 +    dom = XmTestDomain()
    13.9      try:
   13.10          dom.configSetVar('vif', " [ 'ip=" + ip + "' ]")
   13.11          dom.start()
    14.1 --- a/tools/xm-test/tests/restore/04_restore_withdevices_pos.py	Tue Dec 13 00:10:19 2005 +0000
    14.2 +++ b/tools/xm-test/tests/restore/04_restore_withdevices_pos.py	Tue Dec 13 00:15:53 2005 +0000
    14.3 @@ -7,7 +7,9 @@ from XmTestLib import *
    14.4  
    14.5  import re
    14.6  
    14.7 -domain = XmTestDomain(extraOpts={"nics":2})
    14.8 +domain = XmTestDomain()
    14.9 +
   14.10 +domain.configSetVar('vif', "[ '', '' ]")
   14.11  
   14.12  domain.configAddDisk("phy:/dev/ram0", "hda1", "w")
   14.13  domain.configAddDisk("phy:/dev/ram1", "hdb2", "w")