4 # This file here is the connection to the SFA code
5 # at some point in time we had duplicated this from sfa
6 # but of course both versions have entirely diverged since then
7 # in addition we really only need 2 hepler functions here, that allow to maintain
8 # hrn for nodes and persons and that is all
10 # So in order to avoid such situations in the future,
11 # we try to import and re-use the SFA code
12 # assumption being that if these hrn's are of importance then it makes sense to
13 # require people to have sfa-plc installed as well
14 # however we do not want this requirement to break myplc in case it is not fulfilled
17 #################### try to import from sfa
19 from sfa.planetlab.plxrn import hostname_to_hrn
24 from sfa.planetlab.plxrn import email_to_hrn
29 from sfa.planetlab.plxrn import slicename_to_hrn
32 #################### if not found, bring our own local version
34 def escape(token): return re.sub(r'([^\\])\.', r'\1\.', token)
36 if hostname_to_hrn is None:
37 def hostname_to_hrn (auth_hrn, login_base, hostname):
38 return ".".join( [ auth_hrn, login_base, escape(hostname) ] )
40 if email_to_hrn is None:
41 def email_to_hrn (auth_hrn, email):
42 return '.'.join([auth_hrn,email.split('@')[0].replace(".", "_").replace("+", "_")])
44 if slicename_to_hrn is None:
45 def slicename_to_hrn (auth_hrn, slicename):
46 return ".".join([auth_hrn] + slicename.split("_",1))