<s> """<STR_LIT>""" <EOL> import os . path <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from nova . i18n import _LE <EOL> from nova . scheduler . filters . utils import * <EOL> rack_config_file_opts = [ <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ] <EOL> CONF = cfg . CONF <EOL> CONF . register_opts ( rack_config_file_opts ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def get_host_racks_config ( ) : <EOL> """<STR_LIT>""" <EOL> host_racks_map = { } <EOL> sections = { } <EOL> filepath = CONF . rack_config <EOL> if not filepath : <EOL> return host_racks_map <EOL> if not os . path . exists ( filepath ) : <EOL> LOG . error ( _LE ( "<STR_LIT>" ) , filepath ) <EOL> return host_racks_map <EOL> prefix = CONF . rack_config_prefix <EOL> if not prefix : <EOL> LOG . error ( _LE ( "<STR_LIT>" ) ) <EOL> return host_racks_map <EOL> try : <EOL> rack_config_parser = cfg . ConfigParser ( filepath , sections ) <EOL> rack_config_parser . parse ( ) <EOL> for section_name in sections . keys ( ) : <EOL> if section_name . startswith ( prefix ) : <EOL> for key , value in sections [ section_name ] . items ( ) : <EOL> host_racks_map . setdefault ( key , set ( [ ] ) ) <EOL> host_racks_map [ key ] . add ( section_name ) <EOL> except Exception as e : <EOL> LOG . error ( _LE ( "<STR_LIT>" ) , <EOL> str ( e ) ) <EOL> return host_racks_map <EOL> def get_host_racks_map ( hosts ) : <EOL> """<STR_LIT>""" <EOL> host_racks_map = { } <EOL> for host_state in hosts : <EOL> host_name = host_state . host <EOL> host_racks = aggregate_values_from_key ( host_state , '<STR_LIT>' ) <EOL> if host_racks : <EOL> host_racks_map . setdefault ( host_name , set ( ) ) <EOL> host_racks_map [ host_name ] = host_racks_map [ host_name ] . union ( <EOL> host_racks ) <EOL> if not host_racks_map : <EOL> host_racks_map = get_host_racks_config ( ) <EOL> return host_racks_map </s>
