GENICloud should only return the resources managed by its aggregates
[sfa.git] / sfa / managers / slice_manager_pl.py
index 5ed2261..c7d6fed 100644 (file)
@@ -37,12 +37,7 @@ def _call_id_supported(api, server):
     """
     Returns true if server support the optional call_id arg, false otherwise.
     """
-    cache_key = server.url + "-version"
-    server_version = api.cache.get(cache_key)
-    if not server_version:
-        server_version = server.GetVersion()
-        # cache version for 24 hours
-        cache.add(cache_key, server_version, ttl= 60*60*24)
+    server_version = api.get_cached_server_version(server)
 
     if 'sfa' in server_version:
         code_tag = server_version['code_tag']
@@ -93,7 +88,10 @@ def ListResources(api, creds, options, call_id):
         args = [credential, my_opts]
         if _call_id_supported(api, server):
             args.append(call_id)
-        return server.ListResources(*args)
+        try:
+            return server.ListResources(*args)
+        except Exception, e:
+            api.logger.warn("ListResources failed at %s: %s" %(server.url, str(e)))
 
     if Callids().already_handled(call_id): return ""
 
@@ -102,6 +100,8 @@ def ListResources(api, creds, options, call_id):
     (hrn, type) = urn_to_hrn(xrn)
     my_opts = copy(options)
     my_opts['geni_compressed'] = False
+    if 'rspec_version' in my_opts:
+        del my_opts['rspec_version']
 
     # get the rspec's return format from options
     rspec_version = RSpecVersion(options.get('rspec_version'))
@@ -121,16 +121,22 @@ def ListResources(api, creds, options, call_id):
     credential = api.getDelegatedCredential(creds)
     if not credential:
         credential = api.getCredential()
+    credentials = [credential]
     threads = ThreadManager()
     for aggregate in api.aggregates:
         # prevent infinite loop. Dont send request back to caller
         # unless the caller is the aggregate's SM
         if caller_hrn == aggregate and aggregate != api.hrn:
             continue
+
+        # For GENICloud
+        if aggregate == api.hrn:
+            continue
+
         # get the rspec from the aggregate
         server = api.aggregates[aggregate]
-        #threads.run(server.ListResources, credential, my_opts, call_id)
-        threads.run(_ListResources, server, credential, my_opts, call_id)
+        #threads.run(server.ListResources, credentials, my_opts, call_id)
+        threads.run(_ListResources, server, credentials, my_opts, call_id)
 
     results = threads.get_results()
     rspec_version = RSpecVersion(my_opts.get('rspec_version'))
@@ -164,7 +170,10 @@ def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
             args = [xrn, credential, rspec, users]
             if _call_id_supported(api, server):
                 args.append(call_id)
-            return server.CreateSliver(*args)
+            try:
+                return server.CreateSliver(*args)
+            except Exception, e:
+                api.logger.warn("CreateSliver failed at %s: %s" %(server.url, str(e)))
 
     if Callids().already_handled(call_id): return ""
     # Validate the RSpec against PlanetLab's schema --disabled for now
@@ -350,23 +359,6 @@ def ListSlices(api, creds, call_id):
     return slices
 
 
-    if rspec_version['type'] == pg_rspec_ad_version['type']:
-        rspec = PGRSpec()
-    else:
-        rspec = SfaRSpec()
-    for result in results:
-        try:
-            rspec.merge(result)
-        except:
-            api.logger.info("SM.ListResources: Failed to merge aggregate rspec")
-
-    # cache the result
-    if caching and api.cache and not xrn:
-        api.cache.add(version_string, rspec.toxml())
-
-    return rspec.toxml()
-
-
 def get_ticket(api, xrn, creds, rspec, users):
     slice_hrn, type = urn_to_hrn(xrn)
     # get the netspecs contained within the clients rspec