Added missing import. NT.
[sfa.git] / sfa / senslab / slab-import.py
index 9bf855a..ae306a8 100644 (file)
@@ -10,9 +10,13 @@ from sfa.senslab.OARrestapi import OARapi
 from sfa.senslab.LDAPapi import LDAPapi
 from sfa.senslab.slabdriver import SlabDriver
 from sfa.util.config import Config
-from sfa.util.xrn import hrn_to_urn, get_authority
+from sfa.util.xrn import hrn_to_urn, get_authority,Xrn,get_leaf
 from sfa.util.table import SfaTable
+from sfa.util.record import SfaRecord
 from sfa.trust.hierarchy import Hierarchy
+from sfa.trust.certificate import Keypair
+from sfa.trust.gid import create_uuid
+
 
 AuthHierarchy = Hierarchy()
 table = SfaTable()
@@ -87,7 +91,13 @@ def delete_record( hrn, type):
     for record in record_list:
         table.remove(record)
                 
-                
+def hostname_to_hrn(root_auth,hostname):
+    # keep only the first part of the DNS name
+    #hrn='.'.join( [auth,hostname.split(".")[0] ] )
+    # escape the '.' in the hostname
+    hrn='.'.join( [root_auth,Xrn.escape(hostname)] )
+    return hrn_to_urn(hrn,'node')
+    
 def main():
 
     config = Config()
@@ -126,9 +136,9 @@ def main():
         
     #Get Senslab nodes 
    
-    Driver = SlabDriver(OARapi(),LDAPapi())
+    Driver = SlabDriver(config)
     nodes_dict  = Driver.GetNodes()
-    print "\r\n NODES8DICT ",nodes_dict
+    #print "\r\n NODES8DICT ",nodes_dict
     
     ldap_person_list = Driver.GetPersons()
     print "\r\n PERSONS_LIST ",ldap_person_list
@@ -153,24 +163,21 @@ def main():
             #(site_hrn, 'authority') not in existing_records:
              #print "SITE HRN UNKNOWN" , site, site_hrn
              #site_hrn = SenslabImporter.import_site(interface_hrn, site)
-            
-    print "\r\n \r\n ===========IMPORT NODE_RECORDS ==========\r\n site %s \r\n \t nodes_dict %s" %(site,nodes_dict)            
+   
         # import node records
        #for node_id in site['node_ids']:
                #for[node['node_id'] for node in nodes_dict]:
                        #print '\r\n \t **NODE_ID %s node %s '%( node_id, node)         
                        #continue 
     for node in nodes_dict:
-        print '\r\n \t NODE_ID %s node %s '%( node_id, node)
-        hrn =  hostname_to_hrn(interface_hrn, root_auth, node['hostname'])
+        hrn =  hostname_to_hrn( root_auth, node['hostname'])
         if hrn not in existing_hrns or \
         (hrn, 'node') not in existing_records:
-            print "\t\t NODE HRN NOT in existing records!" ,hrn
+            print "\t\t NODE HRN NOT in existing record, importing it" ,hrn
             import_node(hrn, node)
 
    # import persons
     for person in ldap_person_list:
-        print >>sys.stderr, "\r\n\r\n^^^^^^^^^^^^^PERSON hrn %s person %s site hrn %s" %(hrn,person)    
         if person['hrn'] not in existing_hrns or \
             (person['hrn'], 'user') not in existing_records :
             import_person( person)