diff --git a/nova_solverscheduler/scheduler/solvers/utils.py b/nova_solverscheduler/scheduler/solvers/utils.py index 0e924da..4f2b503 100644 --- a/nova_solverscheduler/scheduler/solvers/utils.py +++ b/nova_solverscheduler/scheduler/solvers/utils.py @@ -47,46 +47,46 @@ LOG = logging.getLogger(__name__) def get_host_racks_config(): - """Read the rack config file to get physical rack configurations.""" - # Example section in the file: - # [ml2_mech_cisco_nexus:1.1.1.1] - # compute1=1/1 - # compute2=1/2 - # ... + """Read the rack config file to get physical rack configurations.""" + # Example section in the file: + # [ml2_mech_cisco_nexus:1.1.1.1] + # compute1=1/1 + # compute2=1/2 + # ... - host_racks_map = {} - sections = {} - - filepath = CONF.rack_config - if not filepath: - return host_racks_map - - if not os.path.exists(filepath): - LOG.error(_LE("The rack config file is not found: %s"), filepath) - return host_racks_map - - prefix = CONF.rack_config_prefix - if not prefix: - LOG.error(_LE("Rack config prefix is not set.")) - return host_racks_map - - try: - rack_config_parser = cfg.ConfigParser(filepath, sections) - rack_config_parser.parse() - - for section_name in sections.keys(): - if section_name.startswith(prefix): - # section_name: rack id - for key, value in sections[section_name].items(): - # key: host name, value: port id - host_racks_map.setdefault(key, set([])) - host_racks_map[key].add(section_name) - except Exception as e: - LOG.error(_LE("The rack config file is not parsed properly: %s"), - str(e)) + host_racks_map = {} + sections = {} + filepath = CONF.rack_config + if not filepath: return host_racks_map + if not os.path.exists(filepath): + LOG.error(_LE("The rack config file is not found: %s"), filepath) + return host_racks_map + + prefix = CONF.rack_config_prefix + if not prefix: + LOG.error(_LE("Rack config prefix is not set.")) + return host_racks_map + + try: + rack_config_parser = cfg.ConfigParser(filepath, sections) + rack_config_parser.parse() + + for section_name in sections.keys(): + if section_name.startswith(prefix): + # section_name: rack id + for key, value in sections[section_name].items(): + # key: host name, value: port id + host_racks_map.setdefault(key, set([])) + host_racks_map[key].add(section_name) + except Exception as e: + LOG.error(_LE("The rack config file is not parsed properly: %s"), + str(e)) + + return host_racks_map + def get_host_racks_map(hosts): """Return a dict where keys are host names and values are names of racks