1 from __future__ import print_function
3 # specialized Xrn class for NITOS
5 from sfa.util.xrn import Xrn
7 # temporary helper functions to use this module instead of namespace
10 def hostname_to_hrn(auth, login_base, hostname):
11 return NitosXrn(auth=auth + '.' + login_base, hostname=hostname).get_hrn()
14 def hostname_to_urn(auth, login_base, hostname):
15 return NitosXrn(auth=auth + '.' + login_base, hostname=hostname).get_urn()
18 def slicename_to_hrn(auth_hrn, site_name, slicename):
19 return NitosXrn(auth=auth_hrn + '.' + site_name, slicename=slicename).get_hrn()
20 # hack to convert nitos user name to hrn
23 def username_to_hrn(auth_hrn, site_name, username):
24 return NitosXrn(auth=auth_hrn + '.' + site_name, slicename=username).get_hrn()
27 def email_to_hrn(auth_hrn, email):
28 return NitosXrn(auth=auth_hrn, email=email).get_hrn()
31 def hrn_to_nitos_slicename(hrn):
32 return NitosXrn(xrn=hrn, type='slice').nitos_slicename()
33 # removed-dangerous - was used for non-slice objects
34 # def hrn_to_nitos_login_base (hrn):
35 # return NitosXrn(xrn=hrn,type='slice').nitos_login_base()
38 def hrn_to_nitos_authname(hrn):
39 return NitosXrn(xrn=hrn, type='any').nitos_authname()
42 def xrn_to_hostname(hrn):
43 return Xrn.unescape(NitosXrn(xrn=hrn, type='node').get_leaf())
46 def channel_to_hrn(auth, login_base, channel):
47 return NitosXrn(auth=auth + '.' + login_base, channel=channel).get_hrn()
50 def channel_to_urn(auth, login_base, channel):
51 return NitosXrn(auth=auth + '.' + login_base, channel=channel).get_urn()
54 def xrn_to_channel(hrn):
55 return Xrn.unescape(NitosXrn(xrn=hrn, type='channel').get_leaf())
61 def site_hrn(auth, login_base):
62 return '.'.join([auth, login_base])
64 def __init__(self, auth=None, hostname=None, slicename=None, email=None, interface=None, channel=None, **kwargs):
65 # def hostname_to_hrn(auth_hrn, login_base, hostname):
66 if hostname is not None:
68 # keep only the first part of the DNS name
69 #self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
70 # escape the '.' in the hostname
71 self.hrn = '.'.join([auth, Xrn.escape(hostname)])
73 # def slicename_to_hrn(auth_hrn, slicename):
74 elif slicename is not None:
76 self.hrn = ".".join([auth] + [slicename.replace(".", "_")])
78 # def email_to_hrn(auth_hrn, email):
79 elif email is not None:
81 # keep only the part before '@' and replace special chars into _
83 [auth, email.split('@')[0].replace(".", "_").replace("+", "_")])
85 elif interface is not None:
86 self.type = 'interface'
87 self.hrn = auth + '.' + interface
89 elif channel is not None:
91 self.hrn = ".".join([auth] + [channel])
94 Xrn.__init__(self, **kwargs)
96 # def hrn_to_pl_slicename(hrn):
97 def nitos_slicename(self):
100 sliver_id_parts = leaf.split(':')
101 name = sliver_id_parts[0]
102 name = re.sub('[^a-zA-Z0-9_]', '', name)
103 # return self.nitos_login_base() + '_' + name
106 # def hrn_to_pl_authname(hrn):
107 def nitos_authname(self):
109 return self.authority[-1]
111 def interface_name(self):
115 def nitos_login_base(self):
117 if self.type and self.type.startswith('authority'):
120 base = self.authority[-1]
122 # Fix up names of GENI Federates
124 base = re.sub('\\\[^a-zA-Z0-9]', '', base)
127 base = base[len(base) - 20:]
132 if __name__ == '__main__':
134 #nitosxrn = NitosXrn(auth="omf.nitos",slicename="aminesl")
135 #slice_hrn = nitosxrn.get_hrn()
136 #slice_name = NitosXrn(xrn="omf.nitos.aminesl",type='slice').nitos_slicename()
137 slicename = "giorgos_n"
138 hrn = slicename_to_hrn("pla", "nitos", slicename)