Example #1
0
File: host.py Project: EdLeafe/nova
    def has_min_version(self, lv_ver=None, hv_ver=None, hv_type=None):
        conn = self.get_connection()
        try:
            if lv_ver is not None:
                libvirt_version = conn.getLibVersion()

                if CONF.libvirt.version_cap:
                    libvirt_version_cap = utils.convert_version_to_int(
                        utils.convert_version_to_tuple(
                            CONF.libvirt.version_cap))
                    if libvirt_version > libvirt_version_cap:
                        libvirt_version = libvirt_version_cap

                if libvirt_version < utils.convert_version_to_int(lv_ver):
                    return False

            if hv_ver is not None:
                hypervisor_version = conn.getVersion()
                if hypervisor_version < utils.convert_version_to_int(hv_ver):
                    return False

            if hv_type is not None:
                hypervisor_type = conn.getType()
                if hypervisor_type != hv_type:
                    return False

            return True
        except Exception:
            return False
Example #2
0
    def _version_check(self,
                       lv_ver=None,
                       hv_ver=None,
                       hv_type=None,
                       op=operator.lt):
        """Check libvirt version, hypervisor version, and hypervisor type

        :param hv_type: hypervisor driver from the top of this file.
        """
        conn = self.get_connection()
        try:
            if lv_ver is not None:
                libvirt_version = conn.getLibVersion()
                if op(libvirt_version, utils.convert_version_to_int(lv_ver)):
                    return False

            if hv_ver is not None:
                hypervisor_version = conn.getVersion()
                if op(hypervisor_version,
                      utils.convert_version_to_int(hv_ver)):
                    return False

            if hv_type is not None:
                hypervisor_type = conn.getType()
                if hypervisor_type != hv_type:
                    return False

            return True
        except Exception:
            return False
Example #3
0
    def _version_check(self,
                       lv_ver=None,
                       hv_ver=None,
                       hv_type=None,
                       op=operator.lt):
        conn = self.get_connection()
        try:
            if lv_ver is not None:
                libvirt_version = conn.getLibVersion()
                if op(libvirt_version, utils.convert_version_to_int(lv_ver)):
                    return False

            if hv_ver is not None:
                hypervisor_version = conn.getVersion()
                if op(hypervisor_version,
                      utils.convert_version_to_int(hv_ver)):
                    return False

            if hv_type is not None:
                hypervisor_type = conn.getType()
                if hypervisor_type != hv_type:
                    return False

            return True
        except Exception:
            return False
Example #4
0
    def _version_check(self, lv_ver=None, hv_ver=None, hv_type=None,
                       op=operator.lt):
        """Check libvirt version, hypervisor version, and hypervisor type

        :param hv_type: hypervisor driver from the top of this file.
        """
        conn = self.get_connection()
        try:
            if lv_ver is not None:
                libvirt_version = conn.getLibVersion()
                if op(libvirt_version, utils.convert_version_to_int(lv_ver)):
                    return False

            if hv_ver is not None:
                hypervisor_version = conn.getVersion()
                if op(hypervisor_version,
                      utils.convert_version_to_int(hv_ver)):
                    return False

            if hv_type is not None:
                hypervisor_type = conn.getType()
                if hypervisor_type != hv_type:
                    return False

            return True
        except Exception:
            return False
Example #5
0
def _check_ovs_supported_version(session):
    # The port type 'ovs' is only support by the VC version 5.5 onwards
    min_version = utils.convert_version_to_int(
        constants.MIN_VC_OVS_VERSION)
    vc_version = utils.convert_version_to_int(
        vim_util.get_vc_version(session))
    if vc_version < min_version:
        LOG.warning(_LW('VMware vCenter version less than %(version)s '
                        'does not support the \'ovs\' port type.'),
                    {'version': constants.MIN_VC_OVS_VERSION})
Example #6
0
 def _check_min_version(self):
     min_version = utils.convert_version_to_int(constants.MIN_VC_VERSION)
     vc_version = vim_util.get_vc_version(self._session)
     LOG.info(_LI("VMware vCenter version: %s"), vc_version)
     if min_version > utils.convert_version_to_int(vc_version):
         # TODO(garyk): enforce this from M
         LOG.warning(_LW('Running Nova with a VMware vCenter version less '
                         'than %(version)s is deprecated. The required '
                         'minimum version of vCenter will be raised to '
                         '%(version)s in the 13.0.0 release.'),
                     {'version': constants.MIN_VC_VERSION})
Example #7
0
    def test_stat_consumption_from_compute_node_non_pci(self):
        stats = {
            "num_instances": "5",
            "num_proj_12345": "3",
            "num_proj_23456": "1",
            "num_vm_%s" % vm_states.BUILDING: "2",
            "num_vm_%s" % vm_states.SUSPENDED: "1",
            "num_task_%s" % task_states.RESIZE_MIGRATING: "1",
            "num_task_%s" % task_states.MIGRATING: "2",
            "num_os_type_linux": "4",
            "num_os_type_windoze": "1",
            "io_workload": "42",
        }
        stats = jsonutils.dumps(stats)

        hyper_ver_int = utils.convert_version_to_int("6.0.0")
        compute = dict(
            stats=stats,
            memory_mb=0,
            free_disk_gb=0,
            local_gb=0,
            local_gb_used=0,
            free_ram_mb=0,
            vcpus=0,
            vcpus_used=0,
            updated_at=None,
            host_ip="127.0.0.1",
            hypervisor_version=hyper_ver_int,
            numa_topology=None,
        )

        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)
        self.assertIsNone(host.pci_stats)
        self.assertEqual(hyper_ver_int, host.hypervisor_version)
