Beispiel #1
0
 def coerce(self, obj, attr, value):
     try:
         value = hv_type.canonicalize(value)
     except exception.InvalidHypervisorVirtType:
         msg = _("Hypervisor virt type '%s' is not valid") % value
         raise ValueError(msg)
     return super(HVType, self).coerce(obj, attr, value)
 def coerce(self, obj, attr, value):
     try:
         value = hv_type.canonicalize(value)
     except exception.InvalidHypervisorVirtType:
         msg = _("Hypervisor virt type '%s' is not valid") % value
         raise ValueError(msg)
     return super(HVType, self).coerce(obj, attr, value)
    def _instance_supported(self, host_state, image_props,
                            hypervisor_version):
        img_arch = image_props.get('hw_architecture')
        img_h_type = image_props.get('img_hv_type')
        if not img_h_type:
            img_h_type = 'qemu'
        img_vm_mode = image_props.get('hw_vm_mode')
        checked_img_props = (
            arch.canonicalize(img_arch),
            hv_type.canonicalize(img_h_type),
            vm_mode.canonicalize(img_vm_mode)
        )

        # Supported if no compute-related instance properties are specified
        if not any(checked_img_props):
            return True

        supp_instances = host_state.supported_instances
        # Not supported if an instance property is requested but nothing
        # advertised by the host.
        if not supp_instances:
            LOG.debug("Instance contains properties %(image_props)s, "
                        "but no corresponding supported_instances are "
                        "advertised by the compute node",
                      {'image_props': image_props})
            return False

        def _compare_props(props, other_props):
            for i in props:
                if i and i not in other_props:
                    return False
            return True

        def _compare_product_version(hyper_version, image_props):
            version_required = image_props.get('img_hv_requested_version')
            if not(hypervisor_version and version_required):
                return True
            img_prop_predicate = versionpredicate.VersionPredicate(
                'image_prop (%s)' % version_required)
            hyper_ver_str = versionutils.convert_version_to_str(hyper_version)
            return img_prop_predicate.satisfied_by(hyper_ver_str)

        for supp_inst in supp_instances:
            if _compare_props(checked_img_props, supp_inst):
                if _compare_product_version(hypervisor_version, image_props):
                    return True

        LOG.debug("Instance contains properties %(image_props)s "
                    "that are not provided by the compute node "
                    "supported_instances %(supp_instances)s or "
                    "hypervisor version %(hypervisor_version)s do not match",
                  {'image_props': image_props,
                   'supp_instances': supp_instances,
                   'hypervisor_version': hypervisor_version})
        return False
Beispiel #4
0
    def _instance_supported(self, host_state, image_props,
                            hypervisor_version):
        img_arch = image_props.get('hw_architecture')
        img_h_type = image_props.get('img_hv_type')
        img_vm_mode = image_props.get('hw_vm_mode')
        checked_img_props = (
            arch.canonicalize(img_arch),
            hv_type.canonicalize(img_h_type),
            vm_mode.canonicalize(img_vm_mode)
        )

        # Supported if no compute-related instance properties are specified
        if not any(checked_img_props):
            return True

        supp_instances = host_state.supported_instances
        # Not supported if an instance property is requested but nothing
        # advertised by the host.
        if not supp_instances:
            LOG.debug("Instance contains properties %(image_props)s, "
                        "but no corresponding supported_instances are "
                        "advertised by the compute node",
                      {'image_props': image_props})
            return False

        def _compare_props(props, other_props):
            for i in props:
                if i and i not in other_props:
                    return False
            return True

        def _compare_product_version(hyper_version, image_props):
            version_required = image_props.get('img_hv_requested_version')
            if not(hypervisor_version and version_required):
                return True
            img_prop_predicate = versionpredicate.VersionPredicate(
                'image_prop ({0!s})'.format(version_required))
            hyper_ver_str = versionutils.convert_version_to_str(hyper_version)
            return img_prop_predicate.satisfied_by(hyper_ver_str)

        for supp_inst in supp_instances:
            if _compare_props(checked_img_props, supp_inst):
                if _compare_product_version(hypervisor_version, image_props):
                    return True

        LOG.debug("Instance contains properties %(image_props)s "
                    "that are not provided by the compute node "
                    "supported_instances %(supp_instances)s or "
                    "hypervisor version %(hypervisor_version)s do not match",
                  {'image_props': image_props,
                   'supp_instances': supp_instances,
                   'hypervisor_version': hypervisor_version})
        return False
Beispiel #5
0
 def test_canonicalize_xapi(self):
     self.assertEqual(hv_type.XEN, hv_type.canonicalize("xapi"))
Beispiel #6
0
 def test_canonicalize_case(self):
     self.assertEqual(hv_type.QEMU, hv_type.canonicalize("QeMu"))
Beispiel #7
0
 def test_canonicalize_none(self):
     self.assertIsNone(hv_type.canonicalize(None))
Beispiel #8
0
 def test_canonicalize_powervm(self):
     self.assertEqual(hv_type.PHYP, hv_type.canonicalize("POWERVM"))
 def test_canonicalize_xapi(self):
     self.assertEqual(hv_type.XEN, hv_type.canonicalize("xapi"))
 def test_canonicalize_case(self):
     self.assertEqual(hv_type.QEMU, hv_type.canonicalize("QeMu"))
 def test_canonicalize_none(self):
     self.assertIsNone(hv_type.canonicalize(None))
Beispiel #12
0
 def test_canonicalize_powervm(self):
     self.assertEqual(hv_type.PHYP, hv_type.canonicalize("POWERVM"))