예제 #1
0
def parser_add_script_subparser(subparsers):
    """Add suparser for 'script'."""
    _script_parser = subparsers.add_parser(
        'script',
        help='run script on sites frontends',
        epilog=help_msgs.SCRIPT_EPILOG,
        formatter_class=RawTextHelpFormatter)
    common.add_expid_arg(_script_parser)

    script_group = _script_parser.add_argument_group("Command")
    script_group = script_group.add_mutually_exclusive_group(required=True)

    script_group.add_argument('--run',
                              type=run_site_association_from_str,
                              metavar=RUN_SITE_ASSOCIATION_METAVAR,
                              dest='run_script_site',
                              nargs='+',
                              help="sites association with 'script'")
    script_group.add_argument('--kill',
                              type=common.site_with_domain_checked,
                              metavar='site',
                              dest='kill_sites',
                              nargs='*',
                              help='sites list')
    script_group.add_argument('--status',
                              type=common.site_with_domain_checked,
                              metavar='site',
                              dest='status_sites',
                              nargs='*',
                              help='sites list')
    return _script_parser
예제 #2
0
def parser_add_wait_subparser(subparsers, expid_required=False):
    """Add wait experiment subparser and return it."""
    wait_parser = subparsers.add_parser('wait',
                                        help='wait user experiment started',
                                        epilog=help_msgs.WAIT_EPILOG,
                                        formatter_class=RawTextHelpFormatter)

    common.add_expid_arg(wait_parser, required=expid_required)

    wait_parser.add_argument(
        '--state',
        default='Running',
        help="wait states `State1,State2` or Finished, default 'Running'")
    wait_parser.add_argument('--step',
                             default=5,
                             type=int,
                             help="Wait time in seconds between each check")
    wait_parser.add_argument('--timeout',
                             default=experiment.WAIT_TIMEOUT_DEFAULT,
                             type=float,
                             help="Max time to wait in seconds")
    wait_parser.add_argument('--cancel-on-timeout',
                             action='store_true',
                             help="Cancel experiment if timeout is reached")

    return wait_parser
예제 #3
0
파일: node.py 프로젝트: aabadie/cli-tools
def parse_options():
    """ Handle node-cli command-line options with argparse """

    parent_parser = common.base_parser()
    # We create top level parser
    parser = argparse.ArgumentParser(
        description=NODE_PARSER,
        parents=[parent_parser], formatter_class=RawTextHelpFormatter,
        epilog=(help_msgs.PARSER_EPILOG.format(cli='node', option='--update') +
                NODE_EPILOG),
    )

    common.add_expid_arg(parser)

    # command
    # argument with parameter can't both set 'command' and set argument value
    # so save argument, and command will be left to 'with_arguments'
    parser.set_defaults(command='with_argument')
    cmd_group = parser.add_mutually_exclusive_group(required=True)

    cmd_group.add_argument(
        '-sta', '--start', help='start command', const='start',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '-sto', '--stop', help='stop command', const='stop',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '-r', '--reset', help='reset command', const='reset',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '--debug-start', help='start debugger', const='debug-start',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '--debug-stop', help='stop debugger', const='debug-stop',
        dest='command', action='store_const')

    cmd_group.add_argument('-up', '--update',
                           dest='firmware_path', default=None,
                           help='flash firmware command with path file')

    cmd_group.add_argument('--profile', '--update-profile',
                           dest='profile_name', default=None,
                           help='change nodes current monitoring profile')

    # nodes list or exclude list
    common.add_nodes_selection_list(parser)

    return parser
예제 #4
0
def parse_options():
    """ Handle iotlab-robot command-line options with argparse """

    parent_parser = common.base_parser()
    # We create top level parser
    parser = argparse.ArgumentParser(parents=[parent_parser])

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # not required by default in Python3

    # Robot Commands

    # 'status' command
    status_parser = subparsers.add_parser('status', help='Get robot status')
    common.add_nodes_selection_list(status_parser)
    common.add_expid_arg(status_parser)

    # 'update' command
    up_parser = subparsers.add_parser('update', help='Update robot mobility')
    up_parser.add_argument('-n',
                           '--name',
                           dest='up_name',
                           required=True,
                           help='Update robot mobility')
    common.add_nodes_selection_list(up_parser)
    common.add_expid_arg(up_parser)

    # Mobility commands

    # 'get' command
    get_parser = subparsers.add_parser('get', help='Get robot mobilities')
    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument('-l',
                           '--list',
                           dest='list',
                           action='store_true',
                           help='Get circuits list')
    get_group.add_argument('-n', '--name', dest='get_name', help='Get circuit')
    get_parser.add_argument('--site',
                            action='append',
                            dest='get_selection',
                            type=lambda x: ('site', x),
                            help='filter list by site')
    get_parser.add_argument('--type',
                            action='append',
                            dest='get_selection',
                            type=lambda x: ('type', x),
                            help='filter list by circuit type')

    return parser
