WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Change the way that networks and PIFs rel

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Change the way that networks and PIFs relate to each other -- the PIF holds a
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 25 Dec 2006 10:55:12 -0800
Delivery-date: Mon, 25 Dec 2006 10:56:02 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1167064011 0
# Node ID 8036efeefbd1cbd7da1c30abec74b34b48c5d208
# Parent  eec06ba7afaa37208d79ef5763e0dd4a114518ec
Change the way that networks and PIFs relate to each other -- the PIF holds a
reference to the network (and the host) not the other way around.  Persist only
the necessary details for the network (not the set of PIFs and VIFs).

Fix the plumbing of the network class inside XendAPI, and implement a few more
functions.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py     |   22 +++++++++++-
 tools/python/xen/xend/XendNetwork.py |   46 +++++++-------------------
 tools/python/xen/xend/XendNode.py    |   60 +++++++++++++++++++++--------------
 tools/python/xen/xend/XendPIF.py     |   43 ++++++++-----------------
 4 files changed, 82 insertions(+), 89 deletions(-)

diff -r eec06ba7afaa -r 8036efeefbd1 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Mon Dec 25 16:24:15 2006 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Mon Dec 25 16:26:51 2006 +0000
@@ -451,14 +451,30 @@ class XendAPI:
         return xen_api_error(XEND_ERROR_UNSUPPORTED)
 
 
-    # Xen API: Class Network
+    # Xen API: Class network
     # ----------------------------------------------------------------
 
