X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Fsfa_rspec_converter.py;h=7bcc7878aa777fed97b9c101770b8c7412fea6a3;hb=49b6134c3730f408a5b66eb7a1b6fa20cb36ebab;hp=77bdc3cbda020791b235a4a244bbceebb8b436ea;hpb=2516940970996337dcd10110b64f3ec572301f1e;p=sfa.git diff --git a/sfa/rspecs/sfa_rspec_converter.py b/sfa/rspecs/sfa_rspec_converter.py index 77bdc3cb..7bcc7878 100755 --- a/sfa/rspecs/sfa_rspec_converter.py +++ b/sfa/rspecs/sfa_rspec_converter.py @@ -1,8 +1,6 @@ #!/usr/bin/python -from lxml import etree -from StringIO import StringIO -from sfa.util.xrn import * +from sfa.util.xrn import hrn_to_urn from sfa.rspecs.rspec import RSpec from sfa.rspecs.version_manager import VersionManager @@ -34,38 +32,51 @@ class SfaRSpecConverter: # create node element node_attrs = {} node_attrs['exclusive'] = 'false' - node_attrs['component_manager_id'] = network - if sfa_node_element.find('hostname') != None: - node_attrs['component_name'] = sfa_node_element.find('hostname').text - if sfa_node_element.find('urn') != None: - node_attrs['component_id'] = sfa_node_element.find('urn').text - node_element = pg_rspec.xml.add_element('node', node_attrs) + if 'component_manager_id' in sfa_node_element.attrib: + node_attrs['component_manager_id'] = sfa_node_element.attrib['component_manager_id'] + else: + node_attrs['component_manager_id'] = hrn_to_urn(network, 'authority+cm') - # create node_type element - for hw_type in ['plab-pc', 'pc']: - hdware_type_element = pg_rspec.xml.add_element('hardware_type', {'name': hw_type}, parent=node_element) - # create available element - pg_rspec.xml.add_element('available', {'now': 'true'}, parent=node_element) - # create locaiton element - # We don't actually associate nodes with a country. - # Set country to "unknown" until we figure out how to make - # sure this value is always accurate. - location = sfa_node_element.find('location') - if location != None: - location_attrs = {} - location_attrs['country'] = location.get('country', 'unknown') - location_attrs['latitude'] = location.get('latitiue', 'None') - location_attrs['longitude'] = location.get('longitude', 'None') - pg_rspec.xml.add_element('location', location_attrs, parent=node_element) + if 'component_id' in sfa_node_element.attrib: + node_attrs['compoenent_id'] = sfa_node_element.attrib['component_id'] - sliver_element = sfa_node_element.find('sliver') - if sliver_element != None: - if content_type == 'request': - # remove all child elements - for child in sfa_node_element.iterchildren(): - sfa_node_element.remove(child) - # add the sliver - pg_rspec.xml.add_element('sliver_type', {'name': 'planetlab-vnode'}, parent=node_element) + if sfa_node_element.find('hostname') != None: + hostname = sfa_node_element.find('hostname').text + node_attrs['component_name'] = hostname + node_attrs['client_id'] = hostname + node_element = pg_rspec.xml.add_element('node', node_attrs) + + if content_type == 'request': + sliver_element = sfa_node_element.find('sliver') + sliver_type_elements = sfa_node_element.xpath('./sliver_type', namespaces=sfa_rspec.namespaces) + available_sliver_types = [element.attrib['name'] for element in sliver_type_elements] + valid_sliver_types = ['emulab-openvz', 'raw-pc'] + + # determine sliver type + requested_sliver_type = 'emulab-openvz' + for available_sliver_type in available_sliver_types: + if available_sliver_type in valid_sliver_types: + requested_sliver_type = available_sliver_type + + if sliver_element != None: + pg_rspec.xml.add_element('sliver_type', {'name': requested_sliver_type}, parent=node_element) + else: + # create node_type element + for hw_type in ['plab-pc', 'pc']: + hdware_type_element = pg_rspec.xml.add_element('hardware_type', {'name': hw_type}, parent=node_element) + # create available element + pg_rspec.xml.add_element('available', {'now': 'true'}, parent=node_element) + # create locaiton element + # We don't actually associate nodes with a country. + # Set country to "unknown" until we figure out how to make + # sure this value is always accurate. + location = sfa_node_element.find('location') + if location != None: + location_attrs = {} + location_attrs['country'] = location.get('country', 'unknown') + location_attrs['latitude'] = location.get('latitude', 'None') + location_attrs['longitude'] = location.get('longitude', 'None') + pg_rspec.xml.add_element('location', location_attrs, parent=node_element) return pg_rspec.toxml()