예제 #5
0
def parse_options():
    """Parse command line option."""
    parser = argparse.ArgumentParser()
    common.add_auth_arguments(parser, False)
    common.add_output_formatter(parser)
    # nodes list or exclude list
    common.add_nodes_selection_list(parser)
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version=iotlabwscli.__version__)
    common.add_expid_arg(parser)
    parser.add_argument('--verbose',
                        action='store_true',
                        help='Set verbose output')
    return parser
예제 #6
0
def parse_options():
    """ Handle node-cli command-line options with argparse """

    parent_parser = common.base_parser()
    # We create top level parser
    parser = argparse.ArgumentParser(parents=[parent_parser])

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # not required by default in Python3

    # Robot Commands

    # 'status' command
    status_parser = subparsers.add_parser('status', help='Get robot status')
    common.add_nodes_selection_list(status_parser)
    common.add_expid_arg(status_parser)

    # 'update' command
    up_parser = subparsers.add_parser('update', help='Update robot mobility')
    up_parser.add_argument('update_name_site',
                           help='Update robot mobility',
                           metavar='NAME,SITE',
                           type=name_site)
    common.add_nodes_selection_list(up_parser)
    common.add_expid_arg(up_parser)

    # Mobility commands

    # 'get' command
    get_parser = subparsers.add_parser('get', help='Get robot mobilities')
    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument('-l',
                           '--list',
                           dest='get_list',
                           action='store_true',
                           help='Get mobilities list')
    get_group.add_argument('-n',
                           '--name',
                           dest='get_name_site',
                           type=name_site,
                           metavar='NAME,SITE',
                           help='Get given mobility')

    return parser
예제 #7
0
def parse_options():
    """Parse command line option."""
    parent_parser = common.base_parser()
    # We create top level parser
    parser = argparse.ArgumentParser(parents=[parent_parser], )

    common.add_expid_arg(parser)

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # needed for python 3.

    # update-m3 parser
    update_parser = subparsers.add_parser('flash-m3',
                                          help='Flash the M3 firmware of A8 '
                                          'node')
    update_parser.add_argument('firmware', help='firmware elf path.')
    # nodes list or exclude list
    common.add_nodes_selection_list(update_parser)

    # reset-m3 parser
    reset_parser = subparsers.add_parser('reset-m3',
                                         help='reset the M3 of A8 node')
    # nodes list or exclude list
    common.add_nodes_selection_list(reset_parser)

    # wait-for-boot parser
    boot_parser = subparsers.add_parser('wait-for-boot',
                                        help='Waits until A8 node have boot')

    boot_parser.add_argument('--max-wait',
                             type=int,
                             default=120,
                             help='Maximum waiting delay for A8 nodes boot '
                             '(in seconds)')

    # nodes list or exclude list
    common.add_nodes_selection_list(boot_parser)

    parser.add_argument('--verbose',
                        action='store_true',
                        help='Set verbose output')

    return parser
예제 #8
0
def parser_add_wait_subparser(subparsers, expid_required=False):
    """Add wait experiment subparser and return it."""
    wait_parser = subparsers.add_parser(
        'wait', help='wait user experiment started',
        epilog=help_msgs.WAIT_EPILOG, formatter_class=RawTextHelpFormatter)

    common.add_expid_arg(wait_parser, required=expid_required)

    wait_parser.add_argument(
        '--state', default='Running',
        help="wait states `State1,State2` or Finished, default 'Running'")
    wait_parser.add_argument(
        '--step', default=5, type=int,
        help="Wait time in seconds between each check")
    wait_parser.add_argument(
        '--timeout', default=float('+inf'), type=float,
        help="Max time to wait in seconds")

    return wait_parser
예제 #9
0
def parser_add_script_subparser(subparsers):
    """Add suparser for 'script'."""
    _script_parser = subparsers.add_parser(
        'script', help='run script on sites frontends',
        epilog=help_msgs.SCRIPT_EPILOG, formatter_class=RawTextHelpFormatter)
    common.add_expid_arg(_script_parser)

    script_group = _script_parser.add_argument_group("Command")
    script_group = script_group.add_mutually_exclusive_group(required=True)

    script_group.add_argument('--run', type=run_site_association_from_str,
                              metavar=RUN_SITE_ASSOCIATION_METAVAR,
                              dest='run_script_site', nargs='+',
                              help="sites association with 'script'")
    script_group.add_argument('--kill', type=common.site_with_domain_checked,
                              metavar='site', dest='kill_sites',
                              nargs='*', help='sites list')
    script_group.add_argument('--status', type=common.site_with_domain_checked,
                              metavar='site', dest='status_sites',
                              nargs='*', help='sites list')
    return _script_parser
