Exemplo n.º 1
0
    def _instance_supported(self, host_state, image_props,
                            hypervisor_version):
        img_arch = image_props.get('architecture', None)
        img_h_type = image_props.get('hypervisor_type', None)
        img_vm_mode = image_props.get('vm_mode', None)
        img_vm_mode = vm_mode.name(img_vm_mode)  # get canonical name
        checked_img_props = (img_arch, img_h_type, 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('hypervisor_version_requires')
            if not(hypervisor_version and version_required):
                return True
            img_prop_predicate = versionpredicate.VersionPredicate(
                'image_prop (%s)' % version_required)
            hyper_ver_str = utils.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):
                    LOG.debug(_("Instance properties %(image_props)s "
                                "are satisfied by compute host hypervisor "
                                "version %(hypervisor_version)s and "
                                "supported instances %(supp_instances)s"),
                              {'image_props': image_props,
                               'supp_instances': supp_instances,
                               'hypervisor_version': hypervisor_version})
                    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
Exemplo n.º 2
0
    def _instance_supported(self, host_state, image_props, hypervisor_version):
        img_arch = image_props.get('architecture', None)
        img_h_type = image_props.get('hypervisor_type', None)
        img_vm_mode = image_props.get('vm_mode', None)
        checked_img_props = (arch.canonicalize(img_arch),
                             hvtype.canonicalize(img_h_type),
                             vm_mode.name(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('hypervisor_version_requires')
            if not (hypervisor_version and version_required):
                return True
            img_prop_predicate = versionpredicate.VersionPredicate(
                'image_prop (%s)' % version_required)
            hyper_ver_str = utils.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
Exemplo n.º 3
0
 def test_name_none(self):
     mode = vm_mode.name(None)
     self.assertIsNone(mode)
Exemplo n.º 4
0
 def test_name_hvm(self):
     mode = vm_mode.name('hvm')
     self.assertEqual(vm_mode.HVM, mode)
Exemplo n.º 5
0
 def test_name_hv_compat(self):
     mode = vm_mode.name('hv')
     self.assertEqual(vm_mode.HVM, mode)
Exemplo n.º 6
0
 def test_name_pv_compat(self):
     mode = vm_mode.name('pv')
     self.assertEqual(vm_mode.XEN, mode)
Exemplo n.º 7
0
 def test_name_none(self):
     mode = vm_mode.name(None)
     self.assertEqual(None, mode)
Exemplo n.º 8
0
 def test_name_hvm(self):
     mode = vm_mode.name('hvm')
     self.assertEqual(vm_mode.HVM, mode)
Exemplo n.º 9
0
 def test_name_hv_compat(self):
     mode = vm_mode.name('hv')
     self.assertEqual(vm_mode.HVM, mode)
Exemplo n.º 10
0
 def test_name_pv_compat(self):
     mode = vm_mode.name('pv')
     self.assertEqual(vm_mode.XEN, mode)
Exemplo n.º 11
0
 def test_name_none(self):
     mode = vm_mode.name(None)
     self.assertIsNone(mode)