From 8fd1b1e684bf5e3eb913d6372a045ab7757bcc01 Mon Sep 17 00:00:00 2001 From: Anton Beloglazov Date: Tue, 31 Mar 2015 15:30:59 +1100 Subject: [PATCH] Replaced "if key in dict: del dict[key]" with "dict.pop(key, None)" --- neat/globals/manager.py | 52 ++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/neat/globals/manager.py b/neat/globals/manager.py index 870119d..b53dce0 100644 --- a/neat/globals/manager.py +++ b/neat/globals/manager.py @@ -335,12 +335,10 @@ def execute_underload(config, state, host): if vm not in vms_last_cpu: log.info('No data yet for VM: %s - skipping host %s', vm, host) hosts_to_keep_active.add(host) - del hosts_cpu_total[host] - del hosts_ram_total[host] - if host in hosts_cpu_usage: - del hosts_cpu_usage[host] - if host in hosts_ram_usage: - del hosts_ram_usage[host] + hosts_cpu_total.pop(host, None) + hosts_ram_total.pop(host, None) + hosts_cpu_usage.pop(host, None) + hosts_ram_usage.pop(host, None) break host_cpu_mhz += vms_last_cpu[vm] else: @@ -348,22 +346,18 @@ def execute_underload(config, state, host): hosts_ram_usage[host] = host_used_ram(state['nova'], host) else: # Exclude inactive hosts - del hosts_cpu_total[host] - del hosts_ram_total[host] + hosts_cpu_total.pop(host, None) + hosts_ram_total.pop(host, None) if log.isEnabledFor(logging.DEBUG): log.debug('Host CPU usage: %s', str(hosts_last_cpu)) log.debug('Host total CPU usage: %s', str(hosts_cpu_usage)) # Exclude the underloaded host - if underloaded_host in hosts_cpu_usage: - del hosts_cpu_usage[underloaded_host] - if underloaded_host in hosts_cpu_total: - del hosts_cpu_total[underloaded_host] - 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] + hosts_cpu_usage.pop(underloaded_host, None) + hosts_cpu_total.pop(underloaded_host, None) + hosts_ram_usage.pop(underloaded_host, None) + hosts_ram_total.pop(underloaded_host, None) if log.isEnabledFor(logging.DEBUG): 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: if vm not in vms_last_cpu: log.info('No data yet for VM: %s - skipping host %s', vm, host) - del hosts_cpu_total[host] - del hosts_ram_total[host] - if host in hosts_cpu_usage: - del hosts_cpu_usage[host] - if host in hosts_ram_usage: - del hosts_ram_usage[host] + hosts_cpu_total.pop(host, None) + hosts_ram_total.pop(host, None) + hosts_cpu_usage.pop(host, None) + hosts_ram_usage.pop(host, None) break host_cpu_mhz += vms_last_cpu[vm] else: @@ -520,18 +512,14 @@ def execute_overload(config, state, host, vm_uuids): else: inactive_hosts_cpu[host] = hosts_cpu_total[host] inactive_hosts_ram[host] = hosts_ram_total[host] - del hosts_cpu_total[host] - del hosts_ram_total[host] + hosts_cpu_total.pop(host, None) + hosts_ram_total.pop(host, None) # Exclude the overloaded host - if overloaded_host in hosts_cpu_usage: - del hosts_cpu_usage[overloaded_host] - if overloaded_host in hosts_cpu_total: - del hosts_cpu_total[overloaded_host] - 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] + hosts_cpu_usage.pop(overloaded_host, None) + hosts_cpu_total.pop(overloaded_host, None) + hosts_ram_usage.pop(overloaded_host, None) + hosts_ram_total.pop(overloaded_host, None) if log.isEnabledFor(logging.DEBUG): log.debug('Host CPU usage: %s', str(hosts_last_cpu))