예제 #10
0
파일: robot.py 프로젝트: iot-lab/cli-tools
def parse_options():
    """ Handle iotlab-robot command-line options with argparse """

    parent_parser = common.base_parser()
    # We create top level parser
    parser = argparse.ArgumentParser(parents=[parent_parser])

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # not required by default in Python3

    # Robot Commands

    # 'status' command
    status_parser = subparsers.add_parser('status', help='Get robot status')
    common.add_nodes_selection_list(status_parser)
    common.add_expid_arg(status_parser)

    # 'update' command
    up_parser = subparsers.add_parser('update', help='Update robot mobility')
    up_parser.add_argument('update_name_site', help='Update robot mobility',
                           metavar='NAME,SITE', type=name_site)
    common.add_nodes_selection_list(up_parser)
    common.add_expid_arg(up_parser)

    # Mobility commands

    # 'get' command
    get_parser = subparsers.add_parser('get', help='Get robot mobilities')
    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument('-l', '--list', dest='get_list',
                           action='store_true', help='Get mobilities list')
    get_group.add_argument('-n', '--name', dest='get_name_site',
                           type=name_site, metavar='NAME,SITE',
                           help='Get given mobility')

    return parser
예제 #11
0
def parse_options():
    """ Handle iotlab-experiment command-line options with argparse """
    parent_parser = common.base_parser()

    # We create top level parser
    parser = ArgumentParser(
        description=EXPERIMENT_PARSER,
        parents=[parent_parser],
        epilog=help_msgs.PARSER_EPILOG.format(
            cli='experiment', option='submit'),
        formatter_class=RawTextHelpFormatter)

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # not required by default in Python3

    # ####### SUBMIT PARSER ###############
    parser_add_submit_subparser(subparsers)

    # ####### SCRIPT PARSER ###############
    parser_add_script_subparser(subparsers)

    # ####### STOP PARSER ###############
    stop_parser = subparsers.add_parser('stop', help='stop user experiment')
    common.add_expid_arg(stop_parser)

    # ####### GET PARSER ###############
    get_parser = subparsers.add_parser(
        'get',
        epilog=help_msgs.GET_EPILOG,
        help='get user\'s experiment',
        formatter_class=RawTextHelpFormatter)

    common.add_expid_arg(get_parser)

    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument(
        '-r', '--resources', dest='get_cmd', action='store_const',
        const='resources', help='get an experiment resources list')
    get_group.add_argument(
        '-ri', '--resources-id', dest='get_cmd', action='store_const',
        const='id', help=('get an experiment resources id list '
                          '(EXP_LIST format : 1-34+72)'))

    get_group.add_argument(
        '-s', '--exp-state', dest='get_cmd', action='store_const',
        const='state', help='get an experiment state')
    get_group.add_argument(
        '-st', '--start-time', dest='get_cmd', action='store_const',
        const='start', help='get expected experiment start time')
    get_group.add_argument(
        '-p', '--print', dest='get_cmd', action='store_const',
        const='', help='get an experiment submission')
    get_group.add_argument(
        '-a', '--archive', dest='get_cmd', action='store_const',
        const='data', help='get an experiment archive (tar.gz)')

    # --list with its options
    get_group.add_argument(
        '-l', '--list', dest='get_cmd', action='store_const',
        const='experiment_list', help='get user\'s experiment list')

    get_parser.add_argument('--offset', default=0, type=int,
                            help='experiment list start index')

    get_parser.add_argument('--limit', default=0, type=int,
                            help='experiment list maximum length')

    get_parser.add_argument('--state', help='experiment list state filter')

    get_group.add_argument('-e', '--experiments', dest='get_cmd',
                           action='store_const',
                           const='experiments',
                           help='get running experiments ids')
    get_parser.add_argument(
        '--active', action='store_true', default=False,
        help='experiments: include waiting/starting experiments')

    # ####### LOAD PARSER ###############
    load_parser = subparsers.add_parser('load', epilog=help_msgs.LOAD_EPILOG,
                                        help='load and submit user experiment',
                                        formatter_class=RawTextHelpFormatter)

    load_parser.add_argument('-f', '--file', dest='path_file',
                             metavar='EXP_JSON', required=True,
                             help='experiment path file')

    _load_list_help = ('file path for firmware/script/... if not in'
                       ' current directory.')

    load_parser.add_argument('-l', '--list', metavar='FILEPATH',
                             dest='files', default=[],
                             type=(lambda s: s.split(',')), action='append',
                             help=_load_list_help)

    # ####### RELOAD PARSER ###############
    reload_parser = subparsers.add_parser('reload',
                                          epilog=help_msgs.RELOAD_EPILOG,
                                          help='reload user experiment',
                                          formatter_class=RawTextHelpFormatter)
    common.add_expid_arg(reload_parser, required=True)

    _parser_add_duration_and_reservation(reload_parser,
                                         duration_required=False)

    # ####### INFO PARSER ###############
    info_parser = subparsers.add_parser('info', epilog=help_msgs.INFO_EPILOG,
                                        help='resources description list',
                                        formatter_class=RawTextHelpFormatter)

    info_parser.add_argument('--site',
                             action='append', dest='info_selection',
                             type=lambda x: ('site', x),
                             help='resources list filter by site')
    info_parser.add_argument('--archi',
                             action='append', dest='info_selection',
                             type=lambda x: ('archi', x),
                             help='resources list filter by architecture')
    info_parser.add_argument('--state', action='append', dest='info_selection',
                             type=lambda x: ('state', x),
                             help='resources list filter by state')

    # subcommand
    info_group = info_parser.add_mutually_exclusive_group(required=True)
    info_group.add_argument('-l', '--list', dest='list_id',
                            action='store_false', help='list resources')
    info_group.add_argument('-li', '--list-id', dest='list_id',
                            action='store_true',
                            help=('resources id list by archi and state '
                                  '(EXP_LIST format : 1-34+72)'))

    # ####### WAIT PARSER ###############
    parser_add_wait_subparser(subparsers, expid_required=False)

    return parser
