def openstack_clouds(config=None, debug=False, cloud=None, strict=False, app_name=None, app_version=None): if not config: config = _get_openstack_config(app_name, app_version) try: if cloud is None: return [ OpenStackCloud(cloud=f.name, debug=debug, cloud_config=f, strict=strict, **f.config) for f in config.get_all_clouds() ] else: return [ OpenStackCloud(cloud=f.name, debug=debug, cloud_config=f, strict=strict, **f.config) for f in config.get_all_clouds() if f.name == cloud ] except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: raise OpenStackCloudException( "Invalid cloud configuration: {exc}".format(exc=str(e)))
def main(): module = AnsibleModule(argument_spec=dict(clouds=dict( required=False, type='list', default=[], elements='str'), )) if not HAS_OPENSTACKSDK: module.fail_json(msg='openstacksdk is required for this module') p = module.params try: config = openstack.config.OpenStackConfig() clouds = [] for cloud in config.get_all_clouds(): if not p['clouds'] or cloud.name in p['clouds']: cloud.config['name'] = cloud.name clouds.append(cloud.config) module.exit_json(ansible_facts=dict(openstack=dict(clouds=clouds))) except exceptions.ConfigException as e: module.fail_json(msg=str(e))
def __init__(self, config_files=None, refresh=False, private=False, config_key=None, config_defaults=None, cloud=None, use_direct_get=False): if config_files is None: config_files = [] config = openstack.config.loader.OpenStackConfig( config_files=openstack.config.loader.CONFIG_FILES + config_files) self.extra_config = config.get_extra_config(config_key, config_defaults) if cloud is None: self.clouds = [ openstack.OpenStackCloud(cloud_config=cloud_config) for cloud_config in config.get_all_clouds() ] else: try: self.clouds = [ openstack.OpenStackCloud( cloud_config=config.get_one_cloud(cloud)) ] except openstack.config.exceptions.OpenStackConfigException as e: raise openstack.OpenStackCloudException(e) if private: for cloud in self.clouds: cloud.private = True # Handle manual invalidation of entire persistent cache if refresh: for cloud in self.clouds: cloud._cache.invalidate()