[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Add a 1-PIF-per-network limit.



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1167321255 0
# Node ID 615109616bb60c34a60d03d7921212ca6185fe10
# Parent  b175c2f19e0a6017330b0562c80b04a1611e1016
Add a 1-PIF-per-network limit.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py          |   38 ++++++++++++++++++------------
 tools/python/xen/xend/XendDomainInfo.py   |   13 +++++++---
 tools/python/xen/xend/XendError.py        |    7 +++--
 tools/python/xen/xend/XendNode.py         |   24 ++++++++++++++++--
 tools/python/xen/xm/messages/en/xen-xm.po |    5 +++
 5 files changed, 62 insertions(+), 25 deletions(-)

diff -r b175c2f19e0a -r 615109616bb6 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Thu Dec 28 15:52:31 2006 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Thu Dec 28 15:54:15 2006 +0000
@@ -540,16 +540,20 @@ class XendAPI:
         return XendNode.instance().pifs[ref]
 
     def PIF_create(self, _, name, network_uuid, host_uuid, mac, mtu, vlan):
-        node = XendNode.instance()
-        if host_uuid != node.uuid:
-            return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
-
-        elif _is_valid_ref(network_uuid, node.is_valid_network):
-            network = node.get_network(network_uuid)
-            return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
-                                                   network))
-        else:
-            return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
+        try:
+            node = XendNode.instance()
+            if host_uuid != node.uuid:
+                return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
+
+            elif _is_valid_ref(network_uuid, node.is_valid_network):
+                network = node.get_network(network_uuid)
+                return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
+                                                       network))
+            else:
+                return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
+        except NetworkAlreadyConnected, exn:
+            return xen_api_error(['NETWORK_ALREADY_CONNECTED',
+                                  network_uuid, exn.pif_uuid])
 
     def PIF_destroy(self, _, ref):
         return xen_api_success(XendNode.instance().PIF_destroy(ref))
@@ -595,11 +599,15 @@ class XendAPI:
         return xen_api_success(self._get_PIF(ref).set_mtu(name))
 
     def PIF_create_VLAN(self, _, ref, network, vlan):
-        if _is_valid_ref(network, XendNode.instance().is_valid_network):
-            return xen_api_success(XendNode.instance().PIF_create_VLAN(
-                ref, network, vlan))
-        else:
-            return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
+        try:
+            if _is_valid_ref(network, XendNode.instance().is_valid_network):
+                return xen_api_success(XendNode.instance().PIF_create_VLAN(
+                    ref, network, vlan))
+            else:
+                return xen_api_error([NETWORK_HANDLE_INVALID, network])
+        except NetworkAlreadyConnected, exn:
+            return xen_api_error(['NETWORK_ALREADY_CONNECTED',
+                                  network, exn.pif_uuid])
 
 
     # Xen API: Class VM
diff -r b175c2f19e0a -r 615109616bb6 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Thu Dec 28 15:52:31 2006 +0000
+++ b/tools/python/xen/xend/XendDomainInfo.py   Thu Dec 28 15:54:15 2006 +0000
@@ -1969,9 +1969,16 @@ class XendDomainInfo:
                     config['device'] = ''
 
             if not config.has_key('network'):
-                config['network'] = \
-                    XendNode.instance().bridge_to_network(
-                    config.get('bridge')).uuid
+                try:
+                    config['network'] = \
+                        XendNode.instance().bridge_to_network(
+                        config.get('bridge')).uuid
+                except Exception:
+                    log.exception('bridge_to_network')
+                    # Ignore this for now -- it may happen if the device
+                    # has been specified using the legacy methods, but at
+                    # some point we're going to have to figure out how to
+                    # handle that properly.
 
             config['MTU'] = 1500 # TODO
             config['io_read_kbs'] = 0.0
diff -r b175c2f19e0a -r 615109616bb6 tools/python/xen/xend/XendError.py
--- a/tools/python/xen/xend/XendError.py        Thu Dec 28 15:52:31 2006 +0000
+++ b/tools/python/xen/xend/XendError.py        Thu Dec 28 15:54:15 2006 +0000
@@ -33,14 +33,15 @@ class XendError(Fault):
         return self.value
 
 class VMBadState(XendError):