예제 #12
0
def parse_options():
    """Parse command line option."""
    parent_parser = argparse.ArgumentParser(add_help=False)
    common.add_auth_arguments(parent_parser, False)
    parent_parser.add_argument('-v',
                               '--version',
                               action='version',
                               version=iotlabsshcli.__version__)

    # We create top level parser
    parser = argparse.ArgumentParser(parents=[parent_parser], )

    common.add_expid_arg(parser)
    common.add_output_formatter(parser)

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # needed for python 3.

    # pylint: disable=super-with-arguments
    class DeprecateHelpFormatter(argparse.HelpFormatter):
        """ Add drepecated help formatter """
        def add_usage(self, usage, actions, groups, prefix=None):
            # self._prog = iotlab-ssh flash-m3 | reset-m3
            old_cmd = self._prog.split()[-1]
            new_cmd = old_cmd.split('-')[0]
            deprecate_warn_cmd(old_cmd, new_cmd, 20)
            return super(DeprecateHelpFormatter,
                         self).add_usage(usage, actions, groups, prefix)

    update_parser = subparsers.add_parser('flash',
                                          parents=[parent_parser],
                                          help='Flash node\'s '
                                          'co-microcontroller')
    update_parser.add_argument('firmware', help='firmware path.')
    # nodes list or exclude list
    common.add_nodes_selection_list(update_parser)

    # reset parser
    reset_parser = subparsers.add_parser('reset',
                                         parents=[parent_parser],
                                         help='Reset node\'s '
                                         'co-microcontroller')
    # nodes list or exclude list
    common.add_nodes_selection_list(reset_parser)

    # wait-for-boot parser
    boot_parser = subparsers.add_parser('wait-for-boot',
                                        parents=[parent_parser],
                                        help='Waits until Linux nodes '
                                        'have boot')
    boot_parser.add_argument('--max-wait',
                             type=int,
                             default=120,
                             help='Maximum waiting delay for nodes boot '
                             '(in seconds)')
    # nodes list or exclude list
    common.add_nodes_selection_list(boot_parser)

    # run-script parser
    run_script_parser = subparsers.add_parser('run-script',
                                              parents=[parent_parser],
                                              help='Run a script in '
                                              'background on Linux '
                                              'nodes')
    run_script_parser.add_argument('script', help='script path.')
    run_script_parser.add_argument('--frontend',
                                   action='store_true',
                                   help='Execution on SSH frontend')
    # nodes list or exclude list
    common.add_nodes_selection_list(run_script_parser)

    # run-cmd parser
    run_cmd_parser = subparsers.add_parser('run-cmd',
                                           parents=[parent_parser],
                                           help='Run a command on Linux nodes')
    run_cmd_parser.add_argument('cmd', help='Command')
    run_cmd_parser.add_argument('--frontend',
                                action='store_true',
                                help='Execution on SSH frontend')
    # nodes list or exclude list
    common.add_nodes_selection_list(run_cmd_parser)

    # copy-file parser
    copy_file_parser = subparsers.add_parser('copy-file',
                                             parents=[parent_parser],
                                             help='Copy file on'
                                             ' SSH frontend directory'
                                             ' (~/shared/.iotlabsshcli)')
    copy_file_parser.add_argument('file_path', help='File path')
    # nodes list or exclude list
    common.add_nodes_selection_list(copy_file_parser)

    parser.add_argument('--verbose',
                        action='store_true',
                        help='Set verbose output')

    # update-m3 parser
    help_msg = 'DEPRECATED: use flash subcommand instead'
    update_m3_parser = \
        subparsers.add_parser('flash-m3', help=help_msg,
                              parents=[parent_parser],
                              formatter_class=DeprecateHelpFormatter)
    update_m3_parser.add_argument('firmware', help='firmware path.')
    # nodes list or exclude list
    common.add_nodes_selection_list(update_m3_parser)

    # reset-m3 parser
    help_msg = 'DEPRECATED: use reset subcommand instead'
    reset_m3_parser = \
        subparsers.add_parser('reset-m3', help=help_msg,
                              parents=[parent_parser],
                              formatter_class=DeprecateHelpFormatter)
    # nodes list or exclude list
    common.add_nodes_selection_list(reset_m3_parser)

    return parser
