Merge branch 'master' of ssh://bakers@git.planet-lab.org/git/sfa
[sfa.git] / sfa / managers / slice_manager_pl.py
index 57d888a..995b837 100644 (file)
@@ -33,27 +33,18 @@ from sfa.util.version import version_core
 from sfa.util.callids import Callids
 
 
-def _get_cached_server_version(api, server):
-    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
-        api.cache.add(cache_key, server_version, ttl= 60*60*24)
-    return server_version
-
 def _call_id_supported(api, server):
     """
     Returns true if server support the optional call_id arg, false otherwise.
     """
-    server_version = _get_cached_server_version(api, server)
+    server_version = api.get_cached_server_version(server)
 
     if 'sfa' in server_version:
         code_tag = server_version['code_tag']
         code_tag_parts = code_tag.split("-")
 
         version_parts = code_tag_parts[0].split(".")
-        major, minor = version_parts[0], version_parts[1]
+        major, minor = version_parts[0:2]
         rev = code_tag_parts[1]
         if int(major) > 1:
             if int(minor) > 0 or int(rev) > 20:
@@ -137,6 +128,7 @@ def ListResources(api, creds, options, call_id):
         # unless the caller is the aggregate's SM
         if caller_hrn == aggregate and aggregate != api.hrn:
             continue
+
         # get the rspec from the aggregate
         server = api.aggregates[aggregate]
         #threads.run(server.ListResources, credentials, my_opts, call_id)
@@ -164,20 +156,20 @@ def ListResources(api, creds, options, call_id):
 def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
 
     def _CreateSliver(server, xrn, credential, rspec, users, call_id):
+        try:
             # Need to call GetVersion at an aggregate to determine the supported 
             # rspec type/format beofre calling CreateSliver at an Aggregate. 
-            server_version = _get_server_version(api, server)    
-            if 'sfa' not in aggregate_version and 'geni_api' in aggregate_version:
+            server_version = api.get_cached_server_version(server)    
+            if 'sfa' not in server_version and 'geni_api' in server_version:
                 # sfa aggregtes support both sfa and pg rspecs, no need to convert
-                # if aggregate supports sfa rspecs. othewise convert to pg rspec
+                # if aggregate supports sfa rspecs. otherwise convert to pg rspec
                 rspec = RSpecConverter.to_pg_rspec(rspec)
             args = [xrn, credential, rspec, users]
             if _call_id_supported(api, server):
                 args.append(call_id)
-            try:
-                return server.CreateSliver(*args)
-            except Exception, e:
-                api.logger.warn("CreateSliver failed at %s: %s" %(server.url, str(e)))
+            return server.CreateSliver(*args)
+        except: 
+            logger.log_exc('Something wrong in _CreateSliver with URL %s'%server.url)
 
     if Callids().already_handled(call_id): return ""
     # Validate the RSpec against PlanetLab's schema --disabled for now