-    
     def __init__(self, value, expected, actual):
         XendError.__init__(self, value)
         self.expected = expected
         self.actual = actual
 
-    def __str__(self):
-        return self.value
+class NetworkAlreadyConnected(XendError):
+    def __init__(self, pif_uuid):
+        XendError.__init__(self, 'Network already connected')
+        self.pif_uuid = pif_uuid
 
 class VmError(XendError):
     """Vm construction error."""
diff -r b175c2f19e0a -r 615109616bb6 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Thu Dec 28 15:52:31 2006 +0000
+++ b/tools/python/xen/xend/XendNode.py Thu Dec 28 15:54:15 2006 +0000
@@ -23,7 +23,7 @@ from xen.util import Brctl
 from xen.util import Brctl
 
 from xen.xend import uuid
-from xen.xend.XendError import XendError
+from xen.xend.XendError import XendError, NetworkAlreadyConnected
 from xen.xend.XendRoot import instance as xendroot
 from xen.xend.XendStorageRepository import XendStorageRepository
 from xen.xend.XendLogging import log
@@ -105,8 +105,13 @@ class XendNode:
             for pif_uuid, pif in saved_pifs.items():
                 if pif['network'] in self.networks:
                     network = self.networks[pif['network']]
-                    self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
-                                    pif['MAC'], network, False, pif_uuid)
+                    try:
+                        self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
+                                        pif['MAC'], network, False, pif_uuid)
+                    except NetworkAlreadyConnected, exn:
+                        log.error('Cannot load saved PIF %s, as network %s ' +
+                                  'is already connected to PIF %s',
+                                  pif_uuid, pif['network'], exn.pif_uuid)
         else:
             for name, mtu, mac in linux_get_phy_ifaces():
                 network = self.networks.values()[0]
@@ -143,6 +148,10 @@ class XendNode:
 
     def PIF_create(self, name, mtu, vlan, mac, network, persist = True,
                    pif_uuid = None):
+        for pif in self.pifs.values():
+            if pif.network == network:
+                raise NetworkAlreadyConnected(pif.uuid)
+
         if pif_uuid is None:
             pif_uuid = uuid.createString()
         self.pifs[pif_uuid] = XendPIF(pif_uuid, name, mtu, vlan, mac, network,
@@ -290,6 +299,15 @@ class XendNode:
         return self.networks[network_ref]
 
     def bridge_to_network(self, bridge):
+        """
+        Determine which network a particular bridge is attached to.
+
+        @param bridge The name of the bridge.  If empty, the default bridge
+        will be used instead (the first one in the list returned by brctl
+        show); this is the behaviour of the vif-bridge script.
+        @return The XendNetwork instance to which this bridge is attached.
+        @raise Exception if the interface is not connected to a network.
+        """
         if not bridge:
             rc, bridge = commands.getstatusoutput(
                 'brctl show | cut -d "\n" -f 2 | cut -f 1')
diff -r b175c2f19e0a -r 615109616bb6 tools/python/xen/xm/messages/en/xen-xm.po
--- a/tools/python/xen/xm/messages/en/xen-xm.po Thu Dec 28 15:52:31 2006 +0000
+++ b/tools/python/xen/xm/messages/en/xen-xm.po Thu Dec 28 15:54:15 2006 +0000
@@ -19,7 +19,7 @@ msgid ""
 msgid ""
 msgstr ""
 "Project-Id-Version: Xen-xm 3.0\n"
-"PO-Revision-Date: 2006-12-25 19:24+0000\n"
+"PO-Revision-Date: 2006-12-28 15:43+0000\n"
 "Last-Translator: Ewan Mellor <ewan@xxxxxxxxxxxxx>\n"
 "Language-Team: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>\n"
 "MIME-Version: 1.0\n"
@@ -65,5 +65,8 @@ msgid "VTPM_HANDLE_INVALID"
 msgid "VTPM_HANDLE_INVALID"
 msgstr "The VTPM handle %(1)s is invalid."
 
+msgid "NETWORK_ALREADY_CONNECTED"
+msgstr "The network you specified already has a PIF attached to it, and so 
another one may not be attached."
+
 msgid "VM_BAD_POWER_STATE"
 msgstr "The VM must be %(2)s to perform the requested operation (it is 
currently %(3)s)."

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.