예제 #13
0
def parse_options():
    """ Handle iotlab-node command-line options with argparse """

    parent_parser = common.base_parser()
    # We create top level parser
    parser = argparse.ArgumentParser(
        description=NODE_PARSER,
        parents=[parent_parser], formatter_class=RawTextHelpFormatter,
        epilog=(help_msgs.PARSER_EPILOG.format(cli='node', option='--update') +
                NODE_EPILOG),
    )

    common.add_expid_arg(parser)

    # command
    # argument with parameter can't both set 'command' and set argument value
    # so save argument, and command will be left to 'with_arguments'
    parser.set_defaults(command='with_argument')
    cmd_group = parser.add_mutually_exclusive_group(required=True)

    cmd_group.add_argument(
        '-sta', '--start', help='start command', const='start',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '-sto', '--stop', help='stop command', const='stop',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '-r', '--reset', help='reset command', const='reset',
        dest='command', action='store_const')
    cmd_group.add_argument(
        '--update-idle', help='flash idle firmware', const='update-idle',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '--debug-start', help='start debugger', const='debug-start',
        dest='command', action='store_const')

    cmd_group.add_argument(
        '--debug-stop', help='stop debugger', const='debug-stop',
        dest='command', action='store_const')

    cmd_group.add_argument('-up', '--update',
                           dest='firmware_path', default=None,
                           help='flash firmware command with path file')

    cmd_group.add_argument('--profile', '--update-profile',
                           dest='profile_name', default=None,
                           help='change nodes current monitoring profile')
    cmd_group.add_argument('--profile-load',
                           dest='profile_path', default=None,
                           help=('change nodes current monitoring profile'
                                 ' with provided JSON'))
    cmd_group.add_argument('--profile-reset',
                           dest='command', const='profile-reset',
                           action='store_const',
                           help='reset to default no monitoring profile')

    # nodes list or exclude list
    common.add_nodes_selection_list(parser)

    return parser
예제 #14
0
def parse_options():
    """Parse command line option."""
    parent_parser = argparse.ArgumentParser(add_help=False)
    common.add_auth_arguments(parent_parser, False)
    parent_parser.add_argument('-v', '--version',
                               action='version',
                               version=iotlabsshcli.__version__)

    # We create top level parser
    parser = argparse.ArgumentParser(
        parents=[parent_parser],
    )

    common.add_expid_arg(parser)
    common.add_output_formatter(parser)

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # needed for python 3.

    # update-m3 parser
    update_parser = subparsers.add_parser('flash-m3',
                                          parents=[parent_parser],
                                          help='Flash the M3 firmware of A8 '
                                               'nodes')
    update_parser.add_argument('firmware', help='firmware elf path.')
    # nodes list or exclude list
    common.add_nodes_selection_list(update_parser)

    # reset-m3 parser
    reset_parser = subparsers.add_parser('reset-m3',
                                         parents=[parent_parser],
                                         help='Reset the M3 of A8 nodes')
    # nodes list or exclude list
    common.add_nodes_selection_list(reset_parser)

    # wait-for-boot parser
    boot_parser = subparsers.add_parser('wait-for-boot',
                                        parents=[parent_parser],
                                        help='Waits until A8 nodes have boot')
    boot_parser.add_argument('--max-wait',
                             type=int,
                             default=120,
                             help='Maximum waiting delay for A8 nodes boot '
                                  '(in seconds)')
    # nodes list or exclude list
    common.add_nodes_selection_list(boot_parser)

    # run-script parser
    run_script_parser = subparsers.add_parser('run-script',
                                              parents=[parent_parser],
                                              help='Run a script in background'
                                                   ' on A8 nodes')
    run_script_parser.add_argument('script', help='script path.')
    run_script_parser.add_argument('--frontend', action='store_true',
                                   help='Execution on SSH frontend')
    # nodes list or exclude list
    common.add_nodes_selection_list(run_script_parser)

    # run-cmd parser
    run_cmd_parser = subparsers.add_parser('run-cmd',
                                           parents=[parent_parser],
                                           help='Run a command on A8 nodes')
    run_cmd_parser.add_argument('cmd', help='Command')
    run_cmd_parser.add_argument('--frontend', action='store_true',
                                help='Execution on SSH frontend')
    # nodes list or exclude list
    common.add_nodes_selection_list(run_cmd_parser)

    # copy-file parser
    copy_file_parser = subparsers.add_parser('copy-file',
                                             parents=[parent_parser],
                                             help='Copy file on'
                                                  ' SSH frontend directory'
                                                  ' (~/A8/.iotlabsshcli/)')
    copy_file_parser.add_argument('file_path', help='File path')
    # nodes list or exclude list
    common.add_nodes_selection_list(copy_file_parser)

    parser.add_argument('--verbose',
                        action='store_true',
                        help='Set verbose output')

    return parser
