using sfa.util.namespace instead of sfa.util.misc
[sfa.git] / sfa / plc / nodes.py
index dcf835d..9a2a853 100644 (file)
@@ -7,7 +7,7 @@ import datetime
 import sys
 import traceback
 
-from sfa.util.misc import *
+from sfa.util.namespace import *
 from sfa.util.rspec import *
 from sfa.util.specdict import * 
 from sfa.util.faults import *
@@ -20,17 +20,18 @@ from sfa.server.aggregate import Aggregates
 
 class Nodes(SimpleStorage):
 
-    def __init__(self, api, ttl = 1):
+    def __init__(self, api, ttl = 1, origin_hrn=None):
         self.api = api
         self.ttl = ttl
         self.threshold = None
-        path = self.api.config.SFA_BASE_DIR
+        path = self.api.config.SFA_DATA_DIR
         filename = ".".join([self.api.interface, self.api.hrn, "nodes"])
         filepath = path + os.sep + filename
         self.nodes_file = filepath
         SimpleStorage.__init__(self, self.nodes_file)
         self.policy = Policy(api)
         self.load()
+        self.origin_hrn = origin_hrn
 
 
     def refresh(self):
@@ -47,9 +48,8 @@ class Nodes(SimpleStorage):
             elif self.api.interface in ['slicemgr']:
                 self.refresh_nodes_smgr()
 
-        
     def refresh_nodes_aggregate(self):
-        rspec = Rspec()
+        rspec = RSpec()
         rspec.parseString(self.get_rspec())
         
         # filter nodes according to policy
@@ -109,24 +109,25 @@ class Nodes(SimpleStorage):
         aggregates = Aggregates(self.api)
         rspecs = {}
         networks = []
-        rspec = Rspec()
-        credential = self.api.getCredential() 
+        rspec = RSpec()
+        credential = self.api.getCredential()
+        origin_hrn = self.origin_hrn
         for aggregate in aggregates:
+          if aggregate not in [self.api.auth.client_cred.get_gid_caller().get_hrn()]:
             try:
                 # get the rspec from the aggregate
-                agg_rspec = aggregates[aggregate].get_resources(credential, hrn)
+                agg_rspec = aggregates[aggregate].get_resources(credential, hrn, origin_hrn)
                 # extract the netspec from each aggregates rspec
                 rspec.parseString(agg_rspec)
                 networks.extend([{'NetSpec': rspec.getDictsByTagName('NetSpec')}])
             except:
                 # XX print out to some error log
-                print >> log, "Error calling list nodes at aggregate %s" % aggregate
+                print >> log, "Error getting resources at aggregate %s" % aggregate
                 traceback.print_exc(log)
-                exc_type, exc_value, exc_traceback = sys.exc_info()
-                print exc_type, exc_value, exc_traceback
+                print >> log, "%s" % (traceback.format_exc())
         # create the rspec dict
         resources = {'networks': networks, 'start_time': start_time, 'duration': duration}
-        resourceDict = {'Rspec': resources}
+        resourceDict = {'RSpec': resources}
         # convert rspec dict to xml
         rspec.parseDict(resourceDict)
         return rspec
@@ -162,14 +163,15 @@ class Nodes(SimpleStorage):
 
     def get_rspec_smgr(self, hrn = None):
         
-       rspec = self.get_remote_resources(hrn)
-       return rspec.toxml()
+        rspec = self.get_remote_resources(hrn)
+        return rspec.toxml()
 
     def get_rspec_aggregate(self, hrn = None):
         """
         Get resource information from PLC
         """
 
+        slicename = None
         # Get the required nodes
         if not hrn:
             nodes = self.api.plshell.GetNodes(self.api.plauth, {'peer_id': None})
@@ -187,7 +189,10 @@ class Nodes(SimpleStorage):
 
         # Filter out whitelisted nodes
         public_nodes = lambda n: n.has_key('slice_ids_whitelist') and not n['slice_ids_whitelist']
-        nodes = filter(public_nodes, nodes)
+            
+        # ...only if they are not already assigned to this slice.
+        if (not slicename):        
+            nodes = filter(public_nodes, nodes)
 
         # Get all network interfaces
         interface_ids = []
@@ -254,9 +259,9 @@ class Nodes(SimpleStorage):
         resources = {'networks': networks, 'start_time': start_time, 'duration': duration}
 
         # convert the plc dict to an rspec dict
-        resourceDict = RspecDict(resources)
+        resourceDict = RSpecDict(resources)
         # convert the rspec dict to xml
-        rspec = Rspec()
+        rspec = RSpec()
         rspec.parseDict(resourceDict)
         return rspec.toxml()