Minimal cleanup to import managers without Errors. NT.
[sfa.git] / sfa / managers / slice_manager_slab.py
index 81a99e2..e67d2b5 100644 (file)
@@ -9,11 +9,11 @@ from lxml import etree
 
 from sfa.util.sfalogging import logger
 #from sfa.util.sfalogging import sfa_logger
-from sfa.util.rspecHelper import merge_rspecs
+#from sfa.util.rspecHelper import merge_rspecs
 from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn
 from sfa.util.plxrn import hrn_to_pl_slicename
-from sfa.util.rspec import *
-from sfa.util.specdict import *
+#from sfa.util.rspec import *
+#from sfa.util.specdict import *
 from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 #from sfa.rspecs.pg_rspec import PGRSpec
@@ -26,16 +26,38 @@ from sfa.rspecs.rspec_converter import RSpecConverter
 from sfa.client.client_helper import sfa_to_pg_users_arg
 from sfa.rspecs.version_manager import VersionManager
 
-from sfa.rspecs.rspec import RSpec 
+#from sfa.rspecs.rspec import RSpec 
 from sfa.util.policy import Policy
 from sfa.util.prefixTree import prefixTree
-from sfa.util.sfaticket import *
+#from sfa.util.sfaticket import *
 from sfa.trust.credential import Credential
-from sfa.util.threadmanager import ThreadManager
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol     
-import sfa.plc.peers as peers
+#from sfa.util.threadmanager import ThreadManager
+#import sfa.util.xmlrpcprotocol as xmlrpcprotocol     
+#import sfa.plc.peers as peers
 from sfa.util.version import version_core
 from sfa.util.callids import Callids
+#from sfa.senslab.api import *
+
+
+#api=SfaAPI(interface='slicemgr')
+
+def _call_id_supported(api, server):
+    """
+    Returns true if server support the optional call_id arg, false otherwise.
+    """
+    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:2]
+        rev = code_tag_parts[1]
+        if int(major) > 1:
+            if int(minor) > 0 or int(rev) > 20:
+                return True
+    return False
 
 # we have specialized xmlrpclib.ServerProxy to remember the input url
 # OTOH it's not clear if we're only dealing with XMLRPCServerProxy instances
@@ -111,16 +133,15 @@ def drop_slicemgr_stats(api,rspec):
  
  
 def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
+       
        version_manager = VersionManager()
-       def _CreateSliver(aggregate, xrn, credential, rspec, users, call_id):
-       # Need to call ParseVersion at an aggregate to determine the supported 
-       # rspec type/format beofre calling CreateSliver at an Aggregate. 
-       # The Aggregate's verion info is cached 
+       def _CreateSliver(aggregate, server, xrn, credential, rspec, users, call_id):
                
                tStart = time.time()
                try:
                        # Need to call GetVersion at an aggregate to determine the supported
                        # rspec type/format beofre calling CreateSliver at an Aggregate.
+                       print>>sys.stderr, " \r\n SLICE MANAGERSLAB _CreateSliver server " 
                        server_version = api.get_cached_server_version(server)
                        requested_users = users
                        if 'sfa' not in server_version and 'geni_api' in server_version:
@@ -160,23 +181,26 @@ def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
        credential = api.getDelegatedCredential(creds)
        if not credential:
                credential = api.getCredential()
-       
+
        # get the callers hrn
        hrn, type = urn_to_hrn(xrn)
        valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0]
        caller_hrn = Credential(string=valid_cred).get_gid_caller().get_hrn()
        threads = ThreadManager()
-       
+       print>>sys.stderr, " \r\n \r\n \t\t =======SLICE MANAGER _CreateSliver api aggregates  %s \t caller_hrn %s api.hrn %s" %(api.aggregates, caller_hrn, api.hrn)
        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
                interface = api.aggregates[aggregate]
-               server = api.get_server(interface, credential)   
+               print>>sys.stderr, " \r\n \r\n \t\t =======SLICE MANAGER _CreateSliver aggregate %s interface %s" %(api.aggregates[aggregate],interface)   
+               server = api.get_server(interface, credential)
+               if server is None:
+                       print>>sys.stderr, " \r\n \r\n \t\t =======SLICE MANAGER _CreateSliver NOSERVERS "  
                # Just send entire RSpec to each aggregate
-               threads.run(_CreateSliver, aggregate, xrn, [credential], rspec.toxml(), users, call_id)
-               
+               #threads.run(_CreateSliver, aggregate, xrn, [credential], rspec.toxml(), users, call_id)
+               threads.run(_CreateSliver, aggregate, server, xrn, [credential], rspec.toxml(), users, call_id)
        results = threads.get_results()
        manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest')
        result_rspec = RSpec(version=manifest_version)