ia64/xen-unstable

changeset 13214:615109616bb6

Add a 1-PIF-per-network limit.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 28 15:54:15 2006 +0000 (2006-12-28)
parents b175c2f19e0a
children a138fabc2120
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendError.py tools/python/xen/xend/XendNode.py tools/python/xen/xm/messages/en/xen-xm.po
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Dec 28 15:52:31 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Dec 28 15:54:15 2006 +0000
     1.3 @@ -540,16 +540,20 @@ class XendAPI:
     1.4          return XendNode.instance().pifs[ref]
     1.5  
     1.6      def PIF_create(self, _, name, network_uuid, host_uuid, mac, mtu, vlan):
     1.7 -        node = XendNode.instance()
     1.8 -        if host_uuid != node.uuid:
     1.9 -            return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
    1.10 +        try:
    1.11 +            node = XendNode.instance()
    1.12 +            if host_uuid != node.uuid:
    1.13 +                return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
    1.14  
    1.15 -        elif _is_valid_ref(network_uuid, node.is_valid_network):
    1.16 -            network = node.get_network(network_uuid)
    1.17 -            return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
    1.18 -                                                   network))
    1.19 -        else:
    1.20 -            return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
    1.21 +            elif _is_valid_ref(network_uuid, node.is_valid_network):
    1.22 +                network = node.get_network(network_uuid)
    1.23 +                return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
    1.24 +                                                       network))
    1.25 +            else:
    1.26 +                return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
    1.27 +        except NetworkAlreadyConnected, exn:
    1.28 +            return xen_api_error(['NETWORK_ALREADY_CONNECTED',
    1.29 +                                  network_uuid, exn.pif_uuid])
    1.30  
    1.31      def PIF_destroy(self, _, ref):
    1.32          return xen_api_success(XendNode.instance().PIF_destroy(ref))
    1.33 @@ -595,11 +599,15 @@ class XendAPI:
    1.34          return xen_api_success(self._get_PIF(ref).set_mtu(name))
    1.35  
    1.36      def PIF_create_VLAN(self, _, ref, network, vlan):
    1.37 -        if _is_valid_ref(network, XendNode.instance().is_valid_network):
    1.38 -            return xen_api_success(XendNode.instance().PIF_create_VLAN(
    1.39 -                ref, network, vlan))
    1.40 -        else:
    1.41 -            return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
    1.42 +        try:
    1.43 +            if _is_valid_ref(network, XendNode.instance().is_valid_network):
    1.44 +                return xen_api_success(XendNode.instance().PIF_create_VLAN(
    1.45 +                    ref, network, vlan))
    1.46 +            else:
    1.47 +                return xen_api_error([NETWORK_HANDLE_INVALID, network])
    1.48 +        except NetworkAlreadyConnected, exn:
    1.49 +            return xen_api_error(['NETWORK_ALREADY_CONNECTED',
    1.50 +                                  network, exn.pif_uuid])
    1.51  
    1.52  
    1.53      # Xen API: Class VM
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 28 15:52:31 2006 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 28 15:54:15 2006 +0000
     2.3 @@ -1969,9 +1969,16 @@ class XendDomainInfo:
     2.4                      config['device'] = ''
     2.5  
     2.6              if not config.has_key('network'):
     2.7 -                config['network'] = \
     2.8 -                    XendNode.instance().bridge_to_network(
     2.9 -                    config.get('bridge')).uuid
    2.10 +                try:
    2.11 +                    config['network'] = \
    2.12 +                        XendNode.instance().bridge_to_network(
    2.13 +                        config.get('bridge')).uuid
    2.14 +                except Exception:
    2.15 +                    log.exception('bridge_to_network')
    2.16 +                    # Ignore this for now -- it may happen if the device
    2.17 +                    # has been specified using the legacy methods, but at
    2.18 +                    # some point we're going to have to figure out how to
    2.19 +                    # handle that properly.
    2.20  
    2.21              config['MTU'] = 1500 # TODO
    2.22              config['io_read_kbs'] = 0.0
     3.1 --- a/tools/python/xen/xend/XendError.py	Thu Dec 28 15:52:31 2006 +0000
     3.2 +++ b/tools/python/xen/xend/XendError.py	Thu Dec 28 15:54:15 2006 +0000
     3.3 @@ -33,14 +33,15 @@ class XendError(Fault):
     3.4          return self.value
     3.5  
     3.6  class VMBadState(XendError):
     3.7 -    
     3.8      def __init__(self, value, expected, actual):
     3.9          XendError.__init__(self, value)
    3.10          self.expected = expected
    3.11          self.actual = actual
    3.12  
    3.13 -    def __str__(self):
    3.14 -        return self.value
    3.15 +class NetworkAlreadyConnected(XendError):
    3.16 +    def __init__(self, pif_uuid):
    3.17 +        XendError.__init__(self, 'Network already connected')
    3.18 +        self.pif_uuid = pif_uuid
    3.19  
    3.20  class VmError(XendError):
    3.21      """Vm construction error."""
     4.1 --- a/tools/python/xen/xend/XendNode.py	Thu Dec 28 15:52:31 2006 +0000
     4.2 +++ b/tools/python/xen/xend/XendNode.py	Thu Dec 28 15:54:15 2006 +0000
     4.3 @@ -23,7 +23,7 @@ import xen.lowlevel.xc
     4.4  from xen.util import Brctl
     4.5  
     4.6  from xen.xend import uuid
     4.7 -from xen.xend.XendError import XendError
     4.8 +from xen.xend.XendError import XendError, NetworkAlreadyConnected
     4.9  from xen.xend.XendRoot import instance as xendroot
    4.10  from xen.xend.XendStorageRepository import XendStorageRepository
    4.11  from xen.xend.XendLogging import log
    4.12 @@ -105,8 +105,13 @@ class XendNode:
    4.13              for pif_uuid, pif in saved_pifs.items():
    4.14                  if pif['network'] in self.networks:
    4.15                      network = self.networks[pif['network']]
    4.16 -                    self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
    4.17 -                                    pif['MAC'], network, False, pif_uuid)
    4.18 +                    try:
    4.19 +                        self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
    4.20 +                                        pif['MAC'], network, False, pif_uuid)
    4.21 +                    except NetworkAlreadyConnected, exn:
    4.22 +                        log.error('Cannot load saved PIF %s, as network %s ' +
    4.23 +                                  'is already connected to PIF %s',
    4.24 +                                  pif_uuid, pif['network'], exn.pif_uuid)
    4.25          else:
    4.26              for name, mtu, mac in linux_get_phy_ifaces():
    4.27                  network = self.networks.values()[0]
    4.28 @@ -143,6 +148,10 @@ class XendNode:
    4.29  
    4.30      def PIF_create(self, name, mtu, vlan, mac, network, persist = True,
    4.31                     pif_uuid = None):
    4.32 +        for pif in self.pifs.values():
    4.33 +            if pif.network == network:
    4.34 +                raise NetworkAlreadyConnected(pif.uuid)
    4.35 +
    4.36          if pif_uuid is None:
    4.37              pif_uuid = uuid.createString()
    4.38          self.pifs[pif_uuid] = XendPIF(pif_uuid, name, mtu, vlan, mac, network,
    4.39 @@ -290,6 +299,15 @@ class XendNode:
    4.40          return self.networks[network_ref]
    4.41  
    4.42      def bridge_to_network(self, bridge):
    4.43 +        """
    4.44 +        Determine which network a particular bridge is attached to.
    4.45 +
    4.46 +        @param bridge The name of the bridge.  If empty, the default bridge
    4.47 +        will be used instead (the first one in the list returned by brctl
    4.48 +        show); this is the behaviour of the vif-bridge script.
    4.49 +        @return The XendNetwork instance to which this bridge is attached.
    4.50 +        @raise Exception if the interface is not connected to a network.
    4.51 +        """
    4.52          if not bridge:
    4.53              rc, bridge = commands.getstatusoutput(
    4.54                  'brctl show | cut -d "\n" -f 2 | cut -f 1')
     5.1 --- a/tools/python/xen/xm/messages/en/xen-xm.po	Thu Dec 28 15:52:31 2006 +0000
     5.2 +++ b/tools/python/xen/xm/messages/en/xen-xm.po	Thu Dec 28 15:54:15 2006 +0000
     5.3 @@ -19,7 +19,7 @@
     5.4  msgid ""
     5.5  msgstr ""
     5.6  "Project-Id-Version: Xen-xm 3.0\n"
     5.7 -"PO-Revision-Date: 2006-12-25 19:24+0000\n"
     5.8 +"PO-Revision-Date: 2006-12-28 15:43+0000\n"
     5.9  "Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
    5.10  "Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
    5.11  "MIME-Version: 1.0\n"
    5.12 @@ -65,5 +65,8 @@ msgstr "The VM handle %(1)s is invalid."
    5.13  msgid "VTPM_HANDLE_INVALID"
    5.14  msgstr "The VTPM handle %(1)s is invalid."
    5.15  
    5.16 +msgid "NETWORK_ALREADY_CONNECTED"
    5.17 +msgstr "The network you specified already has a PIF attached to it, and so another one may not be attached."
    5.18 +
    5.19  msgid "VM_BAD_POWER_STATE"
    5.20  msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."