Example #8
0
 def test_image_properties_filter_fails_without_host_props(self):
     img_props = {"properties": {"architecture": arch.X86_64, "hypervisor_type": hvtype.KVM, "vm_mode": vm_mode.HVM}}
     filter_properties = {"request_spec": {"image": img_props}}
     hypervisor_version = utils.convert_version_to_int("6.0.0")
     capabilities = {"enabled": True, "hypervisor_version": hypervisor_version}
     host = fakes.FakeHostState("host1", "node1", capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
Example #9
0
    def get_available_resource(self, nodename):
        """Retrieve resource information.

        This method is called when nova-compute launches, and
        as part of a periodic task that records the results in the DB.

        :param nodename: ignored in this driver
        :returns: dictionary describing resources

        """
        host_stats = self.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats["host_memory_total"] / (1024 * 1024)
        # NOTE(belliott) memory-free-computed is a value provided by XenServer
        # for gauging free memory more conservatively than memory-free.
        free_ram_mb = host_stats["host_memory_free_computed"] / (1024 * 1024)
        total_disk_gb = host_stats["disk_total"] / (1024 * 1024 * 1024)
        used_disk_gb = host_stats["disk_used"] / (1024 * 1024 * 1024)
        hyper_ver = utils.convert_version_to_int(self._session.product_version)
        dic = {
            "vcpus": 0,
            "memory_mb": total_ram_mb,
            "local_gb": total_disk_gb,
            "vcpus_used": 0,
            "memory_mb_used": total_ram_mb - free_ram_mb,
            "local_gb_used": used_disk_gb,
            "hypervisor_type": "xen",
            "hypervisor_version": hyper_ver,
            "hypervisor_hostname": host_stats["host_hostname"],
            "cpu_info": host_stats["host_cpu_info"]["cpu_count"],
            "supported_instances": jsonutils.dumps(host_stats["supported_instances"]),
        }

        return dic
Example #10
0
    def get_available_resource(self, nodename):
        if not hasattr(self, "_nodename"):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(
                _("Hostname has changed from %(old)s to %(new)s. " "A restart is required to take effect.")
                % {"old": self._nodename, "new": nodename}
            )

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            "vcpus": 1,
            "vcpus_used": 0,
            "memory_mb": memory["total"] / units.Mi,
            "memory_mb_used": memory["used"] / units.Mi,
            "local_gb": disk["total"] / units.Gi,
            "local_gb_used": disk["used"] / units.Gi,
            "disk_available_least": disk["available"] / units.Gi,
            "hypervisor_type": "docker",
            "hypervisor_version": utils.convert_version_to_int("1.0"),
            "hypervisor_hostname": self._nodename,
            "cpu_info": "?",
            "supported_instances": jsonutils.dumps([("i686", "docker", "lxc"), ("x86_64", "docker", "lxc")]),
        }
        return stats