-    Network_attr_ro = ['VIFs', 'PIFs']
-    Network_attr_rw = ['name_label',
+    network_attr_ro = ['VIFs', 'PIFs']
+    network_attr_rw = ['name_label',
                        'name_description',
                        'default_gateway',
                        'default_netmask']
+
+    def _get_network(self, ref):
+        return XendNode.instance().get_network(ref)
+
+    def network_get_all(self, session):
+        return xen_api_success(XendNode.instance().get_network_refs())
+
+    def network_get_record(self, session, ref):
+        return xen_api_success(
+            XendNode.instance().get_network(ref).get_record())
+
+    def network_get_VIFs(self, _, ref):
+        return xen_api_success(self._get_network(ref).get_VIF_UUIDs())
+
+    def network_get_PIFs(self, session, ref):
+        return xen_api_success(self._get_network(ref).get_PIF_UUIDs())
 
     # Xen API: Class PIF
     # ----------------------------------------------------------------
diff -r eec06ba7afaa -r 8036efeefbd1 tools/python/xen/xend/XendNetwork.py
--- a/tools/python/xen/xend/XendNetwork.py      Mon Dec 25 16:24:15 2006 +0000
+++ b/tools/python/xen/xend/XendNetwork.py      Mon Dec 25 16:26:51 2006 +0000
@@ -12,7 +12,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
-# Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
 # Copyright (c) 2006 Xensource Inc.
 #============================================================================
 
@@ -22,7 +21,8 @@ import struct
 import struct
 import socket
 
-from xen.xend.XendRoot import instance as xendroot
+import XendNode
+from XendLogging import log
 
 IP_ROUTE_RE = r'^default via ([\d\.]+) dev (\w+)'
 
@@ -63,57 +63,37 @@ class XendNetwork:
         self.name_description = description
         self.default_gateway = gateway
         self.default_netmask = netmask
-        self.vifs = {}
-        self.pifs = {}
-
-    def get_name_label(self):
-        return self.name_label
 
     def set_name_label(self, new_name):
         self.name_label = new_name
 
-    def get_name_description(self):
-        return self.name_description
-
     def set_name_description(self, new_desc):
         self.name_description = new_desc
-
-    def get_default_gateway(self):
-        return self.default_gateway
 
     def set_default_gateway(self, new_gateway):
         if re.search('^\d+\.\d+\.\d+\.\d+$', new_gateway):
             self.default_gateway = new_gateway
 
-    def get_default_netmask(self):
-        return self.default_netmask
-
     def set_default_netmask(self, new_netmask):
         if re.search('^\d+\.\d+\.\d+\.\d+$', new_netmask):
             self.default_netmask = new_netmask
 
-    def add_pif(self, pif):
-        self.pifs[pif.get_uuid()] = pif
+    def get_VIF_UUIDs(self):
+        return []
 
-    def remove_pif(self, pif_uuid):
-        if pif_uuid in self.pifs:
-            del self.pifs[pif_uuid]
+    def get_PIF_UUIDs(self):
+        return [x.uuid for x in XendNode.instance().pifs.values()
+                if x.network == self]
 
-    def add_vif(self, vif):
-        self.vifs[vif.get_uuid()] = vif
-
-    def remove_vif(self, vif_uuid):
-        if vif_uuid in self.vifs:
-            del self.vifs[vif_uuid]
-        
-    def get_record(self):
-        return {
+    def get_record(self, transient = True):
+        result = {
             'uuid': self.uuid,
             'name_label': self.name_label,
             'name_description': self.name_description,
             'default_gateway': self.default_gateway,
             'default_netmask': self.default_netmask,
-            'VIFs': self.vifs.keys(),
-            'PIFs': self.pifs.keys()
         }
-           
+        if transient:
+            result['VIFs'] = self.get_VIF_UUIDs()
+            result['PIFs'] = self.get_PIF_UUIDs()
+        return result
diff -r eec06ba7afaa -r 8036efeefbd1 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Mon Dec 25 16:24:15 2006 +0000
+++ b/tools/python/xen/xend/XendNode.py Mon Dec 25 16:26:51 2006 +0000
@@ -83,20 +83,6 @@ class XendNode:
         self.pifs = {}
         self.networks = {}
 
-        # initialise PIFs
-        saved_pifs = self.state_store.load_state('pif')
-        if saved_pifs:
-            for pif_uuid, pif in saved_pifs.items():
-                self.pifs[pif_uuid] = XendPIF(pif_uuid,
-                                              pif['name'],
-                                              pif['MTU'],
-                                              pif['MAC'])
-        else:
-            for name, mtu, mac in linux_get_phy_ifaces():
-                pif_uuid = uuid.createString()
-                pif = XendPIF(pif_uuid, name, mtu, mac)
-                self.pifs[pif_uuid] = pif
-
         # initialise networks
         saved_networks = self.state_store.load_state('network')
         if saved_networks:
@@ -106,16 +92,30 @@ class XendNode:
                                 network.get('name_description', ''),
                                 network.get('default_gateway', ''),
                                 network.get('default_netmask', ''))
-                
-                for pif_uuid in network.get('PIFs', {}).keys():
-                    pif = self.pifs.get(pif_uuid)
-                    if pif:
-                        self.networks.pifs[pif_uuid] = pif
         else:
             gateway, netmask = linux_get_default_network()
             net_uuid = uuid.createString()
             net = XendNetwork(net_uuid, 'net0', '', gateway, netmask)
             self.networks[net_uuid] = net
+
+        # initialise PIFs
+        saved_pifs = self.state_store.load_state('pif')
+        if saved_pifs:
+            for pif_uuid, pif in saved_pifs.items():
+                if pif['network'] in self.networks:
+                    network = self.networks[pif['network']]
+                    self.pifs[pif_uuid] = XendPIF(pif_uuid,
+                                                  pif['name'],
+                                                  pif['MTU'],
+                                                  pif['MAC'],
+                                                  network,
+                                                  self)
+        else:
+            for name, mtu, mac in linux_get_phy_ifaces():
+                network = self.networks.values()[0]
+                pif_uuid = uuid.createString()
+                pif = XendPIF(pif_uuid, name, mtu, mac, network, self)
+                self.pifs[pif_uuid] = pif
 
         # initialise storage
         saved_sr = self.state_store.load_state('sr')
@@ -125,7 +125,6 @@ class XendNode:
         else:
             sr_uuid = uuid.createString()
             self.sr = XendStorageRepository(sr_uuid)
-        self.save()
 
     def save(self):
         # save state
@@ -133,10 +132,10 @@ class XendNode:
                                    'name_description':self.desc}}
         self.state_store.save_state('host',host_record)
         self.state_store.save_state('cpu', self.cpus)
