1 # specialized Xrn class for PlanetLab
3 from sfa.util.xrn import Xrn
5 # temporary helper functions to use this module instead of namespace
6 def hostname_to_hrn (auth, login_base, hostname):
7 return PlXrn(auth=auth+'.'+login_base,hostname=hostname).get_hrn()
8 def slicename_to_hrn (auth_hrn, slicename):
9 return PlXrn(auth=auth_hrn,slicename=slicename).get_hrn()
10 def email_to_hrn (auth_hrn, email):
11 return PlXrn(auth=auth_hrn, email=email).get_hrn()
12 def hrn_to_pl_slicename (hrn):
13 return PlXrn(xrn=hrn,type='slice').pl_slicename()
14 def hrn_to_pl_login_base (hrn):
15 return PlXrn(xrn=hrn,type='slice').pl_login_base()
16 def hrn_to_pl_authname (hrn):
17 return PlXrn(xrn=hrn,type='any').pl_authname()
23 def site_hrn (auth, login_base):
24 return '.'.join(auth,login_base)
26 def __init__ (self, auth=None, hostname=None, slicename=None, email=None, **kwargs):
27 #def hostname_to_hrn(auth_hrn, login_base, hostname):
28 if hostname is not None:
30 # keep only the first part of the DNS name
31 self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
33 #def slicename_to_hrn(auth_hrn, slicename):
34 elif slicename is not None:
36 # split at the first _
37 parts = slicename.split("_",1)
38 self.hrn = ".".join([auth] + parts )
40 #def email_to_hrn(auth_hrn, email):
41 elif email is not None:
43 # keep only the part before '@' and replace special chars into _
44 self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")])
47 Xrn.__init__ (self,**kwargs)
49 #def hrn_to_pl_slicename(hrn):
50 def pl_slicename (self):
53 leaf = re.sub('[^a-zA-Z0-9]', '', leaf)
54 return self.pl_login_base() + '_' + leaf
56 #def hrn_to_pl_authname(hrn):
57 def pl_authname (self):
59 return self.authority[-1]
61 #def hrn_to_pl_login_base(hrn):
62 def pl_login_base (self):
64 base = self.authority[-1]
66 # Fix up names of GENI Federates
68 base = re.sub('\\\[^a-zA-Z0-9]', '', base)
71 base = base[len(base)-20:]