def create(config, default_env_type=DEFAULT_ENV_TYPE, pre_chain=[ UrlAbbrevProcessor(), EnsureUrlProcessor(), EnsurePythonObjectProcessor() ]): """Convenience method to create a NsblInventory object out of the configs and a few optional parameters. Args: config (list): list of config items default_env_type (str): the type a environment is if it is not explicitely specified, either ENV_TYPE_HOST or ENV_TYPE_GROUP pre_chain (list): the chain of ConfigProcessors to plug in front of the one that is used internally, needs to return a python list Returns: NsblInventory: the inventory object, already 'processed' """ chain = pre_chain + [FrklProcessor(NSBL_INVENTORY_BOOTSTRAP_FORMAT)] inv_frkl = Frkl(config, chain) init_params = {"default_env_type": default_env_type} inventory = NsblInventory(init_params) inv_frkl.process(inventory) return inventory
def create(config, role_repos=[], task_descs=[], include_parent_meta=False, include_parent_vars=False, default_env_type=DEFAULT_ENV_TYPE, pre_chain=[ UrlAbbrevProcessor(), EnsureUrlProcessor(), EnsurePythonObjectProcessor() ], wrap_into_hosts=[], additional_roles=[]): """"Utility method to create a Nsbl object out of the configuration and some metadata about how to process that configuration. Args: config (list): a list of configuration items role_repos (list): a list of all locally available role repos task_descs (list): a list of additional task descriptions, those can be used to augment the ones that come with role repositories include_parent_meta (bool): whether to include parent meta dict into tasks (not used at the moment) include_parent_var (bool): whether to include parent var dict into tasks (not used at the moment) default_env_type (str): the type a environment is if it is not explicitely specified, either ENV_TYPE_HOST or ENV_TYPE_GROUP pre_chain (list): the chain of ConfigProcessors to plug in front of the one that is used internally, needs to return a python list wrap_into_hosts (list): whether to wrap the input configuration into a a list of hosts, for convenience, default: [] additional_roles (list): a list of additional roles that should always be added to the ansible environment Returns: Nsbl: the Nsbl object, already 'processed' """ init_params = { "task_descs": task_descs, "role_repos": role_repos, "include_parent_meta": include_parent_meta, "include_parent_vars": include_parent_vars, "default_env_type": default_env_type, "additional_roles": additional_roles } nsbl = Nsbl(init_params) # if not wrap_into_localhost_env: if not wrap_into_hosts: chain = pre_chain + [ FrklProcessor(NSBL_INVENTORY_BOOTSTRAP_FORMAT) ] else: # wrap_processor = WrapTasksIntoLocalhostEnvProcessor({}) wrap_processor = WrapTasksIntoHostsProcessor( {ENV_HOSTS_KEY: wrap_into_hosts}) chain = pre_chain + [ wrap_processor, FrklProcessor(NSBL_INVENTORY_BOOTSTRAP_FORMAT) ] inv_frkl = Frkl(config, chain) temp = inv_frkl.process(nsbl) return nsbl
def convert(self, value, param, ctx): if not isinstance(value, string_types): raise Exception("freckle url needs to a string: {}".format(value)) try: frkl_obj = Frkl(value, [ UrlAbbrevProcessor(init_params={"abbrevs": DEFAULT_ABBREVIATIONS, "add_default_abbrevs": False, "verbose": True})]) result = frkl_obj.process() return result[0] except: self.fail('%s is not a valid repo url' % value, param, ctx)
def expand_string_to_git_repo(value, default_abbrevs): if isinstance(value, string_types): is_string = True elif isinstance(value, (list, tuple)): is_string = False else: raise Exception("Not a supported type (only string or list are accepted): {}".format(value)) try: frkl_obj = Frkl(value, [ UrlAbbrevProcessor(init_params={"abbrevs": default_abbrevs, "add_default_abbrevs": False})]) result = frkl_obj.process() if is_string: return result[0] else: return result except (Exception) as e: raise Exception("'{}' is not a valid repo url: {}".format(value, e.message))
def create_command(self, command_name, yaml_file): """Created the commandline options and arguments out of a frecklecutable.""" log.debug("Loading command file '{}'...".format(yaml_file)) chain = [ UrlAbbrevProcessor(), EnsureUrlProcessor(), EnsurePythonObjectProcessor() ] try: frkl_obj = Frkl(yaml_file, chain) config_content = frkl_obj.process(MergeDictResultCallback()) except (Exception) as e: log.debug("Can't parse command file '{}'".format(yaml_file)) click.echo("- can't parse command file '{}'".format(yaml_file)) return None tasks = config_content.get("tasks", None) if not tasks: return None # extra_options = {'jack': 4098, 'sape': 4139} freck_defaults = { "path": os.path.abspath(yaml_file), "dir": os.path.abspath(os.path.dirname(yaml_file)) } config_content.setdefault("defaults", {})["frecklecutable"] = freck_defaults cli_command = create_cli_command(config_content, command_name=command_name, command_path=yaml_file) return cli_command
def convert(self, value, param, ctx): chain = [ UrlAbbrevProcessor(), EnsureUrlProcessor(), EnsurePythonObjectProcessor(), LoadMoreConfigsProcessor()] try: if not isinstance(value, (list, tuple)): value = [value] frkl_obj = Frkl(value, chain) result = frkl_obj.process() if isinstance(result[0], (list, tuple)): result_dict = {} for item in result[0]: dict_merge(result_dict, item, copy_dct=False) return result_dict else: return result[0] except (Exception) as e: self.fail("Can't read vars '{}': {}".format(value, str(e)))