if the record exist dont try to add it, update it
[plcapi.git] / PLC / SFA.py
index b1cdbc4..883f570 100644 (file)
@@ -69,7 +69,7 @@ class SFA:
         elif object.has_key('site_ids') and object['site_ids']:
             site_ids.extend(object['site_ids'])
         else:
-            raise Exception
+            return login_bases
 
         # get the login bases
         for site_id in site_ids:
@@ -81,11 +81,11 @@ class SFA:
         parent_hrn = authority + "." + login_base 
         if type in ['person', 'user']:
             name_parts = object['email'].split("@")
-            hrn = parent_hrn + "." + name_parts[:1]
+            hrn = parent_hrn + "." + name_parts[:1][0]
         
         elif type in ['slice']:
             name_parts = object['name'].split("_")
-            hrn = parent_hrn + "." + name_parts[-1:]
+            hrn = parent_hrn + "." + name_parts[-1:][0]
         
         elif type in ['node']:
             hrn = hostname_to_hrn(self.authority, login_base, object['hostname'])
@@ -154,6 +154,8 @@ class SFA:
             # add the record to sfa
             if not self.sfa_record_exists(object['hrn'], type):
                 self.registry.register(self.credential, record)
+            else:
+                self.registry.update(self.credential, record)
 
     @wrap_exception
     @required_packages_imported