def test_host_used_ram(self): with MockTransaction: hostname = 'hosthost' nova = mock('nova') nova.hosts = mock('hosts') host1 = mock('host1') host1.memory_mb = 4000 host2 = mock('host2') host2.memory_mb = 3000 expect(nova.hosts).get(hostname). \ and_return([host1, host2]).once() assert manager.host_used_ram(nova, hostname) == 3000 with MockTransaction: hostname = 'hosthost' nova = mock('nova') nova.hosts = mock('hosts') host1 = mock('host1') host1.memory_mb = 4000 host2 = mock('host2') host2.memory_mb = 3000 host3 = mock('host3') host3.memory_mb = 3500 expect(nova.hosts).get(hostname). \ and_return([host1, host2, host3]).once() assert manager.host_used_ram(nova, hostname) == 3500
vms_names = sorted(vms_names) vms_cpu_usage = db.select_last_cpu_mhz_for_vms() for vm in vms: if not vm in vms_cpu_usage: vms_cpu_usage[vm] = 0 vms_ram_usage = manager.vms_ram_limit(nova, vms) hosts_cpu_usage_hypervisor = db.select_last_cpu_mhz_for_hosts() hosts_cpu_usage = {} hosts_ram_usage = {} for host, vms in hosts_to_vms.items(): hosts_cpu_usage[host] = hosts_cpu_usage_hypervisor[host] + \ sum(vms_cpu_usage[x] for x in vms) hosts_ram_usage[host] = manager.host_used_ram(nova, host) first = True for host in sorted(hosts_to_vms.keys()): if not first: print "-----------------------------------------------------------" first = False vms = hosts_to_vms[host] print '{0:24} {1:5d} / {2:5d} MHz {3:5d} / {4:5d} MB'. \ format(host, hosts_cpu_usage[host], hosts_cpu_total[host], hosts_ram_usage[host], hosts_ram_total[host]) for vm, uuid in vms_names:
vms_names = sorted(vms_names) vms_cpu_usage = db.select_last_cpu_mhz_for_vms() for vm in vms: if not vm in vms_cpu_usage: vms_cpu_usage[vm] = 0 vms_ram_usage = manager.vms_ram_limit(nova, vms) hosts_cpu_usage_hypervisor = db.select_last_cpu_mhz_for_hosts() hosts_cpu_usage = {} hosts_ram_usage = {} for host, vms in hosts_to_vms.items(): hosts_cpu_usage[host] = hosts_cpu_usage_hypervisor[host] + \ sum(vms_cpu_usage[x] for x in vms) hosts_ram_usage[host] = manager.host_used_ram(nova, host) first = True for host in sorted(hosts_to_vms.keys()): if not first: print "-----------------------------------------------------------" first = False vms = hosts_to_vms[host] print '{0:24} {1:5d} / {2:5d} MHz {3:5d} / {4:5d} MB'. \ format(host, hosts_cpu_usage[host], hosts_cpu_total[host], hosts_ram_usage[host], hosts_ram_total[host]) for vm, uuid in vms_names: if uuid in vms: