1 # specialized Xrn class for Dummy TB
3 from sfa.util.xrn import Xrn
5 # temporary helper functions to use this module instead of namespace
6 def hostname_to_hrn (auth, testbed_name, hostname):
7 return DummyXrn(auth=auth+'.'+testbed_name,hostname=hostname).get_hrn()
8 def hostname_to_urn(auth, testbed_name, hostname):
9 return DummyXrn(auth=auth+'.'+testbed_name,hostname=hostname).get_urn()
10 def slicename_to_hrn (auth_hrn, slicename):
11 return DummyXrn(auth=auth_hrn,slicename=slicename).get_hrn()
12 def email_to_hrn (auth_hrn, email):
13 return DummyXrn(auth=auth_hrn, email=email).get_hrn()
14 def hrn_to_dummy_slicename (hrn):
15 return DummyXrn(xrn=hrn,type='slice').dummy_slicename()
16 def hrn_to_dummy_authname (hrn):
17 return DummyXrn(xrn=hrn,type='any').dummy_authname()
18 def xrn_to_hostname(hrn):
19 return Xrn.unescape(PlXrn(xrn=hrn, type='node').get_leaf())
24 def site_hrn (auth, testbed_name):
25 return '.'.join([auth,testbed_name])
27 def __init__ (self, auth=None, hostname=None, slicename=None, email=None, interface=None, **kwargs):
28 #def hostname_to_hrn(auth_hrn, login_base, hostname):
29 if hostname is not None:
31 # keep only the first part of the DNS name
32 #self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
33 # escape the '.' in the hostname
34 self.hrn='.'.join( [auth,Xrn.escape(hostname)] )
36 #def slicename_to_hrn(auth_hrn, slicename):
37 elif slicename is not None:
39 # split at the first _
40 parts = slicename.split("_",1)
41 self.hrn = ".".join([auth] + parts )
43 #def email_to_hrn(auth_hrn, email):
44 elif email is not None:
46 # keep only the part before '@' and replace special chars into _
47 self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")])
49 elif interface is not None:
50 self.type = 'interface'
51 self.hrn = auth + '.' + interface
54 Xrn.__init__ (self,**kwargs)
56 #def hrn_to_pl_slicename(hrn):
57 def dummy_slicename (self):
60 sliver_id_parts = leaf.split(':')
61 name = sliver_id_parts[0]
62 name = re.sub('[^a-zA-Z0-9_]', '', name)
65 #def hrn_to_pl_authname(hrn):
66 def dummy_authname (self):
68 return self.authority[-1]
70 def interface_name(self):
74 def dummy_login_base (self):
76 if self.type and self.type.startswith('authority'):
79 base = self.authority[-1]
81 # Fix up names of GENI Federates
83 base = re.sub('\\\[^a-zA-Z0-9]', '', base)
86 base = base[len(base)-20:]