-        pif_records = dict([(k, v.get_record())
+        pif_records = dict([(k, v.get_record(transient = False))
                             for k, v in self.pifs.items()])
         self.state_store.save_state('pif', pif_records)
-        net_records = dict([(k, v.get_record())
+        net_records = dict([(k, v.get_record(transient = False))
                             for k, v in self.networks.items()])
         self.state_store.save_state('network', net_records)
 
@@ -163,6 +162,9 @@ class XendNode:
 
     def is_valid_cpu(self, cpu_ref):
         return (cpu_ref in self.cpus)
+
+    def is_valid_network(self, network_ref):
+        return (network_ref in self.networks)
 
     #
     # Storage Repo
@@ -233,7 +235,17 @@ class XendNode:
     def get_host_cpu_load(self, host_cpu_ref):
         return 0.0
 
-    
+
+    #
+    # Network Functions
+    #
+    
+    def get_network_refs(self):
+        return self.networks.keys()
+
+    def get_network(self, network_ref):
+        return self.networks[network_ref]
+
 
     #
     # Getting host information.
@@ -318,5 +330,5 @@ def instance():
         inst
     except:
         inst = XendNode()
+        inst.save()
     return inst
-
diff -r eec06ba7afaa -r 8036efeefbd1 tools/python/xen/xend/XendPIF.py
--- a/tools/python/xen/xend/XendPIF.py  Mon Dec 25 16:24:15 2006 +0000
+++ b/tools/python/xen/xend/XendPIF.py  Mon Dec 25 16:26:51 2006 +0000
@@ -12,7 +12,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
-# Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
 # Copyright (c) 2006 Xensource Inc.
 #============================================================================
 
@@ -100,29 +99,18 @@ class XendPIF:
 class XendPIF:
     """Representation of a Physical Network Interface."""
     
-    def __init__(self, uuid, name, mtu, mac):
+    def __init__(self, uuid, name, mtu, mac, network, host):
         self.uuid = uuid
         self.name = name
         self.mac = mac
         self.mtu = mtu
         self.vlan = ''
-        self.network = None
+        self.network = network
+        self.host = host
 
     def set_name(self, new_name):
         self.name = new_name
             
-    def get_name(self):
-        return self.name
-
-    def get_uuid(self):
-        return self.uuid
-
-    def get_mac(self):
-        return self.mac
-
-    def get_vlan(self):
-        return self.vlan
-
     def set_mac(self, new_mac):
         success = linux_set_mac(new_mac)
         if success:
@@ -141,17 +129,14 @@ class XendPIF:
     def get_io_write_kbs(self):
         return 0.0
 
-    def get_record(self):
-        if self.network:
-            network_uuid = self.network.get_uuid()
-        else:
-            network_uuid = None
-
-        return {'name': self.name,
-                'MAC': self.mac,
-                'MTU': self.mtu,
-                'VLAN': self.vlan,
-                'network': network_uuid,
-                'io_read_kbs': self.get_io_read_kbs(),
-                'io_write_kbs': self.get_io_write_kbs()}
-                
+    def get_record(self, transient = True):
+        result = {'name': self.name,
+                  'MAC': self.mac,
+                  'MTU': self.mtu,
+                  'VLAN': self.vlan,
+                  'host': self.host.uuid,
+                  'network': self.network.uuid}
+        if transient:
+            result['io_read_kbs'] = self.get_io_read_kbs()
+            result['io_write_kbs'] = self.get_io_write_kbs()
+        return result

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Change the way that networks and PIFs relate to each other -- the PIF holds a, Xen patchbot-unstable <=