1 # specialized Xrn class for Dummy TB
3 from sfa.util.xrn import Xrn
5 def xrn_to_hostname(xrn):
6 """Returns a node's hostname from its xrn.
7 :param xrn: The nodes xrn identifier.
8 :type xrn: Xrn (from sfa.util.xrn)
10 :returns: node's hostname.
14 return Xrn.unescape(Xrn(xrn=xrn, type='node').get_leaf())
17 def xrn_object(root_auth, hostname):
18 """Creates a valid xrn object from the node's hostname and the authority
21 :param hostname: the node's hostname.
22 :param root_auth: the SFA root authority.
23 :type hostname: string
24 :type root_auth: string
26 :returns: the iotlab node's xrn
30 return Xrn('.'.join([root_auth, Xrn.escape(hostname)]), type='node')
32 # temporary helper functions to use this module instead of namespace
33 def hostname_to_hrn (auth, hostname):
34 return IotlabXrn(auth=auth ,hostname=hostname).get_hrn()
35 def hostname_to_urn(auth, hostname):
36 return IotlabXrn(auth=auth,hostname=hostname).get_urn()
37 def slicename_to_hrn (auth_hrn, slicename):
38 return IotlabXrn(auth=auth_hrn,slicename=slicename).get_hrn()
40 def hrn_to_iotlab_slicename (hrn):
41 return IotlabXrn(xrn=hrn,type='slice').iotlab_slicename()
42 def hrn_to_iotlab_authname (hrn):
43 return IotlabXrn(xrn=hrn,type='any').iotlab_authname()
46 class IotlabXrn (Xrn):
52 def __init__ (self, auth=None, hostname=None, login=None, slicename=None,**kwargs):
53 #def hostname_to_hrn(auth_hrn, login_base, hostname):
54 if hostname is not None:
56 # keep only the first part of the DNS name
57 # escape the '.' in the hostname
58 self.hrn ='.'.join( [auth, Xrn.escape(hostname)] )
61 elif login is not None:
63 self.hrn = '.'.join([auth, login])
65 #def slicename_to_hrn(auth_hrn, slicename):
66 elif slicename is not None:
68 slicename = '_'.join([login, "slice"])
69 self.hrn = '.'.join([auth, slicename])
71 # split at the first _
74 Xrn.__init__ (self,**kwargs)
76 #def hrn_to_pl_slicename(hrn):
77 def iotlab_slicename (self):
80 sliver_id_parts = leaf.split(':')
81 name = sliver_id_parts[0]
82 name = re.sub('[^a-zA-Z0-9_]', '', name)
85 #def hrn_to_pl_authname(hrn):
86 def iotlab_authname (self):
88 return self.authority[-1]
90 def iotlab_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:]