예제 #15
0
def parse_options():
    """ Handle iotlab-experiment command-line options with argparse """
    parent_parser = common.base_parser()

    # We create top level parser
    parser = ArgumentParser(description=EXPERIMENT_PARSER,
                            parents=[parent_parser],
                            epilog=help_msgs.PARSER_EPILOG.format(
                                cli='experiment', option='submit'),
                            formatter_class=RawTextHelpFormatter)

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # not required by default in Python3

    # ####### SUBMIT PARSER ###############
    parser_add_submit_subparser(subparsers)

    # ####### SCRIPT PARSER ###############
    parser_add_script_subparser(subparsers)

    # ####### STOP PARSER ###############
    stop_parser = subparsers.add_parser('stop', help='stop user experiment')
    common.add_expid_arg(stop_parser)

    # ####### GET PARSER ###############
    get_parser = subparsers.add_parser('get',
                                       epilog=help_msgs.GET_EPILOG,
                                       help='get user\'s experiment',
                                       formatter_class=RawTextHelpFormatter)

    common.add_expid_arg(get_parser)

    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument('-r',
                           '--resources',
                           dest='get_cmd',
                           action='store_const',
                           const='resources',
                           help='get an experiment resources list')
    get_group.add_argument('-ri',
                           '--resources-id',
                           dest='get_cmd',
                           action='store_const',
                           const='id',
                           help=('get an experiment resources id list '
                                 '(EXP_LIST format : 1-34+72)'))

    get_group.add_argument('-s',
                           '--exp-state',
                           dest='get_cmd',
                           action='store_const',
                           const='state',
                           help='get an experiment state')
    get_group.add_argument('-st',
                           '--start-time',
                           dest='get_cmd',
                           action='store_const',
                           const='start',
                           help='get expected experiment start time')
    get_group.add_argument('-p',
                           '--print',
                           dest='get_cmd',
                           action='store_const',
                           const='',
                           help='get an experiment submission')
    get_group.add_argument('-a',
                           '--archive',
                           dest='get_cmd',
                           action='store_const',
                           const='data',
                           help='get an experiment archive (tar.gz)')

    # --list with its options
    get_group.add_argument('-l',
                           '--list',
                           dest='get_cmd',
                           action='store_const',
                           const='experiment_list',
                           help='get user\'s experiment list')

    get_parser.add_argument('--offset',
                            default=0,
                            type=int,
                            help='experiment list start index')

    get_parser.add_argument('--limit',
                            default=0,
                            type=int,
                            help='experiment list maximum length')

    get_parser.add_argument('--state', help='experiment list state filter')

    get_group.add_argument('-e',
                           '--experiments',
                           dest='get_cmd',
                           action='store_const',
                           const='experiments',
                           help='get running experiments ids')
    get_parser.add_argument(
        '--active',
        action='store_true',
        default=False,
        help='experiments: include waiting/starting experiments')

    # ####### LOAD PARSER ###############
    load_parser = subparsers.add_parser('load',
                                        epilog=help_msgs.LOAD_EPILOG,
                                        help='load and submit user experiment',
                                        formatter_class=RawTextHelpFormatter)

    load_parser.add_argument('-f',
                             '--file',
                             dest='path_file',
                             metavar='EXP_JSON',
                             required=True,
                             help='experiment path file')

    _load_list_help = ('file path for firmware/script/... if not in'
                       ' current directory.')

    load_parser.add_argument('-l',
                             '--list',
                             metavar='FILEPATH',
                             dest='files',
                             default=[],
                             type=(lambda s: s.split(',')),
                             action='append',
                             help=_load_list_help)

    # ####### RELOAD PARSER ###############
    reload_parser = subparsers.add_parser('reload',
                                          epilog=help_msgs.RELOAD_EPILOG,
                                          help='reload user experiment',
                                          formatter_class=RawTextHelpFormatter)
    common.add_expid_arg(reload_parser, required=True)

    _parser_add_duration_and_reservation(reload_parser,
                                         duration_required=False)

    # ####### INFO PARSER ###############
    info_parser = subparsers.add_parser('info',
                                        epilog=help_msgs.INFO_EPILOG,
                                        help='resources description list',
                                        formatter_class=RawTextHelpFormatter)

    info_parser.add_argument('--site',
                             action='append',
                             dest='info_selection',
                             type=lambda x: ('site', x),
                             help='resources list filter by site')
    info_parser.add_argument('--archi',
                             action='append',
                             dest='info_selection',
                             type=lambda x: ('archi', x),
                             help='resources list filter by architecture')
    info_parser.add_argument('--state',
                             action='append',
                             dest='info_selection',
                             type=lambda x: ('state', x),
                             help='resources list filter by state')

    # subcommand
    info_group = info_parser.add_mutually_exclusive_group(required=True)
    info_group.add_argument('-l',
                            '--list',
                            dest='list_id',
                            action='store_false',
                            help='list resources')
    info_group.add_argument('-li',
                            '--list-id',
                            dest='list_id',
                            action='store_true',
                            help=('resources id list by archi and state '
                                  '(EXP_LIST format : 1-34+72)'))

    # ####### WAIT PARSER ###############
    parser_add_wait_subparser(subparsers, expid_required=False)

    return parser
