Пример #1
0
    def setup_parser(self):
        parser = argparse.ArgumentParser(prog="linstor")
        """
        ATTENTION! ATTENTION!
        If you add a new global option here, don't forget to update:
        utils.py:filter_new_args
        otherwise drbd options will fail!
        ATTENTION OVER! ATTENTION OVER!
        """
        parser.add_argument('--version',
                            '-v',
                            action='version',
                            version='%(prog)s ' + VERSION + '; ' + GITHASH)
        parser.add_argument(
            '--no-color',
            action="store_true",
            help=
            'Do not use colors in output. Useful for old terminals/scripting.')
        parser.add_argument(
            '--no-utf8',
            action="store_true",
            default=not sys.stdout.isatty(),
            help='Do not use utf-8 characters in output (i.e., tables).')
        parser.add_argument(
            '--warn-as-error',
            action="store_true",
            help='Treat WARN return code as error (i.e., return code > 0).')
        parser.add_argument(
            '--curl',
            action="store_true",
            help=
            "Do not execute the action, only output a curl equivalent command."
        )
        parser.add_argument(
            '--controllers',
            default='localhost:%d' % linstor.Linstor.REST_PORT,
            help=
            'Comma separated list of controllers (e.g.: "host1:port,host2:port"). '
            'If the environment variable %s is set, '
            'the ones set via this argument get appended.' %
            KEY_LS_CONTROLLERS)
        parser.add_argument('-m', '--machine-readable', action="store_true")
        parser.add_argument(
            '--output-version',
            choices=['v0', 'v1'],
            default=os.environ.get(ENV_OUTPUT_VERSION, "v0"),
            help="Machine readable output format, default 'v0'. "
            "Can also be set via environment variable '{env}'".format(
                env=ENV_OUTPUT_VERSION))
        parser.add_argument('--verbose', '-V', action='store_true')
        parser.add_argument(
            '-t',
            '--timeout',
            default=300,
            type=int,
            help="Connection/Command timeout value in seconds.")
        parser.add_argument(
            '--disable-config',
            action="store_true",
            help="Disable config loading and only use commandline arguments.")
        parser.add_argument('--user', '-u', help="Linstor username to use")
        parser.add_argument('--password', '-P', help="Linstor user password")
        parser.add_argument('--certfile', help="SSL certificate file")
        parser.add_argument('--keyfile', help="SSL key file")
        parser.add_argument('--cafile', help="SSL CA certificate file")
        parser.add_argument('--allow-insecure-auth',
                            action='store_true',
                            help="Allow password authentication with HTTP")

        subp = parser.add_subparsers(
            title='subcommands',
            description='valid subcommands',
            help='Use the list command to print a '
            'nicer looking overview of all valid commands')

        # interactive mode
        parser_ia = subp.add_parser(Commands.INTERACTIVE,
                                    description='Start interactive mode')
        parser_ia.set_defaults(func=self.cmd_interactive)

        # help
        p_help = subp.add_parser(Commands.HELP,
                                 description='Print help for a command')
        p_help.add_argument('command', nargs='*')
        p_help.set_defaults(func=self.cmd_help, always_allowed=True)

        # list
        p_list = subp.add_parser(Commands.LIST_COMMANDS,
                                 aliases=['commands', 'list'],
                                 description='List available commands')
        p_list.add_argument('-t',
                            '--tree',
                            action="store_true",
                            help="Print a tree view of all commands.")
        p_list.set_defaults(func=self.cmd_list, always_allowed=True)

        # exit
        p_exit = subp.add_parser(Commands.EXIT,
                                 aliases=['quit'],
                                 description='Only useful in interactive mode')
        p_exit.set_defaults(func=self.cmd_exit, always_allowed=True)

        for sub_cmd in self._command_list:
            sub_cmd.setup_commands(subp)

        # dm-migrate
        c_dmmigrate = subp.add_parser(
            Commands.DMMIGRATE,
            description='Generate a migration script from drbdmanage to linstor'
        )
        c_dmmigrate.add_argument(
            'ctrlvol',
            help='json dump generated by "drbdmanage export-ctrlvol"')
        c_dmmigrate.add_argument(
            'script', help='file name of the generated migration shell script')
        c_dmmigrate.set_defaults(func=MigrateCommands.cmd_dmmigrate)

        # zsh completer
        self._zsh_generator = ZshGenerator(subp)
        zsh_compl = subp.add_parser(
            Commands.GEN_ZSH_COMPLETER,
            description='Generate a zsh completion script')
        zsh_compl.set_defaults(func=self._zsh_generator.cmd_completer)

        argcomplete.autocomplete(parser)

        subp.metavar = "{%s}" % ", ".join(sorted(Commands.MainList))

        return parser
