modify accept arguments for get_rspec, preparing to switch to protogeni api spec
authorTony Mack <tmack@cs.princeton.edu>
Mon, 2 Aug 2010 21:24:55 +0000 (21:24 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Mon, 2 Aug 2010 21:24:55 +0000 (21:24 +0000)
sfa/managers/aggregate_manager_pl.py
sfa/managers/slice_manager_pl.py

index bf19c2f..6021cea 100644 (file)
@@ -17,6 +17,7 @@ from sfa.util.record import *
 from sfa.util.sfaticket import SfaTicket
 from sfa.util.debug import log
 from sfa.plc.slices import Slices
+from sfa.trust.credential import Credential
 import sfa.plc.peers as peers
 from sfa.plc.network import *
 from sfa.plc.api import SfaAPI
@@ -204,14 +205,22 @@ def get_slices(api):
 
     return slice_urns
     
-def get_rspec(api, xrn=None, origin_hrn=None):
+def get_rspec(api, creds, options):
+    # get slice's hrn from options
+    xrn = options.get('geni_slice_urn', None)
+    hrn, type = urn_to_hrn(xrn)
+
+    # get hrn of the original caller
+    origin_hrn = options.get('origin_hrn', None)
+    if not origin_hrn:
+        origin_hrn = Credential(string=creds[0]).get_gid_caller().get_hrn()
+    
     # look in cache first
     if api.cache and not xrn:
         rspec = api.cache.get('nodes')
         if rspec:
             return rspec 
 
-    hrn, type = urn_to_hrn(xrn)
     network = Network(api)
     if (hrn):
         if network.get_slice(api, hrn):
@@ -225,6 +234,7 @@ def get_rspec(api, xrn=None, origin_hrn=None):
 
     return rspec
 
+
 """
 Returns the request context required by sfatables. At some point, this
 mechanism should be changed to refer to "contexts", which is the
index 97bdcda..d141539 100644 (file)
@@ -18,6 +18,7 @@ from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
 from sfa.util.prefixTree import prefixTree
 from sfa.util.sfaticket import *
+from sfa.trust.credential import Credential
 from sfa.util.threadmanager import ThreadManager
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol     
 from sfa.util.debug import log
@@ -111,7 +112,6 @@ def get_ticket(api, xrn, rspec, origin_hrn=None):
         attrs = agg_ticket.get_attributes()
         if not object_gid:
             object_gid = agg_ticket.get_gid_object()
-        print object_gid
         rspecs.append(agg_ticket.get_rspec())
         initscripts.extend(attrs.get('initscripts', [])) 
         slivers.extend(attrs.get('slivers', [])) 
@@ -183,7 +183,16 @@ def get_slices(api):
 
     return slices
  
-def get_rspec(api, xrn=None, origin_hrn=None):
+def get_rspec(api, creds, options):
+    # get slice's hrn from options
+    xrn = options.get('geni_slice_urn', None)
+    hrn, type = urn_to_hrn(xrn)
+
+    # get hrn of the original caller
+    origin_hrn = options.get('origin_hrn', None)
+    if not origin_hrn:
+        origin_hrn = Credential(string=creds[0]).get_gid_caller().get_hrn()
+    
     # look in cache first 
     if api.cache and not xrn:
         rspec =  api.cache.get('nodes')
@@ -192,13 +201,23 @@ def get_rspec(api, xrn=None, origin_hrn=None):
 
     hrn, type = urn_to_hrn(xrn)
     rspec = None
+    # XX
+    # XX TODO: Should try to use delegated credential first 
+    # XX
     cred = api.getCredential()
     threads = ThreadManager()
+    
     for aggregate in api.aggregates:
-        if aggregate not in [api.auth.client_cred.get_gid_caller().get_hrn()]:      
+        if aggregate not in [api.auth.client_cred.get_gid_caller().get_hrn()]:   
             # get the rspec from the aggregate
             server = api.aggregates[aggregate]
+            # XX
+            # XX TODO: switch to ProtoGeni spec in next release. Give other 
+            # XX aggregtes a chacne to upgrade to this release before switching 
+            # XX 
+            # threads.run(server.ListResources, cred, options)
             threads.run(server.get_resources, cred, xrn, origin_hrn)
+                    
 
     results = threads.get_results()
     # combine the rspecs into a single rspec 
@@ -218,7 +237,8 @@ def get_rspec(api, xrn=None, origin_hrn=None):
                     rspec.append(deepcopy(network))
                 for request in root.iterfind("./request"):
                     rspec.append(deepcopy(request))
-
+    
+    print results
     rspec =  etree.tostring(rspec, xml_declaration=True, pretty_print=True)
     # cache the result
     if api.cache and not xrn: