X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplanetlab%2Fplxrn.py;h=70ff5e02bdf81152291288350b303fcf89a6431c;hb=fad16c7d54b658b37a9b42fbee47b0d4f51cb8ec;hp=c9fa5ca00d06a7350713d0a61761380e86219436;hpb=cc8495078fb3e681cf38b47393255eb33b199f4c;p=sfa.git diff --git a/sfa/planetlab/plxrn.py b/sfa/planetlab/plxrn.py index c9fa5ca0..70ff5e02 100644 --- a/sfa/planetlab/plxrn.py +++ b/sfa/planetlab/plxrn.py @@ -1,3 +1,5 @@ +from __future__ import print_function + # specialized Xrn class for PlanetLab import re from sfa.util.xrn import Xrn, get_authority @@ -27,14 +29,15 @@ def top_auth (hrn): def hash_loginbase(site_hrn): if len(site_hrn) <= 12: - return site_hrn.replace('.','8') + return site_hrn.replace('.','8').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) + auth = auth.replace('_', '8') + auth2 = auth[:int(len(auth)*ratio)] + auths_tab2.append(auth2) return '8'.join(auths_tab2) class PlXrn (Xrn): @@ -99,9 +102,18 @@ 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:] - return base + +tests = [ + 'inria.foo.x', + 'in.foo.x_y', + 'inria.foo.longer', + 'onelab.upmc.fit_demo', + 'onelab.upmc.fit_demo.some_other', +] + +if __name__ == '__main__': + for test in tests: + print(("{} - hash_loginbase -> {}".format(test, hash_loginbase(test))))