From: Josh Karlin Date: Wed, 29 Sep 2010 18:13:40 +0000 (-0400) Subject: fixed up the names of new site names/slices to be more PLC compatible X-Git-Tag: sfa-1.0-2~7^2~1 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=a8a91083ea1868971c7884a405ce3fe89010eede fixed up the names of new site names/slices to be more PLC compatible --- diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index fe4e53d1..ff11270a 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -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 diff --git a/sfa/plc/slices.py b/sfa/plc/slices.py index 9b3ff5df..041a5625 100644 --- a/sfa/plc/slices.py +++ b/sfa/plc/slices.py @@ -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 diff --git a/sfa/util/namespace.py b/sfa/util/namespace.py index fcc65ba4..89a9903d 100644 --- a/sfa/util/namespace.py +++ b/sfa/util/namespace.py @@ -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)