X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Felements%2Fversions%2Fiotlabv1Node.py;h=e64368ad0166bf0a68312bb34c17b6a6689224b1;hb=4a9e6751f9f396f463932133b9d62fc925a99ef6;hp=8d3722df42ca5054b0717d0e4b1440d6181cd99a;hpb=abe140800765684e54f1cb39aec52d5c7ebf3d0b;p=sfa.git diff --git a/sfa/rspecs/elements/versions/iotlabv1Node.py b/sfa/rspecs/elements/versions/iotlabv1Node.py index 8d3722df..e64368ad 100644 --- a/sfa/rspecs/elements/versions/iotlabv1Node.py +++ b/sfa/rspecs/elements/versions/iotlabv1Node.py @@ -10,19 +10,21 @@ from sfa.rspecs.elements.interface import Interface from sfa.rspecs.elements.versions.iotlabv1Sliver import Iotlabv1Sliver from sfa.util.sfalogging import logger + class IotlabNode(NodeElement): - #First get the fields already defined in the class Node + # First get the fields already defined in the class Node fields = list(NodeElement.fields) - #Extend it with iotlab's specific fields - fields.extend (['archi', 'radio', 'mobile','position']) + # Extend it with iotlab's specific fields + fields.extend(['archi', 'radio', 'mobile', 'position']) class IotlabPosition(Element): - fields = ['posx', 'posy','posz'] + fields = ['x', 'y', 'z'] + class IotlabLocation(Location): fields = list(Location.fields) - fields.extend (['site']) + fields.extend(['site']) class IotlabMobility(Element): @@ -31,7 +33,6 @@ class IotlabMobility(Element): fields = ['mobile', 'mobility_type'] - class Iotlabv1Node: @staticmethod @@ -42,7 +43,7 @@ class Iotlabv1Node: """ logger.debug(" add_connection_information ") - #Get network item in the xml + # Get network item in the xml network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] @@ -51,14 +52,14 @@ class Iotlabv1Node: iotlab_network_dict['login'] = ldap_username iotlab_network_dict['ssh'] = \ - ['ssh ' + ldap_username + '@'+site+'.iotlab.info' + ['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'])) + str(iotlab_network_dict['ssh'])) + network_elem.set('login', str(iotlab_network_dict['login'])) @staticmethod - def add_nodes(xml, nodes): + def add_nodes(xml, nodes, rspec_content_type=None): """Adds the nodes to the xml. Adds the nodes as well as dedicated iotlab fields to the node xml @@ -72,7 +73,7 @@ class Iotlabv1Node: :rtype: list """ - #Add network item in the xml + # Add network item in the xml network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] @@ -84,23 +85,23 @@ class Iotlabv1Node: network_elem = xml node_elems = [] - #Then add nodes items to the network item in the xml + # Then add nodes items to the network item in the xml for node in nodes: - #Attach this node to the network element + # Attach this node to the network element 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 + # Set the attibutes of this node element for attribute in node: - # set component name + # set component name if attribute is 'component_name': component_name = node['component_name'] node_elem.set('component_name', component_name) # set hardware types, extend fields to add Iotlab's architecture - #and radio type + # and radio type if attribute is 'hardware_types': for hardware_type in node.get('hardware_types', []): @@ -115,10 +116,10 @@ class Iotlabv1Node: # set location if attribute is 'location': node_elem.add_instance('location', node['location'], - IotlabLocation.fields) + IotlabLocation.fields) # add granularity of the reservation system - #TODO put the granularity in network instead SA 18/07/12 + # TODO put the granularity in network instead SA 18/07/12 if attribute is 'granularity': granularity = node['granularity'] if granularity: @@ -134,43 +135,50 @@ class Iotlabv1Node: available_elem = node_elem.add_element('available', now='false') - #set position + # set position if attribute is 'position': node_elem.add_instance('position', node['position'], IotlabPosition.fields) - ## add services + # add services #PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers if attribute is 'slivers': slivers = node.get('slivers', []) if not slivers: - # we must still advertise the available sliver types + # we must still advertise the available sliver types slivers = Sliver({'type': 'iotlab-node'}) # we must also advertise the available initscripts #slivers['tags'] = [] - #if node.get('pl_initscripts'): - #for initscript in node.get('pl_initscripts', []): - #slivers['tags'].append({'name': 'initscript', \ - #'value': initscript['name']}) + # if node.get('pl_initscripts'): + # for initscript in node.get('pl_initscripts', []): + # slivers['tags'].append({'name': 'initscript', \ + #'value': initscript['name']}) Iotlabv1Sliver.add_slivers(node_elem, slivers) + # add sliver tag in Request Rspec + if rspec_content_type == "request": + node_elem.add_instance('sliver', '', []) return node_elems @staticmethod - def get_nodes(xml, filter={}): - xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), \ - XpathFilter.xpath(filter)) + def get_nodes(xml, filter=None): + if filter is None: + filter = {} + 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={}): + def get_nodes_with_slivers(xml, sliver_filter=None): + if sliver_filter is None: + sliver_filter = {} 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 @@ -186,21 +194,20 @@ 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 position position_elems = node_elem.xpath('./default:position | ./position') @@ -222,10 +229,9 @@ 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): logger.debug("Iotlabv1NODE \tadd_slivers ") @@ -248,12 +254,9 @@ class Iotlabv1Node: @staticmethod def remove_slivers(xml, hostnames): 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) - - -