Example #11
0
    def update_status(self):
        """Update the current state of the cluster."""
        # Get the datastore in the cluster
        try:
            ds = vm_util.get_datastore_ref_and_name(self._session, self._cluster)
        except exception.DatastoreNotFound:
            ds = (None, None, 0, 0)

        # Get cpu, memory stats from the cluster
        stats = vm_util.get_stats_from_cluster(self._session, self._cluster)
        about_info = self._session._call_method(vim_util, "get_about_info")
        data = {}
        data["vcpus"] = stats["cpu"]["vcpus"]
        data["cpu_info"] = {
            "vendor": stats["cpu"]["vendor"],
            "model": stats["cpu"]["model"],
            "topology": {"cores": stats["cpu"]["cores"], "threads": stats["cpu"]["vcpus"]},
        }
        data["disk_total"] = ds[2] / units.Gi
        data["disk_available"] = ds[3] / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = stats["mem"]["total"]
        data["host_memory_free"] = stats["mem"]["free"]
        data["hypervisor_type"] = about_info.name
        data["hypervisor_version"] = utils.convert_version_to_int(str(about_info.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [("i686", "vmware", "hvm"), ("x86_64", "vmware", "hvm")]

        self._stats = data
        return data
Example #12
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(_('Hostname has changed from %(old)s to %(new)s. '
                        'A restart is required to take effect.'
                        ), {'old': self._nodename,
                            'new': nodename})

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus': hostinfo.get_total_vcpus(),
            'vcpus_used': hostinfo.get_vcpus_used(self.list_instances(True)),
            'memory_mb': memory['total'] / units.Mi,
            'memory_mb_used': memory['used'] / units.Mi,
            'local_gb': disk['total'] / units.Gi,
            'local_gb_used': disk['used'] / units.Gi,
            'disk_available_least': disk['available'] / units.Gi,
            'hypervisor_type': 'docker',
            'hypervisor_version': utils.convert_version_to_int('1.0'),
            'hypervisor_hostname': self._nodename,
            'cpu_info': '?',
            'numa_topology': None,
            'supported_instances': jsonutils.dumps([
                (arch.I686, hv_type.DOCKER, vm_mode.EXE),
                (arch.X86_64, hv_type.DOCKER, vm_mode.EXE)
            ])
        }
        return stats
Example #13
0
 def __init__(self, virtapi, read_only=False):
     super(FakeDriver, self).__init__(virtapi)
     self.instances = {}
     self.host_status_base = {
         'vcpus':
         self.vcpus,
         'memory_mb':
         self.memory_mb,
         'local_gb':
         self.local_gb,
         'vcpus_used':
         0,
         'memory_mb_used':
         0,
         'local_gb_used':
         100000000000,
         'hypervisor_type':
         'fake',
         'hypervisor_version':
         utils.convert_version_to_int('1.0'),
         'hypervisor_hostname':
         CONF.host,
         'cpu_info': {},
         'disk_available_least':
         0,
         'supported_instances':
         jsonutils.dumps([(arch.X86_64, hv_type.FAKE, vm_mode.HVM)]),
         'numa_topology':
         None,
     }
     self._mounts = {}
     self._interfaces = {}
     if not _FAKE_NODES:
         set_nodes([CONF.host])
Example #14
0
    def update_status(self):
        """Update the current state of the cluster."""
        capacity, freespace = _get_ds_capacity_and_freespace(self._session,
                                                             self._cluster)

        # Get cpu, memory stats from the cluster
        stats = vm_util.get_stats_from_cluster(self._session, self._cluster)
        about_info = self._session._call_method(vim_util, "get_about_info")
        data = {}
        data["vcpus"] = stats['cpu']['vcpus']
        data["cpu_info"] = {"vendor": stats['cpu']['vendor'],
                            "model": stats['cpu']['model'],
                            "topology": {"cores": stats['cpu']['cores'],
                                         "threads": stats['cpu']['vcpus']}}
        data["disk_total"] = capacity / units.Gi
        data["disk_available"] = freespace / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = stats['mem']['total']
        data["host_memory_free"] = stats['mem']['free']
        data["hypervisor_type"] = about_info.name
        data["hypervisor_version"] = utils.convert_version_to_int(
                str(about_info.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [
            (arch.I686, hvtype.VMWARE, vm_mode.HVM),
            (arch.X86_64, hvtype.VMWARE, vm_mode.HVM)]

        self._stats = data
        return data
Example #15
0
    def get_available_resource(self, nodename):
        """Retrieve resource information.

        This method is called when nova-compute launches, and
        as part of a periodic task that records the results in the DB.

        :param nodename: ignored in this driver
        :returns: dictionary describing resources

        """
        host_stats = self.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats['host_memory_total'] / unit.Mi
        # NOTE(belliott) memory-free-computed is a value provided by XenServer
        # for gauging free memory more conservatively than memory-free.
        free_ram_mb = host_stats['host_memory_free_computed'] / unit.Mi
        total_disk_gb = host_stats['disk_total'] / unit.Gi
        used_disk_gb = host_stats['disk_used'] / unit.Gi
        hyper_ver = utils.convert_version_to_int(self._session.product_version)
        dic = {'vcpus': 0,
               'memory_mb': total_ram_mb,
               'local_gb': total_disk_gb,
               'vcpus_used': 0,
               'memory_mb_used': total_ram_mb - free_ram_mb,
               'local_gb_used': used_disk_gb,
               'hypervisor_type': 'xen',
               'hypervisor_version': hyper_ver,
               'hypervisor_hostname': host_stats['host_hostname'],
               'cpu_info': host_stats['host_cpu_info']['cpu_count'],
               'supported_instances': jsonutils.dumps(
                   host_stats['supported_instances'])}

        return dic
Example #16
0
    def get_available_resource(self, nodename):
        """Retrieve resource information.

        This method is called when nova-compute launches, and
        as part of a periodic task that records the results in the DB.

        :param nodename: ignored in this driver
        :returns: dictionary describing resources

        """
        host_stats = self.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats['host_memory_total'] / unit.Mi
        # NOTE(belliott) memory-free-computed is a value provided by XenServer
        # for gauging free memory more conservatively than memory-free.
        free_ram_mb = host_stats['host_memory_free_computed'] / unit.Mi
        total_disk_gb = host_stats['disk_total'] / unit.Gi
        used_disk_gb = host_stats['disk_used'] / unit.Gi
        hyper_ver = utils.convert_version_to_int(self._session.product_version)
        dic = {'vcpus': 0,
               'memory_mb': total_ram_mb,
               'local_gb': total_disk_gb,
               'vcpus_used': 0,
               'memory_mb_used': total_ram_mb - free_ram_mb,
               'local_gb_used': used_disk_gb,
               'hypervisor_type': 'xen',
               'hypervisor_version': hyper_ver,
               'hypervisor_hostname': host_stats['host_hostname'],
               'cpu_info': host_stats['host_cpu_info']['cpu_count'],
               'supported_instances': jsonutils.dumps(
                   host_stats['supported_instances'])}

        return dic
Example #17
0
    def test_stat_consumption_from_compute_node_non_pci(self):
        stats = [
            dict(key='num_instances', value='5'),
            dict(key='num_proj_12345', value='3'),
            dict(key='num_proj_23456', value='1'),
            dict(key='num_vm_%s' % vm_states.BUILDING, value='2'),
            dict(key='num_vm_%s' % vm_states.SUSPENDED, value='1'),
            dict(key='num_task_%s' % task_states.RESIZE_MIGRATING, value='1'),
            dict(key='num_task_%s' % task_states.MIGRATING, value='2'),
            dict(key='num_os_type_linux', value='4'),
            dict(key='num_os_type_windoze', value='1'),
            dict(key='io_workload', value='42'),
        ]
        hyper_ver_int = utils.convert_version_to_int('6.0.0')
        compute = dict(stats=stats,
                       memory_mb=0,
                       free_disk_gb=0,
                       local_gb=0,
                       local_gb_used=0,
                       free_ram_mb=0,
                       vcpus=0,
                       vcpus_used=0,
                       updated_at=None,
                       host_ip='127.0.0.1',
                       hypervisor_version=hyper_ver_int)

        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)
        self.assertIsNone(host.pci_stats)
        self.assertEqual(hyper_ver_int, host.hypervisor_version)
Example #18
0
    def test_stat_consumption_from_compute_node_non_pci(self):
        stats = {
            'num_instances': '5',
            'num_proj_12345': '3',
            'num_proj_23456': '1',
            'num_vm_%s' % vm_states.BUILDING: '2',
            'num_vm_%s' % vm_states.SUSPENDED: '1',
            'num_task_%s' % task_states.RESIZE_MIGRATING: '1',
            'num_task_%s' % task_states.MIGRATING: '2',
            'num_os_type_linux': '4',
            'num_os_type_windoze': '1',
            'io_workload': '42',
        }

        hyper_ver_int = utils.convert_version_to_int('6.0.0')
        compute = objects.ComputeNode(
            stats=stats, memory_mb=0, free_disk_gb=0, local_gb=0,
            local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
            disk_available_least=None,
            updated_at=None, host_ip='127.0.0.1',
            hypervisor_type='htype',
            hypervisor_hostname='hostname', cpu_info='cpu_info',
            supported_hv_specs=[],
            hypervisor_version=hyper_ver_int, numa_topology=None,
            pci_device_pools=None, metrics=None,
            cpu_allocation_ratio=16.0, ram_allocation_ratio=1.5)

        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)
        self.assertEqual([], host.pci_stats.pools)
        self.assertEqual(hyper_ver_int, host.hypervisor_version)
Example #19
0
    def get_available_resource(self, nodename):
        """Updates compute manager resource info on ComputeNode table.

           Since we don't have a real hypervisor, pretend we have lots of
           disk and ram.
        """
        if nodename not in _FAKE_NODES:
            return {}

        dic = {
            'vcpus': 1,
            'memory_mb': 8192,
            'local_gb': 1028,
            'vcpus_used': 0,
            'memory_mb_used': 0,
            'local_gb_used': 0,
            'hypervisor_type': 'fake',
            'hypervisor_version': utils.convert_version_to_int('1.0'),
            'hypervisor_hostname': nodename,
            'disk_available_least': 0,
            'cpu_info': '?',
            'supported_instances': jsonutils.dumps([(None, 'fake', None)]),
            'numa_topology': None,
        }
        return dic
Example #20
0
 def test_update_from_compute_node_resets_stashed_numa(self):
     hyper_ver_int = utils.convert_version_to_int('6.0.0')
     compute = objects.ComputeNode(
         memory_mb=0,
         free_disk_gb=0,
         local_gb=0,
         metrics=None,
         local_gb_used=0,
         free_ram_mb=0,
         vcpus=0,
         vcpus_used=0,
         disk_available_least=None,
         updated_at=None,
         host_ip='127.0.0.1',
         hypervisor_type='htype',
         hypervisor_hostname='hostname',
         cpu_info='cpu_info',
         supported_hv_specs=[],
         hypervisor_version=hyper_ver_int,
         numa_topology=fakes.NUMA_TOPOLOGY._to_json(),
         stats=None,
         pci_device_pools=None)
     host = host_manager.HostState("fakehost", "fakenode")
     host.instance_numa_topology = 'fake-instance-topology'
     host.update_from_compute_node(compute)
     self.assertIsNone(host.instance_numa_topology)
Example #21
0
File: host.py Project: PFZheng/nova
    def update_status(self):
        """Update the current state of the cluster."""
        capacity, freespace = _get_ds_capacity_and_freespace(self._session,
                                                             self._cluster)

        # Get cpu, memory stats from the cluster
        stats = vm_util.get_stats_from_cluster(self._session, self._cluster)
        about_info = self._session._call_method(vim_util, "get_about_info")
        data = {}
        data["vcpus"] = stats['cpu']['vcpus']
        data["cpu_info"] = {"vendor": stats['cpu']['vendor'],
                            "model": stats['cpu']['model'],
                            "topology": {"cores": stats['cpu']['cores'],
                                         "threads": stats['cpu']['vcpus']}}
        data["disk_total"] = capacity / units.Gi
        data["disk_available"] = freespace / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = stats['mem']['total']
        data["host_memory_free"] = stats['mem']['free']
        data["hypervisor_type"] = about_info.name
        data["hypervisor_version"] = utils.convert_version_to_int(
                str(about_info.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [('i686', 'vmware', 'hvm'),
                                       ('x86_64', 'vmware', 'hvm')]

        self._stats = data
        return data
Example #22
0
    def update_status(self):
        """Update the current state of the cluster."""
        # Get the datastore in the cluster
        try:
            ds = vm_util.get_datastore_ref_and_name(self._session,
                                                    self._cluster)
        except exception.DatastoreNotFound:
            ds = (None, None, 0, 0)

        # Get cpu, memory stats from the cluster
        stats = vm_util.get_stats_from_cluster(self._session, self._cluster)
        about_info = self._session._call_method(vim_util, "get_about_info")
        data = {}
        data["vcpus"] = stats['cpu']['vcpus']
        data["cpu_info"] = {"vendor": stats['cpu']['vendor'],
                            "model": stats['cpu']['model'],
                            "topology": {"cores": stats['cpu']['cores'],
                                         "threads": stats['cpu']['vcpus']}}
        data["disk_total"] = ds[2] / (1024 * 1024 * 1024)
        data["disk_available"] = ds[3] / (1024 * 1024 * 1024)
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = stats['mem']['total']
        data["host_memory_free"] = stats['mem']['free']
        data["hypervisor_type"] = about_info.name
        data["hypervisor_version"] = utils.convert_version_to_int(
            str(about_info.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [('i686', 'vmware', 'hvm'),
                                       ('x86_64', 'vmware', 'hvm')]

        self._stats = data
        return data
Example #23
0
    def update_status(self):
        """Update the current state of the cluster."""
        capacity, freespace = _get_ds_capacity_and_freespace(self._session,
            self._cluster, self._datastore_regex)

        # Get cpu, memory stats from the cluster
        stats = vm_util.get_stats_from_cluster(self._session, self._cluster)
        about_info = self._session._call_method(vim_util, "get_about_info")
        data = {}
        data["vcpus"] = stats['vcpus']
        data["disk_total"] = capacity / units.Gi
        data["disk_available"] = freespace / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = stats['mem']['total']
        data["host_memory_free"] = stats['mem']['free']
        data["hypervisor_type"] = about_info.name
        data["hypervisor_version"] = utils.convert_version_to_int(
                str(about_info.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [
            (arch.I686, hv_type.VMWARE, vm_mode.HVM),
            (arch.X86_64, hv_type.VMWARE, vm_mode.HVM)]

        self._stats = data
        return data
Example #24
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(_('Hostname has changed from %(old)s to %(new)s. '
                        'A restart is required to take effect.'
                        ) % {'old': self._nodename,
                             'new': nodename})

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus': 1,
            'vcpus_used': 0,
            'memory_mb': memory['total'] / units.Mi,
            'memory_mb_used': memory['used'] / units.Mi,
            'local_gb': disk['total'] / units.Gi,
            'local_gb_used': disk['used'] / units.Gi,
            'disk_available_least': disk['available'] / units.Gi,
            'hypervisor_type': 'docker',
            'hypervisor_version': utils.convert_version_to_int('1.0'),
            'hypervisor_hostname': self._nodename,
            'cpu_info': '?',
            'supported_instances': jsonutils.dumps([
                    ('i686', 'docker', 'lxc'),
                    ('x86_64', 'docker', 'lxc')
                ])
        }
        return stats
Example #25
0
    def test_stat_consumption_from_compute_node_rescue_unshelving(self):
        stats = {
            'num_instances': '5',
            'num_proj_12345': '3',
            'num_proj_23456': '1',
            'num_vm_%s' % vm_states.BUILDING: '2',
            'num_vm_%s' % vm_states.SUSPENDED: '1',
            'num_task_%s' % task_states.UNSHELVING: '1',
            'num_task_%s' % task_states.RESCUING: '2',
            'num_os_type_linux': '4',
            'num_os_type_windoze': '1',
            'io_workload': '42',
        }
        stats = jsonutils.dumps(stats)

        hyper_ver_int = utils.convert_version_to_int('6.0.0')
        compute = dict(stats=stats, memory_mb=0, free_disk_gb=0, local_gb=0,
                       local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
                       updated_at=None, host_ip='127.0.0.1',
                       hypervisor_version=hyper_ver_int, numa_topology=None)

        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)

        self.assertEqual(5, host.num_instances)
        self.assertEqual(42, host.num_io_ops)
        self.assertEqual(10, len(host.stats))

        self.assertIsNone(host.pci_stats)
        self.assertEqual(hyper_ver_int, host.hypervisor_version)
Example #26
0
    def test_resources_consumption_from_compute_node(self):
        metrics = [
            dict(name='res1',
                 value=1.0,
                 source='source1',
                 timestamp=None),
            dict(name='res2',
                 value="string2",
                 source='source2',
                 timestamp=None),
        ]
        hyper_ver_int = utils.convert_version_to_int('6.0.0')
        compute = dict(metrics=jsonutils.dumps(metrics),
                       memory_mb=0, free_disk_gb=0, local_gb=0,
                       local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
                       updated_at=None, host_ip='127.0.0.1',
                       hypervisor_version=hyper_ver_int,
                       numa_topology=fakes.NUMA_TOPOLOGY.to_json())
        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)

        self.assertEqual(len(host.metrics), 2)
        self.assertEqual(set(['res1', 'res2']), set(host.metrics.keys()))
        self.assertEqual(1.0, host.metrics['res1'].value)
        self.assertEqual('source1', host.metrics['res1'].source)
        self.assertEqual('string2', host.metrics['res2'].value)
        self.assertEqual('source2', host.metrics['res2'].source)
        self.assertIsInstance(host.numa_topology, six.string_types)
Example #27
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(_('Hostname has changed from %(old)s to %(new)s. '
                        'A restart is required to take effect.'
                        ), {'old': self._nodename,
                            'new': nodename})

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus': hostinfo.get_total_vcpus(),
            'vcpus_used': hostinfo.get_vcpus_used(self.list_instances(True)),
            'memory_mb': memory['total'] / units.Mi,
            'memory_mb_used': memory['used'] / units.Mi,
            'local_gb': disk['total'] / units.Gi,
            'local_gb_used': disk['used'] / units.Gi,
            'disk_available_least': disk['available'] / units.Gi,
            'hypervisor_type': 'docker',
            'hypervisor_version': utils.convert_version_to_int('1.0'),
            'hypervisor_hostname': self._nodename,
            'cpu_info': '?',
            'supported_instances': jsonutils.dumps([
                (arch.I686, hv_type.DOCKER, vm_mode.EXE),
                (arch.X86_64, hv_type.DOCKER, vm_mode.EXE)
            ])
        }
        return stats
Example #28
0
    def test_stat_consumption_from_compute_node_rescue_unshelving(self):
        stats = {
            'num_instances': '5',
            'num_proj_12345': '3',
            'num_proj_23456': '1',
            'num_vm_%s' % vm_states.BUILDING: '2',
            'num_vm_%s' % vm_states.SUSPENDED: '1',
            'num_task_%s' % task_states.UNSHELVING: '1',
            'num_task_%s' % task_states.RESCUING: '2',
            'num_os_type_linux': '4',
            'num_os_type_windoze': '1',
            'io_workload': '42',
        }

        hyper_ver_int = utils.convert_version_to_int('6.0.0')
        compute = objects.ComputeNode(
            stats=stats, memory_mb=0, free_disk_gb=0, local_gb=0,
            local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
            disk_available_least=None,
            updated_at=None, host_ip='127.0.0.1',
            hypervisor_type='htype',
            hypervisor_hostname='hostname', cpu_info='cpu_info',
            supported_hv_specs=[],
            hypervisor_version=hyper_ver_int, numa_topology=None,
            pci_device_pools=None, metrics=None)

        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)

        self.assertEqual(5, host.num_instances)
        self.assertEqual(42, host.num_io_ops)
        self.assertEqual(10, len(host.stats))

        self.assertIsNone(host.pci_stats)
        self.assertEqual(hyper_ver_int, host.hypervisor_version)
Example #29
0
def parse_version(version):
    try:
        m = VERSION_RE.match(version)
        ver_tup = tuple([int(m.group(n)) for n in ('maj', 'min', 'mic')])
    except AttributeError:
        logging.WARN("bad version: %s" % version)
        ver_tup = (0, 0, 0)
    return utils.convert_version_to_int(ver_tup)
Example #30
0
def parse_version(version):
    try:
        m = VERSION_RE.match(version)
        ver_tup = tuple([int(m.group(n)) for n in ('maj', 'min', 'mic')])
    except AttributeError:
        logging.WARN("bad version: %s" % version)
        ver_tup = (0, 0, 0)
    return utils.convert_version_to_int(ver_tup)
 def test_image_properties_filter_passes_without_inst_props(self):
     filter_properties = {'request_spec': {}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {'supported_instances':
                     [(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
                     'hypervisor_version': hypervisor_version}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #32
0
 def test_image_properties_filter_passes_without_inst_props(self):
     filter_properties = {"request_spec": {}}
     hypervisor_version = utils.convert_version_to_int("6.0.0")
     capabilities = {
         "supported_instances": [(arch.X86_64, hvtype.KVM, vm_mode.HVM)],
         "hypervisor_version": hypervisor_version,
     }
     host = fakes.FakeHostState("host1", "node1", capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_passes_without_inst_props(self):
     filter_properties = {'request_spec': {}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances': [(arch.X86_64, hvtype.KVM, vm_mode.HVM)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #34
0
    def __init__(self, virtapi, read_only=False):
        super(MCT_Driver, self).__init__(virtapi);

        ## Power state is the state we get by calling virt driver on a particu-
        ## lar domain. The hypervisor is always considered the authority on the
        ## status of a particular VM and the power_state in the DB should be vi
        ## ewed as a snapshot of the VMs's state in the (recent) past.It can be
        ## periodically updated,and should also be updated at the end of a task
        ## if the task is supposed to affect power_state.
        ##
        ## NOSTATE   = 0x00
        ## RUNNING   = 0x01
        ## PAUSED    = 0x03
        ## SHUTDOWN  = 0x04 # the VM is powered off
        ## CRASHED   = 0x06
        ## SUSPENDED = 0x07
        ##
        self.returnState = {
            0 : power_state.NOSTATE ,
            1 : power_state.RUNNING ,
            2 : power_state.PAUSED  ,
            3 : power_state.SHUTDOWN,
            6 : power_state.CRASHED ,
            7 : power_state.SUSPENDED
        };

        ## TODO: ver diferenca entre power and task status.

        ## Instance the classe that will be the interface layer between the MCT
        ## drive and MCT_Agent. 
        self.mct = MCT_Action(self.returnState);

        ## Get the machine hostname. It will be the nodename:
        self.__hostname = socket.gethostname();

        ## Fixed resource informations about the "multicloud tournament -- MCT.
        self.__resourcesStatusBase = {
            'hypervisor_type'    : 'mct',
            'hypervisor_version' : utils.convert_version_to_int("0.1"),
            'hypervisor_hostname': self.__hostname,
            'numa_topology'      : None,
            'cpu_info'           : '?'

            #'supported_instances'    : jsonutils.dumps(host_stats['supported_instances']),
            #'pci_passthrough_devices': jsonutils.dumps(host_stats['pci_passthrough_devices']),
        };

        ## Expose the drive (host) capabilities:
        self.capabilities = {
            "has_imagecache"               : False,
            "supports_recreate"            : False,
            "supports_migrate_to_same_host": False,
        };

        ## Create the object that will store the "MCT instances" in execution,
        self.__instances = MCT_Instances();
 def test_image_properties_filter_fails_without_host_props(self):
     img_props = {'properties': {'architecture': arch.X86_64,
                                 'hypervisor_type': hv_type.KVM,
                                 'vm_mode': vm_mode.HVM}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {'enabled': True,
                     'hypervisor_version': hypervisor_version}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
Example #36
0
 def test_image_properties_filter_fails_partial_inst_props(self):
     img_props = {"properties": {"architecture": arch.X86_64, "vm_mode": vm_mode.HVM}}
     filter_properties = {"request_spec": {"image": img_props}}
     hypervisor_version = utils.convert_version_to_int("6.0.0")
     capabilities = {
         "supported_instances": [(arch.X86_64, hvtype.XEN, vm_mode.XEN)],
         "hypervisor_version": hypervisor_version,
     }
     host = fakes.FakeHostState("host1", "node1", capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_xen_hv_type_compat(self):
     # if an old image has 'xapi' for hv_type it should be treated as xen
     img_props = {'properties': {'hypervisor_type': 'xapi'}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {'supported_instances':
                     [(arch.I686, hv_type.XEN, vm_mode.HVM)],
                     'hypervisor_version': hypervisor_version}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_fails_partial_inst_props(self):
     img_props = {'properties': {'architecture': arch.X86_64,
                                 'vm_mode': vm_mode.HVM}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {'supported_instances':
                     [(arch.X86_64, hv_type.XEN, vm_mode.XEN)],
                     'hypervisor_version': hypervisor_version}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
Example #39
0
    def get_available_resource(self, nodename):
        """Retrieve resource information.

        This method is called when nova-compute launches, and
        as part of a periodic task that records the results in the DB.

        :param nodename: ignored in this driver
        :returns: dictionary describing resources

        """
        host_stats = self.host_state.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats['host_memory_total'] / units.Mi
        # NOTE(belliott) memory-free-computed is a value provided by XenServer
        # for gauging free memory more conservatively than memory-free.
        free_ram_mb = host_stats['host_memory_free_computed'] / units.Mi
        total_disk_gb = host_stats['disk_total'] / units.Gi
        used_disk_gb = host_stats['disk_used'] / units.Gi
        allocated_disk_gb = host_stats['disk_allocated'] / units.Gi
        hyper_ver = utils.convert_version_to_int(self._session.product_version)
        dic = {
            'vcpus':
            host_stats['host_cpu_info']['cpu_count'],
            'memory_mb':
            total_ram_mb,
            'local_gb':
            total_disk_gb,
            'vcpus_used':
            host_stats['vcpus_used'],
            'memory_mb_used':
            total_ram_mb - free_ram_mb,
            'local_gb_used':
            used_disk_gb,
            'hypervisor_type':
            'xen',
            'hypervisor_version':
            hyper_ver,
            'hypervisor_hostname':
            host_stats['host_hostname'],
            # Todo(bobba) cpu_info may be in a format not supported by
            # arch_filter.py - see libvirt/driver.py get_cpu_info
            'cpu_info':
            jsonutils.dumps(host_stats['host_cpu_info']),
            'disk_available_least':
            total_disk_gb - allocated_disk_gb,
            'supported_instances':
            jsonutils.dumps(host_stats['supported_instances']),
            'pci_passthrough_devices':
            jsonutils.dumps(host_stats['pci_passthrough_devices']),
            'numa_topology':
            None
        }

        return dic
 def test_image_properties_filter_xen_hvtype_compat(self):
     # if an old image has 'xapi' for hvtype it should be treated as xen
     img_props = {'properties': {'hypervisor_type': 'xapi'}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances': [(arch.I686, hvtype.XEN, vm_mode.HVM)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #41
0
 def fake_get_compute(context, host):
     service = dict(
         host=host,
         binary='nova-compute',
         topic='compute',
         report_count=1,
         updated_at='foo',
         hypervisor_type='bar',
         hypervisor_version=utils.convert_version_to_int('1.0'),
         disabled=False)
     return {'compute_node': [service]}
 def test_image_properties_filter_baremetal_vmmode_compat(self):
     # if an old image has 'baremetal' for vmmode it should be
     # treated as hvm
     img_props = {'properties': {'vm_mode': 'baremetal'}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {'supported_instances':
                     [(arch.I686, hv_type.BAREMETAL, vm_mode.HVM)],
                     'hypervisor_version': hypervisor_version}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #43
0
 def fake_get_compute(context, host):
     service = dict(host=host,
                    binary='nova-compute',
                    topic='compute',
                    report_count=1,
                    updated_at='foo',
                    hypervisor_type='bar',
                    hypervisor_version=utils.convert_version_to_int(
                        '1.0'),
                    disabled=False)
     return {'compute_node': [service]}
Example #44
0
 def test_image_properties_filter_xen_hvtype_compat(self):
     # if an old image has 'xapi' for hvtype it should be treated as xen
     img_props = {"properties": {"hypervisor_type": "xapi"}}
     filter_properties = {"request_spec": {"image": img_props}}
     hypervisor_version = utils.convert_version_to_int("6.0.0")
     capabilities = {
         "supported_instances": [(arch.I686, hvtype.XEN, vm_mode.HVM)],
         "hypervisor_version": hypervisor_version,
     }
     host = fakes.FakeHostState("host1", "node1", capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #45
0
 def test_image_properties_filter_baremetal_vmmode_compat(self):
     # if an old image has 'baremetal' for vmmode it should be
     # treated as hvm
     img_props = {"properties": {"vm_mode": "baremetal"}}
     filter_properties = {"request_spec": {"image": img_props}}
     hypervisor_version = utils.convert_version_to_int("6.0.0")
     capabilities = {
         "supported_instances": [(arch.I686, hvtype.BAREMETAL, vm_mode.HVM)],
         "hypervisor_version": hypervisor_version,
     }
     host = fakes.FakeHostState("host1", "node1", capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
    def test_stat_consumption_from_compute_node(self):
        stats = {
            'num_instances': '5',
            'num_proj_12345': '3',
            'num_proj_23456': '1',
            'num_vm_%s' % vm_states.BUILDING: '2',
            'num_vm_%s' % vm_states.SUSPENDED: '1',
            'num_task_%s' % task_states.RESIZE_MIGRATING: '1',
            'num_task_%s' % task_states.MIGRATING: '2',
            'num_os_type_linux': '4',
            'num_os_type_windoze': '1',
            'io_workload': '42',
        }
        stats = jsonutils.dumps(stats)

        hyper_ver_int = utils.convert_version_to_int('6.0.0')
        compute = dict(stats=stats,
                       memory_mb=1,
                       free_disk_gb=0,
                       local_gb=0,
                       local_gb_used=0,
                       free_ram_mb=0,
                       vcpus=0,
                       vcpus_used=0,
                       updated_at=None,
                       host_ip='127.0.0.1',
                       hypervisor_type='htype',
                       hypervisor_hostname='hostname',
                       cpu_info='cpu_info',
                       supported_instances='{}',
                       hypervisor_version=hyper_ver_int)

        host = host_manager.HostState("fakehost", "fakenode")
        host.update_from_compute_node(compute)

        self.assertEqual(5, host.num_instances)
        self.assertEqual(3, host.num_instances_by_project['12345'])
        self.assertEqual(1, host.num_instances_by_project['23456'])
        self.assertEqual(2, host.vm_states[vm_states.BUILDING])
        self.assertEqual(1, host.vm_states[vm_states.SUSPENDED])
        self.assertEqual(1, host.task_states[task_states.RESIZE_MIGRATING])
        self.assertEqual(2, host.task_states[task_states.MIGRATING])
        self.assertEqual(4, host.num_instances_by_os_type['linux'])
        self.assertEqual(1, host.num_instances_by_os_type['windoze'])
        self.assertEqual(42, host.num_io_ops)
        self.assertEqual(10, len(host.stats))

        self.assertEqual('127.0.0.1', host.host_ip)
        self.assertEqual('htype', host.hypervisor_type)
        self.assertEqual('hostname', host.hypervisor_hostname)
        self.assertEqual('cpu_info', host.cpu_info)
        self.assertEqual({}, host.supported_instances)
        self.assertEqual(hyper_ver_int, host.hypervisor_version)
 def test_image_properties_filter_baremetal_vmmode_compat(self):
     # if an old image has 'baremetal' for vmmode it should be
     # treated as hvm
     img_props = {'properties': {'vm_mode': 'baremetal'}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances':
         [(arch.I686, hvtype.BAREMETAL, vm_mode.HVM)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #48
0
    def has_min_version(self, lv_ver=None, hv_ver=None, hv_type=None):
        conn = self.get_connection()
        try:
            if lv_ver is not None:
                libvirt_version = conn.getLibVersion()

                if libvirt_version < utils.convert_version_to_int(lv_ver):
                    return False

            if hv_ver is not None:
                hypervisor_version = conn.getVersion()
                if hypervisor_version < utils.convert_version_to_int(hv_ver):
                    return False

            if hv_type is not None:
                hypervisor_type = conn.getType()
                if hypervisor_type != hv_type:
                    return False

            return True
        except Exception:
            return False
 def test_image_properties_filter_fails_partial_inst_props(self):
     img_props = {
         'properties': {
             'architecture': arch.X86_64,
             'vm_mode': vm_mode.HVM
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances': [(arch.X86_64, hvtype.XEN, vm_mode.XEN)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_fails_without_host_props(self):
     img_props = {
         'properties': {
             'architecture': arch.X86_64,
             'hypervisor_type': hvtype.KVM,
             'vm_mode': vm_mode.HVM
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'enabled': True,
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_passes_same_inst_props_and_version(self):
     img_props = {
         'properties': {
             '_architecture': arch.X86_64,
             'hypervisor_type': hvtype.KVM,
             'vm_mode': vm_mode.HVM,
             'hypervisor_version_requires': '>=6.0,<6.2'
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances': [(arch.X86_64, hvtype.KVM, vm_mode.HVM)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #52
0
 def __init__(self, virtapi, read_only=False):
     super(FakeDriver, self).__init__(virtapi)
     self.instances = {}
     self.resources = Resources(vcpus=self.vcpus,
                                memory_mb=self.memory_mb,
                                local_gb=self.local_gb)
     self.host_status_base = {
         'hypervisor_type': 'fake',
         'hypervisor_version': utils.convert_version_to_int('1.0'),
         'hypervisor_hostname': CONF.host,
         'cpu_info': {},
         'disk_available_least': 0,
         'supported_instances': jsonutils.dumps([(None, 'fake', None)]),
         'numa_topology': None,
     }
     self._mounts = {}
     self._interfaces = {}
     if not _FAKE_NODES:
         set_nodes([CONF.host])
Example #53
0
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session)
        summary = self._session._call_method(vim_util,
                                             "get_dynamic_property",
                                             host_mor,
                                             "HostSystem",
                                             "summary")

        if summary is None:
            return

        try:
            ds = vm_util.get_datastore_ref_and_name(self._session)
        except exception.DatastoreNotFound:
            ds = (None, None, 0, 0)

        data = {}
        data["vcpus"] = summary.hardware.numCpuThreads
        data["cpu_info"] = \
                {"vendor": summary.hardware.vendor,
                 "model": summary.hardware.cpuModel,
                 "topology": {"cores": summary.hardware.numCpuCores,
                              "sockets": summary.hardware.numCpuPkgs,
                              "threads": summary.hardware.numCpuThreads}
                }
        data["disk_total"] = ds[2] / (1024 * 1024 * 1024)
        data["disk_available"] = ds[3] / (1024 * 1024 * 1024)
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / (1024 * 1024)
        data["host_memory_free"] = data["host_memory_total"] - \
                                   summary.quickStats.overallMemoryUsage
        data["hypervisor_type"] = summary.config.product.name
        data["hypervisor_version"] = utils.convert_version_to_int(
            str(summary.config.product.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [('i686', 'vmware', 'hvm'),
                                       ('x86_64', 'vmware', 'hvm')]

        self._stats = data
        return data
Example #54
0
 def __init__(self, virtapi, read_only=False):
     super(FakeDriver, self).__init__(virtapi)
     self.instances = {}
     self.host_status_base = {
         'vcpus': 100000,
         'memory_mb': 8000000000,
         'local_gb': 600000000000,
         'vcpus_used': 0,
         'memory_mb_used': 0,
         'local_gb_used': 100000000000,
         'hypervisor_type': 'fake',
         'hypervisor_version': utils.convert_version_to_int('1.0'),
         'hypervisor_hostname': CONF.host,
         'cpu_info': {},
         'disk_available_least': 500000000000,
     }
     self._mounts = {}
     self._interfaces = {}
     if not _FAKE_NODES:
         set_nodes([CONF.host])
    def update_status(self):
        """Update the current state of the cluster."""
        capacity, freespace = _get_ds_capacity_and_freespace(self._session,
            self._cluster, self._datastore_regex)

        # Get cpu, memory stats from the cluster
        # PF9: using our get_stats_from_cluster_pf9 since the OpenStack function
        # get_stats_from_cluster function does not return all the required
        # information
        stats = vm_util.get_stats_from_cluster_pf9(self._session, self._cluster)
        about_info = self._session._call_method(vim_util, "get_about_info")
        data = {}
        # PF9 changes: In Liberty the vendor, model, topology and clock_rate
        # information was dropped since it does not mean much when a single
        # vCenter cluster is managing multiple ESX hosts. PF9 still needs this
        # information in UI hence reverting to Atherton code for this part.
        # Relevant changes made in vm_util.py
        data["vcpus"] = stats['cpu']['vcpus']
        data["cpu_info"] = {"vendor": stats['cpu']['vendor'],
                            "model": stats['cpu']['model'],
                            "topology": {"cores": stats['cpu']['cores'],
                                         "sockets": stats['cpu']['sockets'],
                                         "threads": stats['cpu']['vcpus']},
                            "clock_rate": stats['cpu']['clock_rate']
                            }
        data["disk_total"] = capacity / units.Gi
        data["disk_available"] = freespace / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = stats['mem']['total']
        data["host_memory_free"] = stats['mem']['free']
        data["hypervisor_type"] = about_info.name
        data["hypervisor_version"] = utils.convert_version_to_int(
                str(about_info.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [
            (arch.I686, hv_type.VMWARE, vm_mode.HVM),
            (arch.X86_64, hv_type.VMWARE, vm_mode.HVM)]

        self._stats = data
        return data