示例#1
0
 def setUpClass(cls):
     cls.spec_xml = \
         """
         <extra_specs>
         <field1>1</field1>
         <field2>2</field2>
         <field3>3</field3>
         </extra_specs>
         """
     cls.flavor_spec = FlavorExtraSpecs.deserialize(cls.spec_xml, 'xml')
示例#2
0
    def _dict_to_obj(cls, flavor_dict):
        spec = 'OS-FLV-WITH-EXT-SPECS:extra_specs'
        extra_specs = (FlavorExtraSpecs._dict_to_obj(flavor_dict.get(spec))
                       if flavor_dict.get(spec) else None)

        flavor = Flavor(
            id=flavor_dict.get('id'), name=flavor_dict.get('name'),
            ram=flavor_dict.get('ram'), disk=flavor_dict.get('disk'),
            vcpus=flavor_dict.get('vcpus'), swap=flavor_dict.get('swap'),
            rxtx_factor=flavor_dict.get('rxtx_factor'),
            ephemeral_disk=flavor_dict.get('OS-FLV-EXT-DATA:ephemeral'),
            links=Links._dict_to_obj(flavor_dict['links']),
            extra_specs=extra_specs)
        return flavor
示例#3
0
    def _xml_ele_to_obj(cls, element):
        flavor_dict = element.attrib

        # XML data types differ from JSON, so we normalize here
        if 'vcpus' in flavor_dict:
            flavor_dict['vcpus'] = (flavor_dict.get('vcpus')
                                    and int(flavor_dict.get('vcpus')))
        if 'disk' in flavor_dict:
            flavor_dict['disk'] = (flavor_dict.get('disk')
                                   and int(flavor_dict.get('disk')))
        if 'rxtx_factor' in flavor_dict:
            flavor_dict['rxtx_factor'] = \
                (flavor_dict.get('rxtx_factor') and
                 float(flavor_dict.get('rxtx_factor')))
        if 'ram' in flavor_dict:
            flavor_dict['ram'] = (flavor_dict.get('ram')
                                  and int(flavor_dict.get('ram')))
        if 'swap' in flavor_dict:
            flavor_dict['swap'] = (flavor_dict.get('swap')
                                   and int(flavor_dict.get('swap')))
        if 'ephemeral' in flavor_dict:
            flavor_dict['ephemeral'] = (flavor_dict.get('ephemeral')
                                        and int(flavor_dict.get('ephemeral')))

        links = Links._xml_ele_to_obj(element)
        specs = element.find('extra_specs')
        extra_specs = (FlavorExtraSpecs._xml_ele_to_obj(specs)
                       if specs is not None else None)
        flavor = Flavor(id=flavor_dict.get('id'),
                        name=flavor_dict.get('name'),
                        ram=flavor_dict.get('ram'),
                        disk=flavor_dict.get('disk'),
                        vcpus=flavor_dict.get('vcpus'),
                        swap=flavor_dict.get('swap'),
                        rxtx_factor=flavor_dict.get('rxtx_factor'),
                        links=links,
                        ephemeral_disk=flavor_dict.get('ephemeral'),
                        extra_specs=extra_specs)
        return flavor
示例#4
0
    def _xml_ele_to_obj(cls, element):
        flavor_dict = element.attrib

        # XML data types differ from JSON, so we normalize here
        if 'vcpus' in flavor_dict:
            flavor_dict['vcpus'] = (flavor_dict.get('vcpus') and
                                    int(flavor_dict.get('vcpus')))
        if 'disk' in flavor_dict:
            flavor_dict['disk'] = (flavor_dict.get('disk') and
                                   int(flavor_dict.get('disk')))
        if 'rxtx_factor' in flavor_dict:
            flavor_dict['rxtx_factor'] = \
                (flavor_dict.get('rxtx_factor') and
                 float(flavor_dict.get('rxtx_factor')))
        if 'ram' in flavor_dict:
            flavor_dict['ram'] = (flavor_dict.get('ram')
                                  and int(flavor_dict.get('ram')))
        if 'swap' in flavor_dict:
            flavor_dict['swap'] = (flavor_dict.get('swap')
                                   and int(flavor_dict.get('swap')))
        if 'ephemeral' in flavor_dict:
            flavor_dict['ephemeral'] = (flavor_dict.get('ephemeral') and
                                        int(flavor_dict.get('ephemeral')))

        links = Links._xml_ele_to_obj(element)
        specs = element.find('extra_specs')
        extra_specs = (FlavorExtraSpecs._xml_ele_to_obj(specs)
                       if specs is not None else None)
        flavor = Flavor(
            id=flavor_dict.get('id'), name=flavor_dict.get('name'),
            ram=flavor_dict.get('ram'), disk=flavor_dict.get('disk'),
            vcpus=flavor_dict.get('vcpus'), swap=flavor_dict.get('swap'),
            rxtx_factor=flavor_dict.get('rxtx_factor'), links=links,
            ephemeral_disk=flavor_dict.get('ephemeral'),
            extra_specs=extra_specs)
        return flavor
示例#5
0
 def setUpClass(cls):
     cls.spec_json = \
         """
         {"extra_specs": {"field1": "1", "field2": "2", "field3": "3"}}
         """
     cls.flavor_spec = FlavorExtraSpecs.deserialize(cls.spec_json, 'json')