예제 #16
0
def parse_options():
    """ Handle experiment-cli command-line options with argparse """
    parent_parser = common.base_parser()

    # We create top level parser
    parser = ArgumentParser(
        description=EXPERIMENT_PARSER,
        parents=[parent_parser],
        epilog=help_msgs.PARSER_EPILOG.format(cli="experiment", option="submit"),
        formatter_class=RawTextHelpFormatter,
    )

    subparsers = parser.add_subparsers(dest="command")
    subparsers.required = True  # not required by default in Python3

    submit_parser = subparsers.add_parser(
        "submit", help="submit user experiment", epilog=help_msgs.SUBMIT_EPILOG, formatter_class=RawTextHelpFormatter
    )

    submit_parser.add_argument(
        "-l",
        "--list",
        action="append",
        dest="nodes_list",
        required=True,
        type=exp_resources_from_str,
        help="experiment list",
    )

    submit_parser.add_argument("-n", "--name", help="experiment name")

    submit_parser.add_argument("-d", "--duration", required=True, type=int, help="experiment duration in minutes")

    submit_parser.add_argument(
        "-r",
        "--reservation",
        type=int,
        help=("experiment schedule starting : seconds " "since 1970-01-01 00:00:00 UTC"),
    )

    submit_parser.add_argument(
        "-p", "--print", dest="print_json", action="store_true", help="print experiment submission"
    )

    # ####### STOP PARSER ###############
    stop_parser = subparsers.add_parser("stop", help="stop user experiment")
    common.add_expid_arg(stop_parser)

    # ####### GET PARSER ###############
    get_parser = subparsers.add_parser(
        "get", epilog=help_msgs.GET_EPILOG, help="get user's experiment", formatter_class=RawTextHelpFormatter
    )

    common.add_expid_arg(get_parser)

    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument(
        "-r",
        "--resources",
        dest="get_cmd",
        action="store_const",
        const="resources",
        help="get an experiment resources list",
    )
    get_group.add_argument(
        "-ri",
        "--resources-id",
        dest="get_cmd",
        action="store_const",
        const="id",
        help=("get an experiment resources id list " "(EXP_LIST format : 1-34+72)"),
    )

    get_group.add_argument(
        "-s", "--exp-state", dest="get_cmd", action="store_const", const="state", help="get an experiment state"
    )
    get_group.add_argument(
        "-st",
        "--start-time",
        dest="get_cmd",
        action="store_const",
        const="start",
        help="get expected experiment start time",
    )
    get_group.add_argument(
        "-p", "--print", dest="get_cmd", action="store_const", const="", help="get an experiment submission"
    )
    get_group.add_argument(
        "-a", "--archive", dest="get_cmd", action="store_const", const="data", help="get an experiment archive (tar.gz)"
    )

    # --list with its options
    get_group.add_argument(
        "-l", "--list", dest="get_cmd", action="store_const", const="experiment_list", help="get user's experiment list"
    )

    get_parser.add_argument("--offset", default=0, type=int, help="experiment list start index")

    get_parser.add_argument("--limit", default=0, type=int, help="experiment list lenght")

    get_parser.add_argument("--state", help="experiment list state filter")

    # ####### LOAD PARSER ###############
    load_parser = subparsers.add_parser(
        "load",
        epilog=help_msgs.LOAD_EPILOG,
        help="load and submit user experiment",
        formatter_class=RawTextHelpFormatter,
    )

    load_parser.add_argument("-f", "--file", dest="path_file", required=True, help="experiment path file")

    load_parser.add_argument(
        "-l",
        "--list",
        dest="firmware_list",
        default=[],
        type=(lambda s: s.split(",")),
        help="comma separated firmware(s) path list",
    )

    # ####### INFO PARSER ###############
    info_parser = subparsers.add_parser(
        "info", epilog=help_msgs.INFO_EPILOG, help="resources description list", formatter_class=RawTextHelpFormatter
    )

    info_parser.add_argument("--site", help="resources list filter by site")
    # subcommand
    info_group = info_parser.add_mutually_exclusive_group(required=True)
    info_group.add_argument("-l", "--list", dest="list_id", action="store_false", help="list resources")
    info_group.add_argument(
        "-li",
        "--list-id",
        dest="list_id",
        action="store_true",
        help=("resources id list by archi and state " "(EXP_LIST format : 1-34+72)"),
    )

    # ####### WAIT PARSER ###############
    wait_parser = subparsers.add_parser(
        "wait", help="wait user experiment started", epilog=help_msgs.WAIT_EPILOG, formatter_class=RawTextHelpFormatter
    )

    common.add_expid_arg(wait_parser)

    wait_parser.add_argument(
        "--state", default="Running", help="wait states `State1,State2` or Finished, default 'Running'"
    )
    wait_parser.add_argument("--step", default=5, type=int, help="Wait time in seconds between each check")
    wait_parser.add_argument("--timeout", default=float("+inf"), type=float, help="Max time to wait in seconds")

    return parser
