<s> import functools <EOL> import os_client_config <EOL> import shade <EOL> from shade import _utils <EOL> class OpenStackInventory ( object ) : <EOL> extra_config = None <EOL> def __init__ ( <EOL> self , config_files = None , refresh = False , private = False , <EOL> config_key = None , config_defaults = None , cloud = None ) : <EOL> if config_files is None : <EOL> config_files = [ ] <EOL> config = os_client_config . config . OpenStackConfig ( <EOL> config_files = os_client_config . config . CONFIG_FILES + config_files ) <EOL> self . extra_config = config . get_extra_config ( <EOL> config_key , config_defaults ) <EOL> if cloud is None : <EOL> self . clouds = [ <EOL> shade . OpenStackCloud ( cloud_config = cloud_config ) <EOL> for cloud_config in config . get_all_clouds ( ) <EOL> ] <EOL> else : <EOL> try : <EOL> self . clouds = [ <EOL> shade . OpenStackCloud ( <EOL> cloud_config = config . get_one_cloud ( cloud ) ) <EOL> ] <EOL> except os_client_config . exceptions . OpenStackConfigException as e : <EOL> raise shade . OpenStackCloudException ( e ) <EOL> if private : <EOL> for cloud in self . clouds : <EOL> cloud . private = True <EOL> if refresh : <EOL> for cloud in self . clouds : <EOL> cloud . _cache . invalidate ( ) <EOL> def list_hosts ( self , expand = True , fail_on_cloud_config = True ) : <EOL> hostvars = [ ] <EOL> for cloud in self . clouds : <EOL> try : <EOL> for server in cloud . list_servers ( detailed = expand ) : <EOL> hostvars . append ( server ) <EOL> except shade . OpenStackCloudException : <EOL> if fail_on_cloud_config : <EOL> raise <EOL> return hostvars <EOL> def search_hosts ( self , name_or_id = None , filters = None , expand = True ) : <EOL> hosts = self . list_hosts ( expand = expand ) <EOL> return _utils . _filter_list ( hosts , name_or_id , filters ) <EOL> def get_host ( self , name_or_id , filters = None , expand = True ) : <EOL> if expand : <EOL> func = self . search_hosts <EOL> else : <EOL> func = functools . partial ( self . search_hosts , expand = False ) <EOL> return _utils . _get_entity ( func , name_or_id , filters ) </s>
