Пример #1
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"] = about_info.version
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [('i686', 'vmware', 'hvm'),
                                       ('x86_64', 'vmware', 'hvm')]

        self._stats = data
        return data
Пример #2
0
    def test_get_datastore_ref_and_name(self):
        result = vm_util.get_datastore_ref_and_name(
            fake_session([fake.Datastore()]))

        self.assertEquals(result[1], "fake-ds")
        self.assertEquals(result[2], 1024 * 1024 * 1024 * 1024)
        self.assertEquals(result[3], 1024 * 1024 * 500 * 1024)
Пример #3
0
 def test_get_datastore_ref_and_name_with_regex_error(self):
     # Test with a regex that has no match
     # Checks if code raises DatastoreNotFound with a specific message
     datastore_invalid_regex = re.compile("unknown-ds")
     exp_message = _("Datastore regex %s did not match any datastores") % datastore_invalid_regex.pattern
     fake_objects = fake.FakeRetrieveResult()
     fake_objects.add_object(fake.Datastore("fake-ds0"))
     fake_objects.add_object(fake.Datastore("fake-ds1"))
     # assertRaisesRegExp would have been a good choice instead of
     # try/catch block, but it's available only from Py 2.7.
     try:
         vm_util.get_datastore_ref_and_name(fake_session(fake_objects), None, None, datastore_invalid_regex)
     except exception.DatastoreNotFound as e:
         self.assertEqual(exp_message, e.args[0])
     else:
         self.fail("DatastoreNotFound Exception was not raised with " "message: %s" % exp_message)
Пример #4
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
Пример #5
0
    def test_get_datastore_ref_and_name(self):
        fake_objects = fake.FakeRetrieveResult()
        fake_objects.add_object(fake.Datastore())
        result = vm_util.get_datastore_ref_and_name(fake_session(fake_objects))

        self.assertEqual(result[1], "fake-ds")
        self.assertEqual(result[2], units.Ti)
        self.assertEqual(result[3], 500 * units.Gi)
Пример #6
0
 def test_get_datastore_ref_and_name_with_regex(self):
     # Test with a regex that matches with a datastore
     datastore_valid_regex = re.compile("^openstack.*\d$")
     fake_objects = fake.FakeRetrieveResult()
     fake_objects.add_object(fake.Datastore("openstack-ds0"))
     fake_objects.add_object(fake.Datastore("fake-ds0"))
     fake_objects.add_object(fake.Datastore("fake-ds1"))
     result = vm_util.get_datastore_ref_and_name(fake_session(fake_objects), None, None, datastore_valid_regex)
     self.assertEqual("openstack-ds0", result[1])
Пример #7
0
 def test_get_datastore_ref_and_name_with_list(self):
     # Test with a regex containing whitelist of datastores
     datastore_valid_regex = re.compile("(openstack-ds0|openstack-ds2)")
     fake_objects = fake.FakeRetrieveResult()
     fake_objects.add_object(fake.Datastore("openstack-ds0"))
     fake_objects.add_object(fake.Datastore("openstack-ds1"))
     fake_objects.add_object(fake.Datastore("openstack-ds2"))
     result = vm_util.get_datastore_ref_and_name(fake_session(fake_objects), None, None, datastore_valid_regex)
     self.assertNotEqual("openstack-ds1", result[1])
Пример #8
0
 def test_get_datastore_ref_and_name_with_token(self):
     regex = re.compile("^ds.*\d$")
     fake0 = fake.FakeRetrieveResult()
     fake0.add_object(fake.Datastore("ds0", 10 * units.Gi, 5 * units.Gi))
     fake0.add_object(fake.Datastore("foo", 10 * units.Gi, 9 * units.Gi))
     setattr(fake0, "token", "token-0")
     fake1 = fake.FakeRetrieveResult()
     fake1.add_object(fake.Datastore("ds2", 10 * units.Gi, 8 * units.Gi))
     fake1.add_object(fake.Datastore("ds3", 10 * units.Gi, 1 * units.Gi))
     result = vm_util.get_datastore_ref_and_name(fake_session(fake0, fake1), None, None, regex)
     self.assertEqual("ds2", result[1])
Пример #9
0
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session, self._cluster)
        if host_mor is None:
            return

        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,
                                                    self._cluster)
        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)
        data["disk_available"] = ds[3] / (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"] = 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
Пример #10
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] / units.Gi
        data["disk_available"] = ds[3] / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / units.Mi
        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