Fixed slicemanager record creation problem from merge from mainstream.
[sfa.git] / sfa / senslab / SenslabImport.py
index 22fd546..716e484 100644 (file)
@@ -1,3 +1,4 @@
+
 #
 # The import tool assumes that the existing PLC hierarchy should all be part
 # of "planetlab.us" (see the root_auth and level1_auth variables below).
@@ -11,8 +12,8 @@
 import getopt
 import sys
 import tempfile
-
-from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
+from sfa.util.sfalogging import _SfaLogger
+#from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
 
 from sfa.util.record import *
 from sfa.util.table import SfaTable
@@ -20,11 +21,12 @@ from sfa.util.xrn import get_authority, hrn_to_urn
 from sfa.util.plxrn import email_to_hrn
 from sfa.util.config import Config
 from sfa.trust.certificate import convert_public_key, Keypair
-from sfa.trust.trustedroot import *
+from sfa.trust.trustedroots import *
 from sfa.trust.hierarchy import *
 from sfa.trust.gid import create_uuid
 
 
+
 def _un_unicode(str):
    if isinstance(str, unicode):
        return str.encode("ascii", "ignore")
@@ -52,15 +54,35 @@ def _cleanup_string(str):
 class SenslabImport:
 
     def __init__(self):
-       sfa_logger_goes_to_import()
-       self.logger = sfa_logger()
+       self.logger = _SfaLogger(logfile='/var/log/sfa_import.log', loggername='importlog')
+    
+       #sfa_logger_goes_to_import()
+       #self.logger = sfa_logger()
        self.AuthHierarchy = Hierarchy()
        self.config = Config()
-       self.TrustedRoots = TrustedRootList(Config.get_trustedroots_dir(self.config))
+       self.TrustedRoots = TrustedRoots(Config.get_trustedroots_dir(self.config))
        print>>sys.stderr, "\r\n ========= \t\t SenslabImport TrustedRoots\r\n" ,  self.TrustedRoots
        self.plc_auth = self.config.get_plc_auth()
+       print>>sys.stderr, "\r\n ========= \t\t SenslabImport  self.plc_auth %s \r\n" %(self.plc_auth ) 
        self.root_auth = self.config.SFA_REGISTRY_ROOT_AUTH
 
+    def create_sm_client_record(self):
+        """
+        Create a user record for the Slicemanager service.
+        """
+        hrn = self.config.SFA_INTERFACE_HRN + '.slicemanager'
+        urn = hrn_to_urn(hrn, 'user')
+        if not self.AuthHierarchy.auth_exists(urn):
+            self.logger.info("Import: creating Slice Manager user")
+            self.AuthHierarchy.create_auth(urn)
+
+        auth_info = self.AuthHierarchy.get_auth_info(hrn)
+        table = SfaTable()
+        sm_user_record = table.find({'type': 'user', 'hrn': hrn})
+        if not sm_user_record:
+            record = SfaRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="user", pointer=-1)
+            record['authority'] = get_authority(record['hrn'])
+            table.insert(record)    
 
     def create_top_level_auth_records(self, hrn):
         """
@@ -164,8 +186,9 @@ class SenslabImport:
             table.update(person_record)
 
     def import_slice(self, parent_hrn, slice):
-        slicename = slice['name'].split("_",1)[-1]
-        slicename = _cleanup_string(slicename)
+        #slicename = slice['name'].split("_",1)[-1]
+       
+        slicename = _cleanup_string(slice['name'])
 
         if not slicename:
             self.logger.error("Import: failed to parse slice name %s" %slice['name'])