예제 #17
0
def parse_options():
    """ Handle experiment-cli command-line options with argparse """
    parent_parser = common.base_parser()

    # We create top level parser
    parser = ArgumentParser(description=EXPERIMENT_PARSER,
                            parents=[parent_parser],
                            epilog=help_msgs.PARSER_EPILOG.format(
                                cli='experiment', option='submit'),
                            formatter_class=RawTextHelpFormatter)

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True  # not required by default in Python3

    submit_parser = subparsers.add_parser('submit',
                                          help='submit user experiment',
                                          epilog=help_msgs.SUBMIT_EPILOG,
                                          formatter_class=RawTextHelpFormatter)

    submit_parser.add_argument('-l',
                               '--list',
                               action='append',
                               dest='nodes_list',
                               required=True,
                               type=exp_resources_from_str,
                               help="experiment list")

    submit_parser.add_argument('-n', '--name', help='experiment name')

    submit_parser.add_argument('-d',
                               '--duration',
                               required=True,
                               type=int,
                               help='experiment duration in minutes')

    submit_parser.add_argument('-r',
                               '--reservation',
                               type=int,
                               help=('experiment schedule starting : seconds '
                                     'since 1970-01-01 00:00:00 UTC'))

    submit_parser.add_argument('-p',
                               '--print',
                               dest='print_json',
                               action='store_true',
                               help='print experiment submission')

    # ####### STOP PARSER ###############
    stop_parser = subparsers.add_parser('stop', help='stop user experiment')
    common.add_expid_arg(stop_parser)

    # ####### GET PARSER ###############
    get_parser = subparsers.add_parser('get',
                                       epilog=help_msgs.GET_EPILOG,
                                       help='get user\'s experiment',
                                       formatter_class=RawTextHelpFormatter)

    common.add_expid_arg(get_parser)

    get_group = get_parser.add_mutually_exclusive_group(required=True)
    get_group.add_argument('-r',
                           '--resources',
                           dest='get_cmd',
                           action='store_const',
                           const='resources',
                           help='get an experiment resources list')
    get_group.add_argument('-ri',
                           '--resources-id',
                           dest='get_cmd',
                           action='store_const',
                           const='id',
                           help=('get an experiment resources id list '
                                 '(EXP_LIST format : 1-34+72)'))

    get_group.add_argument('-s',
                           '--exp-state',
                           dest='get_cmd',
                           action='store_const',
                           const='state',
                           help='get an experiment state')
    get_group.add_argument('-st',
                           '--start-time',
                           dest='get_cmd',
                           action='store_const',
                           const='start',
                           help='get expected experiment start time')
    get_group.add_argument('-p',
                           '--print',
                           dest='get_cmd',
                           action='store_const',
                           const='',
                           help='get an experiment submission')
    get_group.add_argument('-a',
                           '--archive',
                           dest='get_cmd',
                           action='store_const',
                           const='data',
                           help='get an experiment archive (tar.gz)')

    # --list with its options
    get_group.add_argument('-l',
                           '--list',
                           dest='get_cmd',
                           action='store_const',
                           const='experiment_list',
                           help='get user\'s experiment list')

    get_parser.add_argument('--offset',
                            default=0,
                            type=int,
                            help='experiment list start index')

    get_parser.add_argument('--limit',
                            default=0,
                            type=int,
                            help='experiment list lenght')

    get_parser.add_argument('--state', help='experiment list state filter')

    # ####### LOAD PARSER ###############
    load_parser = subparsers.add_parser('load',
                                        epilog=help_msgs.LOAD_EPILOG,
                                        help='load and submit user experiment',
                                        formatter_class=RawTextHelpFormatter)

    load_parser.add_argument('-f',
                             '--file',
                             dest='path_file',
                             required=True,
                             help='experiment path file')

    load_parser.add_argument('-l',
                             '--list',
                             dest='firmware_list',
                             default=[],
                             type=(lambda s: s.split(',')),
                             help='comma separated firmware(s) path list')

    # ####### INFO PARSER ###############
    info_parser = subparsers.add_parser('info',
                                        epilog=help_msgs.INFO_EPILOG,
                                        help='resources description list',
                                        formatter_class=RawTextHelpFormatter)

    info_parser.add_argument('--site', help='resources list filter by site')
    # subcommand
    info_group = info_parser.add_mutually_exclusive_group(required=True)
    info_group.add_argument('-l',
                            '--list',
                            dest='list_id',
                            action='store_false',
                            help='list resources')
    info_group.add_argument('-li',
                            '--list-id',
                            dest='list_id',
                            action='store_true',
                            help=('resources id list by archi and state '
                                  '(EXP_LIST format : 1-34+72)'))

    # ####### WAIT PARSER ###############
    wait_parser = subparsers.add_parser('wait',
                                        help='wait user experiment started',
                                        epilog=help_msgs.WAIT_EPILOG,
                                        formatter_class=RawTextHelpFormatter)

    common.add_expid_arg(wait_parser)

    wait_parser.add_argument(
        '--state',
        default='Running',
        help="wait states `State1,State2` or Finished, default 'Running'")
    wait_parser.add_argument('--step',
                             default=5,
                             type=int,
                             help="Wait time in seconds between each check")
    wait_parser.add_argument('--timeout',
                             default=float('+inf'),
                             type=float,
                             help="Max time to wait in seconds")

    return parser