X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sfa%2Fplanetlab%2Fplxrn.py;h=7d2c5bb3a67b82057dc65a5670667c66c67b4ba8;hb=5064f82a7a8ae78d7ad0ace873e3870811c4a4b8;hp=22e94181695c32f031da6162aed33a8dc3a32985;hpb=e8b16b96a23e1ab54e780587cc7cc0345a1ddf0e;p=sfa.git diff --git a/sfa/planetlab/plxrn.py b/sfa/planetlab/plxrn.py index 22e94181..7d2c5bb3 100644 --- a/sfa/planetlab/plxrn.py +++ b/sfa/planetlab/plxrn.py @@ -1,6 +1,6 @@ # specialized Xrn class for PlanetLab import re -from sfa.util.xrn import Xrn +from sfa.util.xrn import Xrn, get_authority # temporary helper functions to use this module instead of namespace def hostname_to_hrn (auth, login_base, hostname): @@ -21,6 +21,22 @@ def hrn_to_pl_authname (hrn): def xrn_to_hostname(hrn): return Xrn.unescape(PlXrn(xrn=hrn, type='node').get_leaf()) +# helpers to handle external objects created via fedaration +def top_auth (hrn): + return hrn.split('.')[0] + +def hash_loginbase(site_hrn): + if len(site_hrn) <= 12: + return site_hrn.replace('.','8') + ratio = float(12) / len(site_hrn) + auths_tab = site_hrn.split('.') + auths_tab2 = [] + for auth in auths_tab: + auth2 = auth[:int(len(auth)*ratio)] + auths_tab2.append(auth2) + + return '8'.join(auths_tab2) + class PlXrn (Xrn): @staticmethod @@ -83,7 +99,7 @@ class PlXrn (Xrn): # Fix up names of GENI Federates base = base.lower() - base = re.sub('\\\[^a-zA-Z0-9]', '', base) + base = re.sub('[\\\\]*[^a-zA-Z0-9]', '', base) if len(base) > 20: base = base[len(base)-20:]