def discover_apache_driver_options(provider): loader = import_from_module( "corc.providers.apache.config_{}".format(provider), "config_{}".format(provider), "load_driver_options", ) return loader
def cli_exec(args): # action determines which function to execute module_path = args.module_path module_name = args.module_name func_name = args.func_name if hasattr(args, "provider_groups"): provider_groups = args.provider_groups else: provider_groups = [] if hasattr(args, "argument_groups"): argument_groups = args.argument_groups else: argument_groups = [] if hasattr(args, "skip_config_groups"): skip_config_groups = args.skip_config_groups else: skip_config_groups = [] provider, provider_kwargs = prepare_provider_kwargs(args, namespace_wrap=True) if provider: module_path = module_path.format(provider=provider) # load missing provider kwargs from config provider_configuration = prepare_kwargs_configurations( provider, provider_kwargs, provider_groups, strip_group_prefix=False) provider_kwargs = load_missing_action_kwargs(provider_configuration) func = import_from_module(module_path, module_name, func_name) if not func: return False # Extract config kwargs from args kwargs_configuration = prepare_kwargs_configurations( provider, args, argument_groups) # Load config and fill in missing values action_kwargs = load_missing_action_kwargs(kwargs_configuration) # Extract none config kwargs from args extra_action_kwargs = prepare_none_config_kwargs(args, skip_config_groups) if provider: return func(provider, provider_kwargs, **action_kwargs, **extra_action_kwargs) return func(**action_kwargs, **extra_action_kwargs)
def list_instances(provider, provider_kwargs, **kwargs): response = {} provider_func = import_from_module( "corc.providers.{}.instance".format(provider), "instance", "client_list_instances", ) instances = provider_func(provider, provider_kwargs, format_return=True, **kwargs) if instances or isinstance(instances, list) and len(instances) == 0: response["instances"] = instances return True, response return False, response
def stop_instance(provider, provider_kwargs, instance={}): response = {} provider_func = import_from_module( "corc.providers.{}.instance".format(provider), "instance", "client_delete_instance", ) deleted_id, msg = provider_func(provider, provider_kwargs, instance=instance) response["msg"] = msg if not deleted_id: return False, response response["id"] = deleted_id return True, response
def generate_config(provider, overwrite_with_empty=False, **kwargs): load_default_config = import_from_module( "corc.providers.{}.config".format(provider), "config", "load_default_config", ) default_config = load_default_config(provider) if kwargs: flat = flatten_dict.flatten(default_config) other_flat = flatten_dict.flatten(kwargs) for k, v in other_flat.items(): if not v and overwrite_with_empty: flat[k] = v if v: flat[k] = v default_config = flatten_dict.unflatten(flat) return default_config
def get_instance(provider, provider_kwargs, instance={}, details={}): response = {} provider_func = import_from_module( "corc.providers.{}.instance".format(provider), "instance", "client_get_instance") instance_id, instance, msg = provider_func( provider, provider_kwargs, format_return=True, instance=instance, details=details, ) response["id"] = instance_id response["msg"] = msg if instance: response["instance"] = instance return True, response return False, response
def prepare_provider_config(provider, provider_kwargs, **kwargs): prepare_config = import_from_module( "corc.cli.providers.{}.config".format(provider), "config", "prepare_config") return prepare_config(provider, provider_kwargs, **kwargs)
def load_valid_config(provider): valid_config = import_from_module( "corc.providers.{}.config".format(provider), "config", "load_valid_config") return valid_config(provider=provider)
def load_default_config(provider): default_config = import_from_module( "corc.providers.{}.config".format(provider), "config", "load_default_config") return default_config(provider=provider)
def load_config_groups(provider): config_groups_loader = import_from_module( "corc.providers.{}.config".format(provider), "config", "load_config_groups") return config_groups_loader(provider=provider)