def __init__ (self, auth=None, hostname=None, slicename=None, email=None, interface=None, **kwargs): #def hostname_to_hrn(auth_hrn, login_base, hostname): if hostname is not None: self.type='node' # keep only the first part of the DNS name #self.hrn='.'.join( [auth,hostname.split(".")[0] ] ) # escape the '.' in the hostname self.hrn='.'.join( [auth,Xrn.escape(hostname)] ) self.hrn_to_urn() #def slicename_to_hrn(auth_hrn, slicename): elif slicename is not None: self.type='slice' # split at the first _ parts = slicename.split("_",1) self.hrn = ".".join([auth] + parts ) self.hrn_to_urn() #def email_to_hrn(auth_hrn, email): elif email is not None: self.type='person' # keep only the part before '@' and replace special chars into _ self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")]) self.hrn_to_urn() elif interface is not None: self.type = 'interface' self.hrn = auth + '.' + interface self.hrn_to_urn() else: Xrn.__init__ (self,**kwargs)
def __init__ (self, auth=None, hostname=None, slicename=None, slivername=None, username=None, **kwargs): if hostname is not None: self.type = 'node' self.hrn = '.'.join( [auth, Xrn.escape(hostname)] ) self.hrn_to_urn() elif slicename is not None: self.type = 'slice' self.hrn = '.'.join([auth, slicename]) self.hrn_to_urn() elif slivername is not None: self.type = 'sliver' # Reformat sliver name xrn_slivername = clab_slivername_to_xrn_slivername(slivername) self.hrn = '.'.join([auth, xrn_slivername]) self.hrn_to_urn() elif username is not None: self.type = 'user' self.hrn = '.'.join([auth, username]) self.hrn_to_urn() else: Xrn.__init__ (self, **kwargs)
def hostname_to_hrn_escaped(root_auth, hostname): """ Returns a node's hrn based on its hostname and the root authority and by removing special caracters from the hostname. :param root_auth: root authority name :param hostname: nodes's hostname :type root_auth: string :type hostname: string :rtype: string """ return '.'.join([root_auth, Xrn.escape(hostname)])
def xrn_object(root_auth, hostname): """Creates a valid xrn object from the node's hostname and the authority of the SFA server. :param hostname: the node's hostname. :param root_auth: the SFA root authority. :type hostname: string :type root_auth: string :returns: the iotlab node's xrn :rtype: Xrn """ return Xrn('.'.join([root_auth, Xrn.escape(hostname)]), type='node')
def leases_to_rspec_leases(self, leases): """ Get leases attributes list""" rspec_leases = [] for lease in leases: for node in lease["resources"]: rspec_lease = Lease() rspec_lease["lease_id"] = lease["id"] iotlab_xrn = Xrn(".".join([self.driver.root_auth, Xrn.escape(node)]), type="node") rspec_lease["component_id"] = iotlab_xrn.urn rspec_lease["start_time"] = str(lease["date"]) duration = int(lease["duration"]) / 60 # duration in minutes rspec_lease["duration"] = duration rspec_lease["slice_id"] = lease["slice_id"] rspec_leases.append(rspec_lease) return rspec_leases
def xrn_object(root_auth, hostname): """ Creates a valid xrn object from the node's hostname and the authority of the SFA server. :param hostname: the node's hostname :type string :param root_auth: the SFA root authority :type string :returns: the C-Lab node's xrn :rtype: Xrn """ escaped_hostname = escape_testbed_obj_names(hostname) return Xrn('.'.join([root_auth, Xrn.escape(escaped_hostname)]), type='node')
def node_to_rspec_node(self, node): """ Get node attributes """ rspec_node = IotlabNode() rspec_node["mobile"] = node["mobile"] rspec_node["archi"] = node["archi"] rspec_node["radio"] = (node["archi"].split(":"))[1] iotlab_xrn = Xrn(".".join([self.driver.root_auth, Xrn.escape(node["network_address"])]), type="node") rspec_node["boot_state"] = "true" rspec_node["component_id"] = iotlab_xrn.urn rspec_node["component_name"] = node["network_address"] rspec_node["component_manager_id"] = hrn_to_urn(self.driver.root_auth, "authority+sa") rspec_node["authority_id"] = rspec_node["component_manager_id"] rspec_node["exclusive"] = "true" rspec_node["hardware_types"] = [HardwareType({"name": "iotlab-node"})] location = IotlabLocation({"country": "France", "site": node["site"]}) rspec_node["location"] = location position = IotlabPosition() for field in position: position[field] = node[field] granularity = Granularity({"grain": 30}) rspec_node["granularity"] = granularity rspec_node["tags"] = [] return rspec_node
def __init__ (self, auth=None, hostname=None, login=None, slicename=None, **kwargs): #def hostname_to_hrn(auth_hrn, login_base, hostname): if hostname is not None: self.type = 'node' # keep only the first part of the DNS name # escape the '.' in the hostname self.hrn = '.'.join( [auth, Xrn.escape(hostname)] ) self.hrn_to_urn() elif login is not None: self.type = 'person' self.hrn = '.'.join([auth, login]) self.hrn_to_urn() #def slicename_to_hrn(auth_hrn, slicename): elif slicename is not None: self.type = 'slice' slicename = '_'.join([login, "slice"]) self.hrn = '.'.join([auth, slicename]) self.hrn_to_urn() # split at the first _ else: Xrn.__init__ (self, **kwargs)
def slab_xrn_object(root_auth, hostname): """Attributes are urn and hrn. Get the hostname using slab_xrn_to_hostname on the urn. """ return Xrn('.'.join( [root_auth, Xrn.escape(hostname)]), type='node')
def hostname_to_hrn_escaped(self, root_auth, hostname): return '.'.join( [root_auth,Xrn.escape(hostname)] )