maintain slice state at the slice manager
authorTony Mack <tmack@cs.princeton.edu>
Tue, 20 Jan 2009 21:05:28 +0000 (21:05 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Tue, 20 Jan 2009 21:05:28 +0000 (21:05 +0000)
plc/slicemgr.py

index 16041e8..54df8be 100644 (file)
@@ -57,7 +57,7 @@ class SliceMgr(GeniServer):
     def load_aggregates(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. 
+        an xmlrpc connection to each. If any info is invalid, skip it. 
        """
        lines = []
         try:
@@ -81,6 +81,7 @@ class SliceMgr(GeniServer):
            url = 'https://%(address)s:%(port)s' % locals()
            self.aggregates[hrn] = GeniClient(url, self.key_file, self.cert_file)
 
+
     def item_hrns(self, items):
        """
        Take a list of items (components or slices) and return a dictionary where
@@ -115,7 +116,7 @@ class SliceMgr(GeniServer):
 
     def refresh_components(self):
        """
-       Update the cached list of nodes and slices.
+       Update the cached list of nodes.
        """
        print "refreshing"
        
@@ -127,9 +128,6 @@ class SliceMgr(GeniServer):
                # resolve components hostnames
                nodes = self.aggregates[aggregate].get_components()
                all_nodes.extend(nodes) 
-               # resolve slices
-               slices = self.aggregates[aggregate].get_slices()
-               all_slices.extend(slice)
                # update timestamp and threshold
                self.timestamp = datetime.datetime.now()
                delta = datetime.timedelta(hours=self.components_ttl)
@@ -139,13 +137,9 @@ class SliceMgr(GeniServer):
                pass    
    
        self.components = all_nodes
-       self.slices = all_slices        
        f = open(self.components_file, 'w')
        f.write(str(self.components))
        f.close()
-       f = open(self.slices_file, 'w')
-       f.write(str(self.slices))
-       f.close()
        f = open(self.timestamp_file, 'w')
        f.write(str(self.threshold))
        f.close()
@@ -154,18 +148,13 @@ class SliceMgr(GeniServer):
        """
        Read cached list of nodes and slices.
        """
-       print "loading"
+       print "loading nodes"
        # Read component list from cached file 
        if os.path.exists(self.components_file):
            f = open(self.components_file, 'r')
            self.components = eval(f.read())
            f.close()
        
-       if os.path.exists(self.slices_file):
-            f = open(self.components_file, 'r')
-            self.slices = eval(f.read())
-            f.close()
-
        time_format = "%Y-%m-%d %H:%M:%S"
        if os.path.exists(self.timestamp_file):
            f = open(self.timestamp_file, 'r')
@@ -173,7 +162,27 @@ class SliceMgr(GeniServer):
            self.timestamp = datetime.datetime.fromtimestamp(time.mktime(time.strptime(timestamp, time_format)))
            delta = datetime.timedelta(hours=self.components_ttl)
             self.threshold = self.timestamp + delta
-           f.close()   
+           f.close()
+    def load_slices(self):
+       """
+       Read current slice instantiation states.
+       """
+       print "loading slices"
+       if os.path.exists(self.slices_file):
+            f = open(self.components_file, 'r')
+            self.slices = eval(f.read())
+            f.close()  
+
+    def write_slices(self):
+        """
+        Write current slice instantiations to file.
+        """
+        print "writing slices"
+        f = open(self.slices_file, 'w')
+        f.write(str(self.slices))
+        f.close()
+
 
     def get_components(self):
        """
@@ -201,6 +210,17 @@ class SliceMgr(GeniServer):
            self.load_components()
        return self.slices
 
+    def get_slivers(self, hrn):
+       """
+       Return the list of slices instantiated at the specified component.
+       """
+
+       # hrn is assumed to be a component hrn
+       if hrn not in self.slices:
+           raise Exception, hrn + " not found"
+       
+       return self.slices[hrn]
+
     def get_rspec(self, hrn, type):
        #rspec = Rspec()
        if type in ['node']: