skip aggregates with incomplete connection info
[sfa.git] / geni / slicemgr.py
index 9138923..5b8a43a 100644 (file)
@@ -10,10 +10,10 @@ from geni.util.credential import Credential
 from geni.util.trustedroot import *
 from geni.util.excep import *
 from geni.util.misc import *
-from geni.util.config import Config
+from geni.util.config import *
 from geni.util.rspec import Rspec
 from geni.util.specdict import *
-from geni.util.storage import SimpleStorage
+from geni.util.storage import SimpleStorage, XmlStorage
 
 class SliceMgr(GeniServer):
 
@@ -50,18 +50,22 @@ class SliceMgr(GeniServer):
         self.time_format = "%Y-%m-%d %H:%M:%S"
         
         # Get list of aggregates this sm talks to
-        # XX do we use simplestorage to maintain this file manually?
-        aggregates_file = self.server_basedir + os.sep + 'aggregates'
-        self.aggregates = SimpleStorage(aggregates_file)
+        aggregates_file = self.server_basedir + os.sep + 'aggregates.xml'
+        connection_dict = {'hrn': '', 'addr': '', 'port': ''}
+        self.aggregate_info = XmlStorage(aggregates_file, {'aggregates': {'aggregate': [connection_dict]}} )
+        self.aggregate_info.load()
         
+        # Get cached list of nodes (rspec) 
         nodes_file = os.sep.join([self.server_basedir, 'smgr.' + self.hrn + '.components'])
         self.nodes = SimpleStorage(nodes_file)
         self.nodes.load()
         
+        # Get cacheds slice states
         slices_file = os.sep.join([self.server_basedir, 'smgr.' + self.hrn + '.slices'])
         self.slices = SimpleStorage(slices_file)
         self.slices.load()
 
+        # Get the policy
         policy_file = os.sep.join([self.server_basedir, 'smgr.' + self.hrn + '.policy'])
         self.policy = SimpleStorage(policy_file, {'whitelist': [], 'blacklist': []})
         self.policy.load()
@@ -71,7 +75,7 @@ class SliceMgr(GeniServer):
 
         self.connectRegistry()
         self.loadCredential()
-        self.connectAggregates(aggregates_file)
+        self.connectAggregates()
 
 
     def loadCredential(self):
@@ -85,7 +89,7 @@ class SliceMgr(GeniServer):
         try:
             self.credential = Credential(filename = ma_cred_filename)
         except IOError:
-            self.credential = self.getCrednetialFromRegistry()
+            self.credential = self.getCredentialFromRegistry()
             
         
     def getCredentialFromRegistry(self):
@@ -113,33 +117,23 @@ class SliceMgr(GeniServer):
         url = 'http://%(address)s:%(port)s' % locals()
         self.registry = GeniClient(url, self.key_file, self.cert_file)
 
-    def connectAggregates(self, aggregates_file):
-        """
-        Get info about the aggregates available to us from file and create 
-        an xmlrpc connection to each. If any info is invalid, skip it. 
-        """
-        lines = []
-        try:
-            f = open(aggregates_file, 'r')
-            lines = f.readlines()
-            f.close()
-        except: raise 
-        
-        for line in lines:
-            # Skip comments
-            if line.strip().startswith("#"):
-                continue
-            line = line.replace("\t", " ").replace("\n", "").replace("\r", "").strip()
-            agg_info = line.split(" ")
-        
-            # skip invalid info
-            if len(agg_info) != 3:
-                continue
-
-            # create xmlrpc connection using GeniClient
-            hrn, address, port = agg_info[0], agg_info[1], agg_info[2]
-            url = 'http://%(address)s:%(port)s' % locals()
-            self.aggregates[hrn] = GeniClient(url, self.key_file, self.cert_file)
+    def connectAggregates(self):
+        """
+        Get connection details for the trusted peer aggregates from file and 
+        create a GeniClient connection to each.      
+        """
+        self.aggregates = {} 
+        aggregates = self.aggregate_info['aggregates']['aggregate']
+        if isinstance(aggregates, dict):
+            aggregates = [aggregates]
+        if isinstance(aggregates, list):
+            for aggregate in aggregates:         
+                # create xmlrpc connection using GeniClient
+                hrn, address, port = aggregate['hrn'], aggregate['addr'], aggregate['port']
+                if not hrn or not address or not port:
+                    continue
+                url = 'http://%(address)s:%(port)s' % locals()
+                self.aggregates[hrn] = GeniClient(url, self.key_file, self.cert_file)
 
     def item_hrns(self, items):
         """