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
8 def hostname_to_hrn(auth, testbed_name, hostname):
9 return DummyXrn(auth=auth + '.' + testbed_name, hostname=hostname).get_hrn()
12 def hostname_to_urn(auth, testbed_name, hostname):
13 return DummyXrn(auth=auth + '.' + testbed_name, hostname=hostname).get_urn()
16 def slicename_to_hrn(auth_hrn, slicename):
17 return DummyXrn(auth=auth_hrn, slicename=slicename).get_hrn()
20 def email_to_hrn(auth_hrn, email):
21 return DummyXrn(auth=auth_hrn, email=email).get_hrn()
24 def hrn_to_dummy_slicename(hrn):
25 return DummyXrn(xrn=hrn, type='slice').dummy_slicename()
28 def hrn_to_dummy_authname(hrn):
29 return DummyXrn(xrn=hrn, type='any').dummy_authname()
32 def xrn_to_hostname(hrn):
33 return Xrn.unescape(PlXrn(xrn=hrn, type='node').get_leaf())
39 def site_hrn(auth, testbed_name):
40 return '.'.join([auth, testbed_name])
42 def __init__(self, auth=None, hostname=None, slicename=None, email=None, interface=None, **kwargs):
43 # def hostname_to_hrn(auth_hrn, login_base, hostname):
44 if hostname is not None:
46 # keep only the first part of the DNS name
47 #self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
48 # escape the '.' in the hostname
49 self.hrn = '.'.join([auth, Xrn.escape(hostname)])
51 # def slicename_to_hrn(auth_hrn, slicename):
52 elif slicename is not None:
54 # split at the first _
55 parts = slicename.split("_", 1)
56 self.hrn = ".".join([auth] + parts)
58 # def email_to_hrn(auth_hrn, email):
59 elif email is not None:
61 # keep only the part before '@' and replace special chars into _
63 [auth, email.split('@')[0].replace(".", "_").replace("+", "_")])
65 elif interface is not None:
66 self.type = 'interface'
67 self.hrn = auth + '.' + interface
70 Xrn.__init__(self, **kwargs)
72 # def hrn_to_pl_slicename(hrn):
73 def dummy_slicename(self):
76 sliver_id_parts = leaf.split(':')
77 name = sliver_id_parts[0]
78 name = re.sub('[^a-zA-Z0-9_]', '', name)
81 # def hrn_to_pl_authname(hrn):
82 def dummy_authname(self):
84 return self.authority[-1]
86 def interface_name(self):
90 def dummy_login_base(self):
92 if self.type and self.type.startswith('authority'):
95 base = self.authority[-1]
97 # Fix up names of GENI Federates
99 base = re.sub('\\\[^a-zA-Z0-9]', '', base)
102 base = base[len(base) - 20:]