Changed config.get to config[]

This commit is contained in:
Anton Beloglazov 2012-10-01 16:09:59 +10:00
parent 9460c30dc0
commit 3dd83b3088
2 changed files with 21 additions and 21 deletions

View File

@ -121,7 +121,7 @@ def start():
'collector.log', 'collector.log',
int(config['log_level'])) int(config['log_level']))
vm_path = common.build_local_vm_path(config.get('local_data_directory')) vm_path = common.build_local_vm_path(config['local_data_directory'])
if not os.access(vm_path, os.F_OK): if not os.access(vm_path, os.F_OK):
os.makedirs(vm_path) os.makedirs(vm_path)
log.info('Created a local VM data directory: ' + vm_path) log.info('Created a local VM data directory: ' + vm_path)
@ -129,7 +129,7 @@ def start():
cleanup_all_local_data(vm_path) cleanup_all_local_data(vm_path)
log.info('Creaned up the local VM data directory: ' + vm_path) log.info('Creaned up the local VM data directory: ' + vm_path)
interval = config.get('data_collector_interval') interval = config['data_collector_interval']
log.info('Starting the data collector, ' + log.info('Starting the data collector, ' +
'iterations every %s seconds', interval) 'iterations every %s seconds', interval)
return common.start( return common.start(
@ -159,7 +159,7 @@ def init_state(config):
host_cpu_mhz, host_ram = get_host_characteristics(vir_connection) host_cpu_mhz, host_ram = get_host_characteristics(vir_connection)
physical_cpus = common.physical_cpu_count(vir_connection) physical_cpus = common.physical_cpu_count(vir_connection)
db = init_db(config.get('sql_connection')) db = init_db(config['sql_connection'])
db.update_host(hostname, host_cpu_mhz, host_ram) db.update_host(hostname, host_cpu_mhz, host_ram)
return {'previous_time': 0., return {'previous_time': 0.,
@ -209,8 +209,8 @@ def execute(config, state):
:return: The updated state dictionary. :return: The updated state dictionary.
:rtype: dict(str: *) :rtype: dict(str: *)
""" """
path = common.build_local_vm_path(config.get('local_data_directory')) path = common.build_local_vm_path(config['local_data_directory'])
data_length = int(config.get('data_collector_data_length')) data_length = int(config['data_collector_data_length'])
vms_previous = get_previous_vms(path) vms_previous = get_previous_vms(path)
vms_current = get_current_vms(state['vir_connection']) vms_current = get_current_vms(state['vir_connection'])

View File

@ -129,7 +129,7 @@ def start():
'local-manager.log', 'local-manager.log',
int(config['log_level'])) int(config['log_level']))
interval = config.get('local_manager_interval') interval = config['local_manager_interval']
log.info('Starting the local manager, ' + log.info('Starting the local manager, ' +
'iterations every %s seconds', interval) 'iterations every %s seconds', interval)
return common.start( return common.start(
@ -158,7 +158,7 @@ def init_state(config):
physical_cpu_mhz_total = common.physical_cpu_mhz_total(vir_connection) physical_cpu_mhz_total = common.physical_cpu_mhz_total(vir_connection)
return {'previous_time': 0., return {'previous_time': 0.,
'vir_connect': vir_connection, 'vir_connect': vir_connection,
'db': init_db(config.get('sql_connection')), 'db': init_db(['sql_connection']),
'physical_cpu_mhz_total': physical_cpu_mhz_total} 'physical_cpu_mhz_total': physical_cpu_mhz_total}
@ -202,47 +202,47 @@ def execute(config, state):
:return: The updated state dictionary. :return: The updated state dictionary.
:rtype: dict(str: *) :rtype: dict(str: *)
""" """
path = common.build_local_vm_path(config.get('local_data_directory')) path = common.build_local_vm_path(config['local_data_directory'])
vm_cpu_mhz = get_local_data(path) vm_cpu_mhz = get_local_data(path)
vm_ram = get_ram(config.get('vir_connection'), vm_cpu_mhz.keys()) vm_ram = get_ram(config['vir_connection'], vm_cpu_mhz.keys())
vm_cpu_mhz = cleanup_vm_data(vm_cpu_mhz, vm_ram.keys()) vm_cpu_mhz = cleanup_vm_data(vm_cpu_mhz, vm_ram.keys())
if not vm_cpu_mhz: if not vm_cpu_mhz:
return return
physical_cpu_mhz_total = int(config.get('physical_cpu_mhz_total')) physical_cpu_mhz_total = int(config['physical_cpu_mhz_total'])
host_cpu_utilization = vm_mhz_to_percentage( host_cpu_utilization = vm_mhz_to_percentage(
vm_cpu_mhz, physical_cpu_mhz_total) vm_cpu_mhz, physical_cpu_mhz_total)
time_step = int(config.get('data_collector_interval')) time_step = int(config['data_collector_interval'])
migration_time = calculate_migration_time( migration_time = calculate_migration_time(
vm_ram, float(config.get('network_migration_bandwidth'))) vm_ram, float(config['network_migration_bandwidth']))
if 'underload_detection' not in state: if 'underload_detection' not in state:
underload_detection_params = json.loads( underload_detection_params = json.loads(
config.get('algorithm_underload_detection_params')) config['algorithm_underload_detection_params'])
underload_detection_state = None underload_detection_state = None
underload_detection = config.get( underload_detection = \
'algorithm_underload_detection_factory')( config['algorithm_underload_detection_factory'](
time_step, time_step,
migration_time, migration_time,
underload_detection_params) underload_detection_params)
state['underload_detection'] = underload_detection state['underload_detection'] = underload_detection
overload_detection_params = json.loads( overload_detection_params = json.loads(
config.get('algorithm_overload_detection_params')) config['algorithm_overload_detection_params'])
overload_detection_state = None overload_detection_state = None
overload_detection = config.get( overload_detection = \
'algorithm_overload_detection_factory')( config['algorithm_overload_detection_factory'](
time_step, time_step,
migration_time, migration_time,
overload_detection_params) overload_detection_params)
state['overload_detection'] = overload_detection state['overload_detection'] = overload_detection
vm_selection_params = json.loads( vm_selection_params = json.loads(
config.get('algorithm_vm_selection_params')) config['algorithm_vm_selection_params'])
vm_selection_state = None vm_selection_state = None
vm_selection = config.get( vm_selection = \
'algorithm_vm_selection_factory')( config['algorithm_vm_selection_factory'](
time_step, time_step,
migration_time, migration_time,
vm_selection_params) vm_selection_params)