Replaced "if key in dict: del dict[key]" with "dict.pop(key, None)"

This commit is contained in:
Anton Beloglazov 2015-03-31 15:30:59 +11:00
parent 6f2524f089
commit 8fd1b1e684

View File

@ -335,12 +335,10 @@ def execute_underload(config, state, host):
if vm not in vms_last_cpu: if vm not in vms_last_cpu:
log.info('No data yet for VM: %s - skipping host %s', vm, host) log.info('No data yet for VM: %s - skipping host %s', vm, host)
hosts_to_keep_active.add(host) hosts_to_keep_active.add(host)
del hosts_cpu_total[host] hosts_cpu_total.pop(host, None)
del hosts_ram_total[host] hosts_ram_total.pop(host, None)
if host in hosts_cpu_usage: hosts_cpu_usage.pop(host, None)
del hosts_cpu_usage[host] hosts_ram_usage.pop(host, None)
if host in hosts_ram_usage:
del hosts_ram_usage[host]
break break
host_cpu_mhz += vms_last_cpu[vm] host_cpu_mhz += vms_last_cpu[vm]
else: else:
@ -348,22 +346,18 @@ def execute_underload(config, state, host):
hosts_ram_usage[host] = host_used_ram(state['nova'], host) hosts_ram_usage[host] = host_used_ram(state['nova'], host)
else: else:
# Exclude inactive hosts # Exclude inactive hosts
del hosts_cpu_total[host] hosts_cpu_total.pop(host, None)
del hosts_ram_total[host] hosts_ram_total.pop(host, None)
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.debug('Host CPU usage: %s', str(hosts_last_cpu)) log.debug('Host CPU usage: %s', str(hosts_last_cpu))
log.debug('Host total CPU usage: %s', str(hosts_cpu_usage)) log.debug('Host total CPU usage: %s', str(hosts_cpu_usage))
# Exclude the underloaded host # Exclude the underloaded host
if underloaded_host in hosts_cpu_usage: hosts_cpu_usage.pop(underloaded_host, None)
del hosts_cpu_usage[underloaded_host] hosts_cpu_total.pop(underloaded_host, None)
if underloaded_host in hosts_cpu_total: hosts_ram_usage.pop(underloaded_host, None)
del hosts_cpu_total[underloaded_host] hosts_ram_total.pop(underloaded_host, None)
if underloaded_host in hosts_ram_usage:
del hosts_ram_usage[underloaded_host]
if underloaded_host in hosts_ram_total:
del hosts_ram_total[underloaded_host]
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.debug('Excluded the underloaded host %s', underloaded_host) log.debug('Excluded the underloaded host %s', underloaded_host)
@ -506,12 +500,10 @@ def execute_overload(config, state, host, vm_uuids):
for vm in vms: for vm in vms:
if vm not in vms_last_cpu: if vm not in vms_last_cpu:
log.info('No data yet for VM: %s - skipping host %s', vm, host) log.info('No data yet for VM: %s - skipping host %s', vm, host)
del hosts_cpu_total[host] hosts_cpu_total.pop(host, None)
del hosts_ram_total[host] hosts_ram_total.pop(host, None)
if host in hosts_cpu_usage: hosts_cpu_usage.pop(host, None)
del hosts_cpu_usage[host] hosts_ram_usage.pop(host, None)
if host in hosts_ram_usage:
del hosts_ram_usage[host]
break break
host_cpu_mhz += vms_last_cpu[vm] host_cpu_mhz += vms_last_cpu[vm]
else: else:
@ -520,18 +512,14 @@ def execute_overload(config, state, host, vm_uuids):
else: else:
inactive_hosts_cpu[host] = hosts_cpu_total[host] inactive_hosts_cpu[host] = hosts_cpu_total[host]
inactive_hosts_ram[host] = hosts_ram_total[host] inactive_hosts_ram[host] = hosts_ram_total[host]
del hosts_cpu_total[host] hosts_cpu_total.pop(host, None)
del hosts_ram_total[host] hosts_ram_total.pop(host, None)
# Exclude the overloaded host # Exclude the overloaded host
if overloaded_host in hosts_cpu_usage: hosts_cpu_usage.pop(overloaded_host, None)
del hosts_cpu_usage[overloaded_host] hosts_cpu_total.pop(overloaded_host, None)
if overloaded_host in hosts_cpu_total: hosts_ram_usage.pop(overloaded_host, None)
del hosts_cpu_total[overloaded_host] hosts_ram_total.pop(overloaded_host, None)
if overloaded_host in hosts_ram_usage:
del hosts_ram_usage[overloaded_host]
if overloaded_host in hosts_ram_total:
del hosts_ram_total[overloaded_host]
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.debug('Host CPU usage: %s', str(hosts_last_cpu)) log.debug('Host CPU usage: %s', str(hosts_last_cpu))