Ejemplo n.º 1
0
    def test_add_global_args(self):
        parser = mock.Mock()

        cliargs.add_global_args(parser, '1')
        expected = [
            '-h', '--version', '-d', '-v', '--api-timeout',
            '--senlin-api-version'
        ]

        options = [arg[0][0] for arg in parser.add_argument.call_args_list]
        self.assertEqual(expected, options)
    def test_add_global_args(self):
        parser = mock.Mock()

        cliargs.add_global_args(parser, '1')
        expected = [
            '-h',
            '--version',
            '-d',
            '-v',
            '--api-timeout',
            '--senlin-api-version'
        ]

        options = [arg[0][0] for arg in parser.add_argument.call_args_list]
        self.assertEqual(expected, options)
Ejemplo n.º 3
0
    def main(self, argv):
        # Parse args once to find version
        parser = argparse.ArgumentParser(
            prog='senlin',
            description=__doc__.strip(),
            epilog=_('Type "senlin help <COMMAND>" for help on a specific '
                     'command.'),
            add_help=False,
            formatter_class=HelpFormatter,
        )

        cliargs.add_global_args(parser, version=senlinclient.__version__)
        cliargs.add_global_identity_args(parser)
        self.add_profiler_args(parser)
        base_parser = parser

        (options, args) = base_parser.parse_known_args(argv)

        self._setup_logging(options.debug)
        self._setup_verbose(options.verbose)

        # build available subcommands based on version
        api_ver = options.senlin_api_version
        LOG.info(api_ver)
        subcommand_parser = self.get_subcommand_parser(base_parser, api_ver)
        self.parser = subcommand_parser

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line
        if not args and options.help or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        # Check if identity information are sufficient
        self._check_identity_arguments(args)

        # Setup Senlin client connection
        sc = self._setup_senlin_client(api_ver, args)

        profile = osprofiler_profiler and options.profile
        if profile:
            osprofiler_profiler.init(options.profile)

        args.func(sc.service, args)

        if profile:
            trace_id = osprofiler_profiler.get().get_base_id()
            print(_("Trace ID: %s") % trace_id)
            print(
                _("To display trace use next command:\n"
                  "osprofiler trace show --html %s ") % trace_id)
Ejemplo n.º 4
0
    def main(self, argv):
        # Parse args once to find version
        parser = argparse.ArgumentParser(
            prog='senlin',
            description=__doc__.strip(),
            epilog=_('Type "senlin help <COMMAND>" for help on a specific '
                     'command.'),
            add_help=False,
            formatter_class=HelpFormatter,
        )

        cliargs.add_global_args(parser, version=senlinclient.__version__)
        cliargs.add_global_identity_args(parser)
        self.add_profiler_args(parser)
        base_parser = parser

        (options, args) = base_parser.parse_known_args(argv)

        self._setup_logging(options.debug)
        self._setup_verbose(options.verbose)

        # build available subcommands based on version
        api_ver = options.senlin_api_version
        LOG.info(api_ver)
        subcommand_parser = self.get_subcommand_parser(base_parser, api_ver)
        self.parser = subcommand_parser

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line
        if not args and options.help or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        # Check if identity information are sufficient
        self._check_identity_arguments(args)

        # Setup Senlin client connection
        sc = self._setup_senlin_client(api_ver, args)

        profile = osprofiler_profiler and options.profile
        if profile:
            osprofiler_profiler.init(options.profile)

        args.func(sc.service, args)

        if profile:
            trace_id = osprofiler_profiler.get().get_base_id()
            print(_("Trace ID: %s") % trace_id)
            print(_("To display trace use next command:\n"
                  "osprofiler trace show --html %s ") % trace_id)