xenserver: Factor out XAPI interactions in interface-reconfigure.
authorIan Campbell <Ian.Campbell@citrix.com>
Thu, 6 Aug 2009 20:43:21 +0000 (13:43 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 18 Aug 2009 23:09:32 +0000 (16:09 -0700)
Currently interface-reconfigure stores a copy of the XAPI database using
python's pickling functionality. Since the XenServer host installer also needs
to write this file (so it is present after slave upgrade) we would like to
switch to something more explicitly under our control.

Begin by factoring out XAPI interactions.

xenserver/opt_xensource_libexec_interface-reconfigure

index 2a32fad275b3fe0ff700ab79e7facd3f44a97382..6f2b5bcc4a0545b575d0a8a127826b81a4c11615 100755 (executable)
@@ -249,6 +249,18 @@ def interface_exists(i):
     return os.path.exists("/sys/class/net/" + i)
 
 class DatabaseCache(object):
+    def __get_pif_records_from_xapi(self, session):
+        self.__pifs = session.xenapi.PIF.get_all_records()
+    
+    def __get_vlan_records_from_xapi(self, session):
+        self.__vlans = session.xenapi.VLAN.get_all_records()
+    
+    def __get_bond_records_from_xapi(self, session):
+        self.__bonds = session.xenapi.Bond.get_all_records()
+    
+    def __get_network_records_from_xapi(self, session):
+        self.__networks = session.xenapi.network.get_all_records()
+    
     def __init__(self, session_ref=None, cache_file=None):
         if session_ref and cache_file:
             raise Error("can't specify session reference and cache file")
@@ -263,10 +275,10 @@ class DatabaseCache(object):
                 session._session = session_ref
 
             try:
-                self.__vlans = session.xenapi.VLAN.get_all_records()
-                self.__bonds = session.xenapi.Bond.get_all_records()
-                self.__pifs = session.xenapi.PIF.get_all_records()
-                self.__networks = session.xenapi.network.get_all_records()
+                self.__get_pif_records_from_xapi(session)
+                self.__get_vlan_records_from_xapi(session)
+                self.__get_bond_records_from_xapi(session)
+                self.__get_network_records_from_xapi(session)
             finally:
                 if not session_ref:
                     session.xenapi.session.logout()