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 # removed-dangerous - was used for non-slice objects
17 #def hrn_to_pl_login_base (hrn):
18 # return PlXrn(xrn=hrn,type='slice').pl_login_base()
19 def hrn_to_pl_authname (hrn):
20 return PlXrn(xrn=hrn,type='any').pl_authname()
21 def xrn_to_hostname(hrn):
22 return Xrn.unescape(PlXrn(xrn=hrn, type='node').get_leaf())
27 def site_hrn (auth, login_base):
28 return '.'.join([auth,login_base])
30 def __init__ (self, auth=None, hostname=None, slicename=None, email=None, interface=None, **kwargs):
31 #def hostname_to_hrn(auth_hrn, login_base, hostname):
32 if hostname is not None:
34 # keep only the first part of the DNS name
35 #self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
36 # escape the '.' in the hostname
37 self.hrn='.'.join( [auth,Xrn.escape(hostname)] )
39 #def slicename_to_hrn(auth_hrn, slicename):
40 elif slicename is not None:
42 # split at the first _
43 parts = slicename.split("_",1)
44 self.hrn = ".".join([auth] + parts )
46 #def email_to_hrn(auth_hrn, email):
47 elif email is not None:
49 # keep only the part before '@' and replace special chars into _
50 self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")])
52 elif interface is not None:
53 self.type = 'interface'
54 self.hrn = auth + '.' + interface
57 Xrn.__init__ (self,**kwargs)
59 #def hrn_to_pl_slicename(hrn):
60 def pl_slicename (self):
63 sliver_id_parts = leaf.split(':')
64 name = sliver_id_parts[0]
65 name = re.sub('[^a-zA-Z0-9_]', '', name)
66 return self.pl_login_base() + '_' + name
68 #def hrn_to_pl_authname(hrn):
69 def pl_authname (self):
71 return self.authority[-1]
73 def interface_name(self):
77 def pl_login_base (self):
79 if self.type and self.type.startswith('authority'):
82 base = self.authority[-1]
84 # Fix up names of GENI Federates
86 base = re.sub('\\\[^a-zA-Z0-9]', '', base)
89 base = base[len(base)-20:]