Added host CPU MHz to vm_mhz_to_percentage
This commit is contained in:
parent
8ae20e8069
commit
6cdb69b2f1
@ -220,6 +220,7 @@ def execute(config, state):
|
|||||||
log.info('The host is idle')
|
log.info('The host is idle')
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
#TODO: update this with host CPU MHz
|
||||||
host_cpu_utilization = vm_mhz_to_percentage(
|
host_cpu_utilization = vm_mhz_to_percentage(
|
||||||
vm_cpu_mhz,
|
vm_cpu_mhz,
|
||||||
state['physical_cpu_mhz_total'])
|
state['physical_cpu_mhz_total'])
|
||||||
@ -394,11 +395,14 @@ def get_max_ram(vir_connection, uuid):
|
|||||||
|
|
||||||
|
|
||||||
@contract
|
@contract
|
||||||
def vm_mhz_to_percentage(vms, physical_cpu_mhz):
|
def vm_mhz_to_percentage(vm_mhz_history, host_mhz_history, physical_cpu_mhz):
|
||||||
""" Convert VM CPU utilization to the host's CPU utilization.
|
""" Convert VM CPU utilization to the host's CPU utilization.
|
||||||
|
|
||||||
:param vms: A map from VM UUIDs to their CPU utilization in MHz.
|
:param vm_mhz_history: A list of CPU utilization histories of VMs in MHz.
|
||||||
:type vms: dict(str: list(int))
|
:type vm_mhz_history: list(list(int))
|
||||||
|
|
||||||
|
:param host_mhz_history: A history if the CPU usage by the host in MHz.
|
||||||
|
:type host_mhz_history: list(int)
|
||||||
|
|
||||||
:param physical_cpu_mhz: The total frequency of the physical CPU in MHz.
|
:param physical_cpu_mhz: The total frequency of the physical CPU in MHz.
|
||||||
:type physical_cpu_mhz: int
|
:type physical_cpu_mhz: int
|
||||||
@ -406,5 +410,8 @@ def vm_mhz_to_percentage(vms, physical_cpu_mhz):
|
|||||||
:return: The history of the host's CPU utilization in percentages.
|
:return: The history of the host's CPU utilization in percentages.
|
||||||
:rtype: list(float)
|
:rtype: list(float)
|
||||||
"""
|
"""
|
||||||
data = itertools.izip_longest(*vms.values(), fillvalue=0)
|
host_mhz_history = [0] * (len(vm_mhz_history) -
|
||||||
|
len(host_mhz_history)) + host_mhz_history
|
||||||
|
data = itertools.izip_longest(*(vm_mhz_history + [host_mhz_history]),
|
||||||
|
fillvalue=0)
|
||||||
return [float(sum(x)) / physical_cpu_mhz for x in data]
|
return [float(sum(x)) / physical_cpu_mhz for x in data]
|
||||||
|
@ -160,8 +160,17 @@ class LocalManager(TestCase):
|
|||||||
|
|
||||||
def test_vm_mhz_to_percentage(self):
|
def test_vm_mhz_to_percentage(self):
|
||||||
self.assertEqual(manager.vm_mhz_to_percentage(
|
self.assertEqual(manager.vm_mhz_to_percentage(
|
||||||
{'a': [100, 200, 300],
|
[[100, 200, 300],
|
||||||
'b': [100, 300, 200],
|
[100, 300, 200],
|
||||||
'c': [100, 100, 700]},
|
[100, 100, 700]],
|
||||||
|
[300, 0, 300],
|
||||||
3000),
|
3000),
|
||||||
[0.1, 0.2, 0.4])
|
[0.2, 0.2, 0.5])
|
||||||
|
|
||||||
|
self.assertEqual(manager.vm_mhz_to_percentage(
|
||||||
|
[[100, 200, 300],
|
||||||
|
[100, 300, 200],
|
||||||
|
[100, 100, 700]],
|
||||||
|
[0, 300],
|
||||||
|
3000),
|
||||||
|
[0.1, 0.2, 0.5])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user