VMware: expose max vCPUs and max memory per ESX host

Expose maximum vCPUs and maximum memory from single ESX host in the
vCenter cluster. This will be used for implementing get_inventory() in
the follow up patch.

Partial-Bug: #1462957

Change-Id: I28e19d46a737ac253718c7c66837bd71b064b0b9
This commit is contained in:
Radoslav Gerganov
2017-10-31 11:22:46 +02:00
parent 93bd310b91
commit 0124d57275
4 changed files with 15 additions and 6 deletions

View File

@@ -2383,7 +2383,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
service = self._create_service(disabled=False, host='fake-mini')
mock_service.return_value = service
fake_stats = {'vcpus': 4, 'mem': {'total': '8194', 'free': '2048'}}
fake_stats = {'cpu': {'vcpus': 4},
'mem': {'total': '8194', 'free': '2048'}}
with test.nested(
mock.patch.object(vm_util, 'get_stats_from_cluster',
side_effect=[vexc.VimConnectionException('fake'),

View File

@@ -117,10 +117,12 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
num_hosts = 2
else:
num_hosts = 1
expected_stats = {'vcpus': num_hosts * 16,
expected_stats = {'cpu': {'vcpus': num_hosts * 16,
'max_vcpus_per_host': 16},
'mem': {'total': num_hosts * 4096,
'free': num_hosts * 4096 -
num_hosts * 512}}
num_hosts * 512,
'max_mem_mb_per_host': 4096}}
self.assertEqual(expected_stats, result)
def test_get_stats_from_cluster_hosts_connected_and_active(self):

View File

@@ -84,7 +84,7 @@ class VCState(object):
self._set_host_enabled(False)
return data
data["vcpus"] = stats['vcpus']
data["vcpus"] = stats['cpu']['vcpus']
data["disk_total"] = capacity / units.Gi
data["disk_available"] = freespace / units.Gi
data["disk_used"] = data["disk_total"] - data["disk_available"]

View File

@@ -1159,8 +1159,10 @@ def get_vm_state(session, instance):
def get_stats_from_cluster(session, cluster):
"""Get the aggregate resource stats of a cluster."""
vcpus = 0
max_vcpus_per_host = 0
used_mem_mb = 0
total_mem_mb = 0
max_mem_mb_per_host = 0
# Get the Host and Resource Pool Managed Object Refs
prop_dict = session._call_method(vutil,
"get_object_properties_dict",
@@ -1186,12 +1188,16 @@ def get_stats_from_cluster(session, cluster):
# The overcommitment ratio is factored in by the scheduler
threads = hardware_summary.numCpuThreads
vcpus += threads
max_vcpus_per_host = max(max_vcpus_per_host, threads)
used_mem_mb += stats_summary.overallMemoryUsage
mem_mb = hardware_summary.memorySize // units.Mi
total_mem_mb += mem_mb
stats = {'vcpus': vcpus,
max_mem_mb_per_host = max(max_mem_mb_per_host, mem_mb)
stats = {'cpu': {'vcpus': vcpus,
'max_vcpus_per_host': max_vcpus_per_host},
'mem': {'total': total_mem_mb,
'free': total_mem_mb - used_mem_mb}}
'free': total_mem_mb - used_mem_mb,
'max_mem_mb_per_host': max_mem_mb_per_host}}
return stats