fixed up the names of new site names/slices to be more PLC compatible
authorJosh Karlin <jkarlin@bbn.com>
Wed, 29 Sep 2010 18:13:40 +0000 (14:13 -0400)
committerJosh Karlin <jkarlin@bbn.com>
Wed, 29 Sep 2010 18:13:40 +0000 (14:13 -0400)
sfa/managers/aggregate_manager_pl.py
sfa/plc/slices.py
sfa/util/namespace.py

index fe4e53d..ff11270 100644 (file)
@@ -38,9 +38,10 @@ def __get_registry_objects(slice_xrn, creds, users):
 
     if users:
         # dont allow special characters in the site login base
-        only_alphanumeric = re.compile('[^a-zA-Z0-9]+')
-        login_base = only_alphanumeric.sub('', hrn_auth[:20]).lower()
-  
+        #only_alphanumeric = re.compile('[^a-zA-Z0-9]+')
+        #login_base = only_alphanumeric.sub('', hrn_auth[:20]).lower()
+        slicename = hrn_to_pl_slicename(hrn)
+        login_base = slicename.split('_')[0]
         reg_objects = {}
 
         site = {}
@@ -60,7 +61,7 @@ def __get_registry_objects(slice_xrn, creds, users):
         slice = {}
         slice['expires'] = int(time.mktime(Credential(string=creds[0]).get_lifetime().timetuple()))
         slice['hrn'] = hrn
-        slice['name'] = site['login_base'] + "_" +  get_leaf(hrn)
+        slice['name'] = hrn_to_pl_slicename(hrn)
         slice['url'] = hrn
         slice['description'] = hrn
         slice['pointer'] = 0
index 9b3ff5d..041a562 100644 (file)
@@ -171,9 +171,10 @@ class Slices:
     def verify_site(self, registry, credential, slice_hrn, peer, sfa_peer, reg_objects=None):
         authority = get_authority(slice_hrn)
         authority_urn = hrn_to_urn(authority, 'authority')
-        
+        login_base = None
         if reg_objects:
             site = reg_objects['site']
+            login_base = site['login_base']
         else:
             site_records = registry.Resolve(authority_urn, [credential])
             site = {}            
@@ -184,8 +185,9 @@ class Slices:
                 raise RecordNotFound(authority)
             
         remote_site_id = site.pop('site_id')    
-                
-        login_base = get_leaf(authority)
+        
+        if login_base is None:
+            login_base = get_leaf(authority)
         sites = self.api.plshell.GetSites(self.api.plauth, login_base)
 
         if not sites:
@@ -238,8 +240,7 @@ class Slices:
             for key in slice_keys:
                 if key in slice_record and slice_record[key]:
                     slice_fields[key] = slice_record[key]
-
-            # add the slice  
+            # add the slice                          
             slice_id = self.api.plshell.AddSlice(self.api.plauth, slice_fields)
             slice = slice_fields
             slice['slice_id'] = slice_id
index fcc65ba..89a9903 100644 (file)
@@ -19,22 +19,22 @@ def get_authority(xrn):
 def hrn_to_pl_slicename(hrn):
     # remove any escaped no alpah numeric characters
     #hrn = re.sub('\\\[^a-zA-Z0-9]', '', hrn)
-    # remove any escaped '.' (i.e. '\.')
-    hrn.replace('\\.', '')
-    parts = hrn.split(".")
+    # remove any escaped '.' (i.e. '\.')      
+    hrn = hrn.replace('\\.', '')    
+    parts = hrn.split(".")  
     return parts[-2] + "_" + parts[-1]
 
 # assuming hrn is the hrn of an authority, return the plc authority name
 def hrn_to_pl_authname(hrn):
     # remove any escaped '.' (i.e. '\.')
-    hrn.replace('\\.', '')
+    hrn = hrn.replace('\\.', '')
     parts = hrn.split(".")
     return parts[-1]
 
 # assuming hrn is the hrn of an authority, return the plc login_base
 def hrn_to_pl_login_base(hrn):
     # remove any escaped '.' (i.e. '\.')
-    hrn.replace('\\.', '')
+    hrn = hrn.replace('\\.', '')
     return hrn_to_pl_authname(hrn)
 
 def hostname_to_hrn(auth_hrn, login_base, hostname):
@@ -85,7 +85,7 @@ def urn_to_hrn(urn):
     # 2. escape '.'            # '.' exists in protogeni object names and are not delimiters
     # 3. replace ':' with '.'  # ':' is the urn hierarchy delimiter
     # 4. join list elements using '.' 
-    hrn = '.'.join([part.replace('.', '\.').replace(':', '.') for part in hrn_parts if part]) 
+    hrn = '.'.join([part.replace('.', '\\.').replace(':', '.') for part in hrn_parts if part]) 
     
     return str(hrn), str(type)