Пример #2
0
    def setup_parser(self):
        parser = argparse.ArgumentParser(prog="linstor")
        parser.add_argument('--version',
                            '-v',
                            action='version',
                            version='%(prog)s ' + VERSION + '; ' + GITHASH)
        parser.add_argument(
            '--no-color',
            action="store_true",
            help=
            'Do not use colors in output. Useful for old terminals/scripting.')
        parser.add_argument(
            '--no-utf8',
            action="store_true",
            default=not sys.stdout.isatty(),
            help='Do not use utf-8 characters in output (i.e., tables).')
        parser.add_argument(
            '--warn-as-error',
            action="store_true",
            help='Treat WARN return code as error (i.e., return code > 0).')
        parser.add_argument(
            '--controllers',
            default='localhost:%d' % sharedconsts.DFLT_CTRL_PORT_PLAIN,
            help=
            'Comma separated list of controllers (e.g.: "host1:port,host2:port"). '
            'If the environment variable %s is set, '
            'the ones set via this argument get appended.' %
            KEY_LS_CONTROLLERS)
        parser.add_argument('-m', '--machine-readable', action="store_true")
        parser.add_argument('-t',
                            '--timeout',
                            default=300,
                            type=int,
                            help="Connection timeout value.")
        parser.add_argument(
            '--disable-config',
            action="store_true",
            help="Disable config loading and only use commandline arguments.")

        subp = parser.add_subparsers(
            title='subcommands',
            description='valid subcommands',
            help='Use the list command to print a '
            'nicer looking overview of all valid commands')

        # interactive mode
        parser_ia = subp.add_parser(Commands.INTERACTIVE,
                                    description='Start interactive mode')
        parser_ia.set_defaults(func=self.cmd_interactive)

        # help
        p_help = subp.add_parser(Commands.HELP,
                                 description='Print help for a command')
        p_help.add_argument('command', nargs='*')
        p_help.set_defaults(func=self.cmd_help)

        # list
        p_list = subp.add_parser(Commands.LIST_COMMANDS,
                                 aliases=['commands', 'list'],
                                 description='List available commands')
        p_list.add_argument('-t',
                            '--tree',
                            action="store_true",
                            help="Print a tree view of all commands.")
        p_list.set_defaults(func=self.cmd_list)

        # exit
        p_exit = subp.add_parser(Commands.EXIT,
                                 aliases=['quit'],
                                 description='Only useful in interactive mode')
        p_exit.set_defaults(func=self.cmd_exit)

        # controller commands
        self._controller_commands.setup_commands(subp)

        # add all node commands
        self._node_commands.setup_commands(subp)

        # new-resource definition
        self._resource_dfn_commands.setup_commands(subp)

        # add all resource commands
        self._resource_commands.setup_commands(subp)

        # add all snapshot commands
        self._snapshot_commands.setup_commands(subp)

        # add all storage pool definition commands
        self._storage_pool_dfn_commands.setup_commands(subp)

        # add all storage pools commands
        self._storage_pool_commands.setup_commands(subp)

        # add all volume definition commands
        self._volume_dfn_commands.setup_commands(subp)

        # misc commands
        self._misc_commands.setup_commands(subp)

        # dm-migrate
        c_dmmigrate = subp.add_parser(
            Commands.DMMIGRATE,
            description='Generate a migration script from drbdmanage to linstor'
        )
        c_dmmigrate.add_argument(
            'ctrlvol',
            help='json dump generated by "drbdmanage export-ctrlvol"')
        c_dmmigrate.add_argument(
            'script', help='file name of the generated migration shell script')
        c_dmmigrate.set_defaults(func=MigrateCommands.cmd_dmmigrate)

        # zsh completer
        self._zsh_generator = ZshGenerator(subp)
        zsh_compl = subp.add_parser(
            Commands.GEN_ZSH_COMPLETER,
            description='Generate a zsh completion script')
        zsh_compl.set_defaults(func=self._zsh_generator.cmd_completer)

        argcomplete.autocomplete(parser)

        subp.metavar = "{%s}" % ", ".join(sorted(Commands.MainList))

        return parser