From: Sandrine Avakian Date: Mon, 29 Jul 2013 15:27:00 +0000 (+0200) Subject: Adding a new field in 'mobile' in Iotlab Rspec type. X-Git-Tag: sfa-2.1-27~39 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=11a928956c2b409aaf8f69d45ae2717e51573a20;p=sfa.git Adding a new field in 'mobile' in Iotlab Rspec type. --- diff --git a/sfa/iotlab/OARrestapi.py b/sfa/iotlab/OARrestapi.py index 18679080..c5e714d2 100644 --- a/sfa/iotlab/OARrestapi.py +++ b/sfa/iotlab/OARrestapi.py @@ -384,11 +384,15 @@ class ParsingResourcesFull(): def AddMobility(self, tuplelist, value): """Add if the node is a mobile node or not to the tuple list. + will also add which kind of mobility it is if the information + is available, supposing the information is formatted as a string + with the 2 information separated by a colon. + :param tuplelist: tuple list on which to add the node's mobility status. The tuplelist is the value associated with the node's id in the OARGETParser's dictionary node_dictlist. - :param value: tells if a node is a mobile node or not. The value is found - in the json. + :param value: tells if a node is a mobile node or not. The value is + found in the json. :type tuplelist: list :type value: integer @@ -396,6 +400,15 @@ class ParsingResourcesFull(): .. seealso:: AddNodeNetworkAddr """ + # future support of mobility type + if ":" in value: + value_list = value.split(':') + if value_list[0] is 0: + tuplelist.append(('mobile', 'False')) + else: + tuplelist.append(('mobile', 'True')) + tuplelist.append(('type', value_list[1])) + if value is 0: tuplelist.append(('mobile', 'False')) else: @@ -416,7 +429,7 @@ class ParsingResourcesFull(): .. seealso:: AddNodeNetworkAddr """ - tuplelist.append(('posx', value )) + tuplelist.append(('posx', value)) diff --git a/sfa/rspecs/elements/versions/iotlabv1Node.py b/sfa/rspecs/elements/versions/iotlabv1Node.py index 50f8e48e..7efd8f69 100644 --- a/sfa/rspecs/elements/versions/iotlabv1Node.py +++ b/sfa/rspecs/elements/versions/iotlabv1Node.py @@ -1,4 +1,8 @@ - +""" +This file describes what the propreties of an iotlab nodes are, if an iotlab +rspec is asked. If additionnal node properties have to be defined and exposed +to the user, it should be done here. +""" from sfa.util.xrn import Xrn from sfa.util.xml import XpathFilter from sfa.rspecs.elements.node import Node @@ -10,21 +14,33 @@ from sfa.rspecs.elements.interface import Interface from sfa.rspecs.elements.versions.iotlabv1Sliver import Iotlabv1Sliver from sfa.util.sfalogging import logger + class IotlabNode(Node): + """ Defines what kind of information is displayed on the first line of + the Rspec describing a node. + """ #First get the fields already defined in the class Node fields = list(Node.fields) #Extend it with iotlab's specific fields - fields.extend (['archi', 'radio', 'mobile','position']) + fields.extend(['archi', 'radio', 'mobile', 'position']) class IotlabPosition(Element): - fields = ['posx', 'posy','posz'] + """ Defines the fields needed to diplay node's coordinates in the RSpec. """ + fields = ['posx', 'posy', 'posz'] + class IotlabLocation(Location): + """ Needed to display the localisation (Country and city) of a node.""" fields = list(Location.fields) - fields.extend (['site']) + fields.extend(['site']) +class IotlabMobility(Element): + """ Class to give information of a node's mobility, and what kind of + mobility it is (train, roomba robot ...) """ + fields = ['mobile', 'type'] + class Iotlabv1Node: @@ -36,7 +52,7 @@ class Iotlabv1Node: should be used after add_nodes, which creates the network item. """ - logger.debug(" add_connection_information " ) + logger.debug(" add_connection_information ") #Get network item in the xml network_elems = xml.xpath('//network') if len(network_elems) > 0: @@ -46,40 +62,52 @@ class Iotlabv1Node: iotlab_network_dict['login'] = ldap_username iotlab_network_dict['ssh'] = \ - ['ssh ' + ldap_username + '@'+site+'.iotlab.info' \ - for site in sites_set] - network_elem.set('ssh', \ - unicode(iotlab_network_dict['ssh'])) - network_elem.set('login', unicode( iotlab_network_dict['login'])) - + ['ssh ' + ldap_username + '@'+site+'.iotlab.info' + for site in sites_set] + network_elem.set('ssh', + unicode(iotlab_network_dict['ssh'])) + network_elem.set('login', unicode(iotlab_network_dict['login'])) @staticmethod def add_nodes(xml, nodes): + """Adds the nodes to the xml. + + Adds the nodes as well as dedicated iotlab fields to the node xml + element. + + :param xml: the xml being constructed. + :type xml: xml + :param nodes: list of node dict + :type nodes: list + :returns: a list of node elements. + :rtype: list + + """ #Add network item in the xml network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] elif len(nodes) > 0 and nodes[0].get('component_manager_id'): network_urn = nodes[0]['component_manager_id'] - network_elem = xml.add_element('network', \ - name = Xrn(network_urn).get_hrn()) + network_elem = xml.add_element('network', + name=Xrn(network_urn).get_hrn()) else: network_elem = xml - logger.debug("iotlabv1Node \t add_nodes nodes %s \r\n "%(nodes[0])) + logger.debug("iotlabv1Node \t add_nodes nodes %s \r\n " % (nodes[0])) node_elems = [] #Then add nodes items to the network item in the xml for node in nodes: #Attach this node to the network element - node_fields = ['component_manager_id', 'component_id', 'exclusive',\ - 'boot_state', 'mobile'] + node_fields = ['component_manager_id', 'component_id', 'exclusive', + 'boot_state', 'mobile'] node_elem = network_elem.add_instance('node', node, node_fields) node_elems.append(node_elem) #Set the attibutes of this node element for attribute in node: # set component name - if attribute is 'component_id': + if attribute is 'component_name': component_name = node['component_name'] node_elem.set('component_name', component_name) @@ -89,35 +117,40 @@ class Iotlabv1Node: if attribute is 'hardware_types': for hardware_type in node.get('hardware_types', []): fields = HardwareType.fields - fields.extend(['archi','radio']) + fields.extend(['archi', 'radio']) node_elem.add_instance('hardware_types', node, fields) + # set mobility + if attribute is 'mobile': + node.elem.add_instance('mobile', node['mobile'], + IotlabMobility.fields) + # set location if attribute is 'location': - node_elem.add_instance('location', node['location'], \ - IotlabLocation.fields) + node_elem.add_instance('location', node['location'], + IotlabLocation.fields) + # add granularity of the reservation system #TODO put the granularity in network instead SA 18/07/12 if attribute is 'granularity' : granularity = node['granularity'] if granularity: - node_elem.add_instance('granularity', \ - granularity, granularity.fields) - + node_elem.add_instance('granularity', + granularity, granularity.fields) # set available element if attribute is 'boot_state': if node.get('boot_state').lower() == 'alive': - available_elem = node_elem.add_element('available', \ - now='true') + available_elem = node_elem.add_element('available', + now='true') else: - available_elem = node_elem.add_element('available', \ - now='false') + available_elem = node_elem.add_element('available', + now='false') #set position if attribute is 'position': - node_elem.add_instance('position', node['position'], \ - IotlabPosition.fields) + node_elem.add_instance('position', node['position'], + IotlabPosition.fields) ## add services #PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers @@ -136,27 +169,65 @@ class Iotlabv1Node: Iotlabv1Sliver.add_slivers(node_elem, slivers) return node_elems - - @staticmethod def get_nodes(xml, filter={}): - xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), \ - XpathFilter.xpath(filter)) + """ + Parsing method called upon receiving a Rspec request in the iotlab + format. (Format is given in the XML header, where 'request' is + specified). + + :returns: call to get_node_objs .a list of nodes with their properties + :rtype: list of dict + + .. note:: doesn't seem to be used outside sfiListNodes if the iotlab + format is specified. + + .. seealso:: get_node_objs + """ + xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), + XpathFilter.xpath(filter)) node_elems = xml.xpath(xpath) return Iotlabv1Node.get_node_objs(node_elems) @staticmethod def get_nodes_with_slivers(xml, sliver_filter={}): + """ + With the nodes found in the Rspec, find the nodes which the user wants + to use, based on the definition of a sliver on a node. Search for those + nodes. + + :param sliver_filter: unused + :returns: call to get_node_objs. A list of nodes where a sliver is + defined with their properties; + :rtype: list of dict + + .. note:: used by CreateSliver. + .. seealso:: get_node_objs + """ xpath = '//node[count(sliver)>0] | \ //default:node[count(default:sliver) > 0]' node_elems = xml.xpath(xpath) logger.debug("SLABV1NODE \tget_nodes_with_slivers \ - node_elems %s"%(node_elems)) + node_elems %s" % (node_elems)) return Iotlabv1Node.get_node_objs(node_elems) @staticmethod def get_node_objs(node_elems): + """ + Get information on the nodes on the xml. Gets the attributes in the + Rspec. + + :param node_elems: xml node elements + :type node_elems: xml xpath return type + + :returns: a list of nodes where a sliver is defined with their + properties + :rtype: list of dict + + .. seealso:: get_nodes_with_slivers, get_nodes + + """ nodes = [] for node_elem in node_elems: node = Node(node_elem.attrib, node_elem) @@ -168,21 +239,21 @@ class Iotlabv1Node: # get hardware types hardware_type_elems = node_elem.xpath('./default:hardware_type | \ ./hardware_type') - node['hardware_types'] = [hw_type.get_instance(HardwareType) \ - for hw_type in hardware_type_elems] + node['hardware_types'] = [hw_type.get_instance(HardwareType) + for hw_type in hardware_type_elems] # get location location_elems = node_elem.xpath('./default:location | ./location') - locations = [location_elem.get_instance(Location) \ - for location_elem in location_elems] + locations = [location_elem.get_instance(Location) + for location_elem in location_elems] if len(locations) > 0: node['location'] = locations[0] # get interfaces iface_elems = node_elem.xpath('./default:interface | ./interface') - node['interfaces'] = [iface_elem.get_instance(Interface) \ - for iface_elem in iface_elems] + node['interfaces'] = [iface_elem.get_instance(Interface) + for iface_elem in iface_elems] # get services #node['services'] = PGv2Services.get_services(node_elem) @@ -198,12 +269,24 @@ class Iotlabv1Node: node['boot_state'] = 'disabled' logger.debug("SLABV1NODE \tget_nodes_objs \ - #nodes %s"%(nodes)) + #nodes %s" % (nodes)) return nodes - @staticmethod def add_slivers(xml, slivers): + """Add the slivers in parameter to the nodes, by modifying the + xml and adding the sliver element in the RSpec. + + :param slivers: list of slivers, which can be either strings or dict. + :type: list + + :returns: None + :rtype: None + + .. seealso:: Iotlabv1Sliver : add_slivers + .. note:: used by sfiAddSliver and add_nodes (in the file) + + """ logger.debug("Iotlabv1NODE \tadd_slivers ") component_ids = [] for sliver in slivers: @@ -223,13 +306,17 @@ class Iotlabv1Node: @staticmethod def remove_slivers(xml, hostnames): + """ + Removes the slivers for the nodes whose hostnames are on the list. + + :param hostnames: list of nodes' hostnames whose sliver have to be + removed. + :type hostnames: list + """ for hostname in hostnames: - nodes = Iotlabv1Node.get_nodes(xml, \ - {'component_id': '*%s*' % hostname}) + nodes = Iotlabv1Node.get_nodes(xml, {'component_id': '*%s*' + % hostname}) for node in nodes: slivers = Iotlabv1Sliver.get_slivers(node.element) for sliver in slivers: node.element.remove(sliver.element) - - -