_commands.py 5.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""SuperBench CLI commands."""

from knack.arguments import ArgumentsContext
from knack.commands import CLICommandsLoader, CommandGroup


class SuperBenchCommandsLoader(CLICommandsLoader):
    """SuperBench CLI commands loader."""
    def load_command_table(self, args):
        """Load commands into the command table.

        Args:
            args (list): List of arguments from the command line.

        Returns:
            collections.OrderedDict: Load commands into the command table.
        """
        with CommandGroup(self, '', 'superbench.cli._handler#{}') as g:
            g.command('version', 'version_command_handler')
            g.command('deploy', 'deploy_command_handler')
            g.command('exec', 'exec_command_handler')
            g.command('run', 'run_command_handler')
26
27
28
        with CommandGroup(self, 'benchmark', 'superbench.cli._benchmark_handler#{}') as g:
            g.command('list', 'benchmark_list_command_handler')
            g.command('list-parameters', 'benchmark_list_params_command_handler')
29
30
        with CommandGroup(self, 'node', 'superbench.cli._node_handler#{}') as g:
            g.command('info', 'info_command_handler')
31
32
        with CommandGroup(self, 'result', 'superbench.cli._result_handler#{}') as g:
            g.command('diagnosis', 'diagnosis_command_handler')
33
            g.command('summary', 'summary_command_handler')
34
            g.command('generate-baseline', 'generate_baseline_command_handler')
35
36
37
38
39
40
41
42
43
44
        return super().load_command_table(args)

    def load_arguments(self, command):
        """Load arguments for commands.

        Args:
            command: The command to load arguments for.
        """
        with ArgumentsContext(self, '') as ac:
            ac.argument('docker_image', options_list=('--docker-image', '-i'), type=str, help='Docker image URI.')
45
46
47
48
49
50
            ac.argument(
                'container_name',
                options_list=('--container-name',),
                type=str,
                help='Docker container name. Defaults to sb-workspace.'
            )
51
52
            ac.argument('docker_username', type=str, help='Docker registry username if authentication is needed.')
            ac.argument('docker_password', type=str, help='Docker registry password if authentication is needed.')
53
            ac.argument('no_docker', action='store_true', help='Run on host directly without Docker.')
54
            ac.argument('no_image_pull', action='store_true', help='Skip pull and use local Docker image.')
55
56
57
58
59
60
            ac.argument(
                'host_file', options_list=('--host-file', '-f'), type=str, help='Path to Ansible inventory host file.'
            )
            ac.argument('host_list', options_list=('--host-list', '-l'), type=str, help='Comma separated host list.')
            ac.argument('host_username', type=str, help='Host username if needed.')
            ac.argument('host_password', type=str, help='Host password or key passphase if needed.')
61
62
63
64
65
            ac.argument(
                'output_dir',
                type=str,
                help='Path to output directory, outputs/{datetime} will be used if not specified.'
            )
66
67
68
69
70
71
72
73
            ac.argument('private_key', type=str, help='Path to private key if needed.')
            ac.argument(
                'config_file', options_list=('--config-file', '-c'), type=str, help='Path to SuperBench config file.'
            )
            ac.argument(
                'config_override',
                options_list=('--config-override', '-C'),
                type=str,
74
75
                nargs='+',
                help='Extra arguments to override config_file.'
76
            )
77
78
79
            ac.argument(
                'get_info', options_list=('--get-info', '-g'), action='store_true', help='Collect node system info.'
            )
80
81
82
83

        with ArgumentsContext(self, 'benchmark') as ac:
            ac.argument('name', options_list=('--name', '-n'), type=str, help='Benchmark name or regular expression.')

84
85
86
        with ArgumentsContext(self, 'result') as ac:
            ac.argument('raw_data_file', options_list=('--data-file', '-d'), type=str, help='Path to raw data file.')
            ac.argument('rule_file', options_list=('--rule-file', '-r'), type=str, help='Path to rule file.')
87
88
89
90
91
92
93
94
95
96
97
98
            ac.argument(
                'summary_rule_file',
                options_list=('--summary-rule-file', '-sr'),
                type=str,
                help='Path to summary rule file.'
            )
            ac.argument(
                'diagnosis_rule_file',
                options_list=('--diagnosis-rule-file', '-dr'),
                type=str,
                help='Path to diagnosis rule file.'
            )
99
100
101
102
103
104
105
106
107
            ac.argument(
                'baseline_file', options_list=('--baseline-file', '-b'), type=str, help='Path to baseline file.'
            )
            ac.argument(
                'output_dir',
                type=str,
                help='Path to output directory, outputs/{datetime} will be used if not specified.'
            )
            ac.argument('output_file_format', type=str, help='Format of output file, excel or json.')
108
            ac.argument('decimal_place_value', type=int, help='Number of decimal places to show in output.')
109
            ac.argument('output_all', action='store_true', help='Output results of all nodes.')
110

111
        super().load_arguments(command)