Esempio n. 1
0
    def parse_args(self, arg_parser, args=None):
        """Parses all the arguments (cli, answers file)

        :return: None, if ``--generate-answers-file`` in arg_arg_parser
        :return: (dict, dict):
            * command arguments dict (arguments to control the IR logic)
            * nested arguments dict (arguments to pass to the playbooks)
        """

        spec_defaults = self.get_spec_defaults()
        cli_args = CliParser.parse_cli_input(arg_parser, args)

        file_args = self.get_answers_file_args(cli_args)

        # generate answers file and exit
        if self.generate_answers_file(cli_args, spec_defaults):
            LOG.warning("Answers file generated. Exiting.")

        # print warnings when something was overridden from non-cli source.
        self.validate_arg_sources(cli_args, file_args,
                                  spec_defaults)

        # print warnings for deprecated
        self.validate_arg_deprecation(cli_args, file_args)

        # now filter defaults to have only parser defined in cli
        defaults = dict((key, spec_defaults[key])
                        for key in cli_args.keys() if
                        key in spec_defaults)

        # copy cli args with the same name to all parser groups
        self._merge_duplicated_cli_args(cli_args)
        self._merge_duplicated_cli_args(file_args)

        dict_utils.dict_merge(defaults, file_args)
        dict_utils.dict_merge(defaults, cli_args)
        self.validate_requires_args(defaults)
        self.validate_length_args(defaults)
        self.validate_choices_args(defaults)
        self.validate_min_max_args(defaults)

        # now resolve complex types.
        self.resolve_custom_types(defaults)
        nested, control, custom = \
            self.get_nested_custom_and_control_args(defaults)
        return nested, control, custom
Esempio n. 2
0
    def parse_args(self, arg_parser, args=None):
        """Parses all the arguments (cli, answers file)

        :return: None, if ``--generate-answers-file`` in arg_arg_parser
        :return: (dict, dict):
            * command arguments dict (arguments to control the IR logic)
            * nested arguments dict (arguments to pass to the playbooks)
        """

        spec_defaults = self.get_spec_defaults()
        cli_args = CliParser.parse_cli_input(arg_parser, args)

        file_args = self.get_answers_file_args(cli_args)

        # generate answers file and exit
        if self.generate_answers_file(cli_args, spec_defaults):
            LOG.warning("Answers file generated. Exiting.")

        # print warnings when something was overridden from non-cli source.
        self.validate_arg_sources(cli_args, file_args,
                                  spec_defaults)

        # print warnings for deprecated
        self.validate_arg_deprecation(cli_args, file_args)

        # now filter defaults to have only parser defined in cli
        defaults = dict((key, spec_defaults[key])
                        for key in cli_args.keys() if
                        key in spec_defaults)

        # copy cli args with the same name to all parser groups
        self._merge_duplicated_cli_args(cli_args)
        self._merge_duplicated_cli_args(file_args)

        dict_utils.dict_merge(defaults, file_args)
        dict_utils.dict_merge(defaults, cli_args)
        self.validate_requires_args(defaults)
        self.validate_length_args(defaults)
        self.validate_choices_args(defaults)
        self.validate_min_max_args(defaults)

        # now resolve complex types.
        self.resolve_custom_types(defaults)
        nested, control = self.get_nested_and_control_args(defaults)
        return nested, control
Esempio n. 3
0
    def parse_args(self, arg_parser, args=None):
        """Parses all the arguments (cli, answers file)

        :return: None, if ``--generate-answers-file`` in arg_arg_parser
        :return: (dict, dict):
            * command arguments dict (arguments to control the IR logic)
            * nested arguments dict (arguments to pass to the playbooks)
            * custom_args custom arguments dict (arguments with custom ansible variables)
        """

        spec_defaults, custom_spec_defaults = self.get_spec_defaults()
        cli_args, custom_cli_args = CliParser.parse_cli_input(arg_parser, args)

        helper_custom_cli_args = dict(custom_cli_args)

        # parse custom ansible variables and their values
        custom_parsed_cli_args = {}
        for custom_parse in custom_cli_args.values():
            custom_parsed_cli_args.update(custom_parse)
        file_args, custom_file_args = self.get_answers_file_args(cli_args)

        # generate answers file and exit
        if self.generate_answers_file(cli_args, custom_cli_args,
                                      spec_defaults):
            LOG.warning("Answers file generated. Exiting.")

        # print warnings when something was overridden from non-cli source.
        self.validate_arg_sources(cli_args, file_args, spec_defaults)

        # print warnings for deprecated
        self.validate_arg_deprecation(cli_args, file_args)

        # now filter defaults to have only parser defined in cli
        defaults = dict((key, spec_defaults[key]) for key in cli_args.keys()
                        if key in spec_defaults)

        # now filter custom ansible defaults to have values defined:
        for custom_default in custom_spec_defaults:
            if custom_default not in custom_parsed_cli_args:
                custom_parsed_cli_args[custom_default] = custom_spec_defaults[
                    custom_default]

        # copy cli args with the same name to all parser groups
        self._merge_duplicated_cli_args(cli_args)
        self._merge_duplicated_cli_args(file_args)

        dict_utils.dict_merge(defaults, file_args)

        # combine custom cli commands with custom file parsing if needed
        if custom_file_args:
            custom_file_args.update(custom_parsed_cli_args)
            custom_parsed_cli_args = custom_file_args

        dict_utils.dict_merge(defaults, cli_args)
        self.validate_requires_args(defaults, custom_parsed_cli_args)
        self.validate_length_args(defaults)
        self.validate_choices_args(defaults)
        self.validate_min_max_args(defaults)

        # now resolve complex types.
        self.resolve_custom_types(defaults, custom_cli_args, custom_file_args)
        nested, control = self.get_nested_and_control_args(defaults)

        # populate custom cli args with resolved complextypes when parsing from CLI
        if helper_custom_cli_args:
            for helper_arg in helper_custom_cli_args:
                resolved_custom_value = custom_cli_args[helper_arg]
                for custom_variable in helper_custom_cli_args[helper_arg]:
                    custom_parsed_cli_args[
                        custom_variable] = resolved_custom_value

        return nested, control, custom_parsed_cli_args