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 hostname_to_urn(auth, login_base, hostname):
9 return PlXrn(auth=auth+'.'+login_base,hostname=hostname).get_urn()
10 def slicename_to_hrn (auth_hrn, slicename):
11 return PlXrn(auth=auth_hrn,slicename=slicename).get_hrn()
12 def email_to_hrn (auth_hrn, email):
13 return PlXrn(auth=auth_hrn, email=email).get_hrn()
14 def hrn_to_pl_slicename (hrn):
15 return PlXrn(xrn=hrn,type='slice').pl_slicename()
16 def hrn_to_pl_login_base (hrn):
17 return PlXrn(xrn=hrn,type='slice').pl_login_base()
18 def hrn_to_pl_authname (hrn):
19 return PlXrn(xrn=hrn,type='any').pl_authname()
25 def site_hrn (auth, login_base):
26 return '.'.join(auth,login_base)
28 def __init__ (self, auth=None, hostname=None, slicename=None, email=None, **kwargs):
29 #def hostname_to_hrn(auth_hrn, login_base, hostname):
30 if hostname is not None:
32 # keep only the first part of the DNS name
33 self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
35 #def slicename_to_hrn(auth_hrn, slicename):
36 elif slicename is not None:
38 # split at the first _
39 parts = slicename.split("_",1)
40 self.hrn = ".".join([auth] + parts )
42 #def email_to_hrn(auth_hrn, email):
43 elif email is not None:
45 # keep only the part before '@' and replace special chars into _
46 self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")])
49 Xrn.__init__ (self,**kwargs)
51 #def hrn_to_pl_slicename(hrn):
52 def pl_slicename (self):
55 leaf = re.sub('[^a-zA-Z0-9]', '', leaf)
56 return self.pl_login_base() + '_' + leaf
58 #def hrn_to_pl_authname(hrn):
59 def pl_authname (self):
61 return self.authority[-1]
63 #def hrn_to_pl_login_base(hrn):
64 def pl_login_base (self):
66 base = self.authority[-1]
68 # Fix up names of GENI Federates
70 base = re.sub('\\\[^a-zA-Z0-9]', '', base)
73 base = base[len(base)-20:]