Example #1
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],
        formatter_class=RawTextHelpFormatter,
        epilog=(help_msgs.PARSER_EPILOG.format(cli="robot", option="--status"))
        # + # help_msgs.COMMAND_EPILOG),  # TODO
    )

    parser.add_argument("-i", "--id", dest="experiment_id", type=int, help="experiment id submission")

    # command
    cmd_group = parser.add_mutually_exclusive_group(required=True)

    cmd_group.add_argument(
        "-s", "--status", help="Get robot status", const="status", dest="command", action="store_const"
    )

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

    return parser
Example #2
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(
        description=NODE_PARSER,
        parents=[parent_parser], formatter_class=RawTextHelpFormatter,
        epilog=(help_msgs.PARSER_EPILOG.format(cli='node', option='--update') +
                NODE_EPILOG),
    )

    parser.add_argument(
        '-i', '--id', dest='experiment_id', type=int,
        help='experiment id submission')

    # 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
Example #3
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
Example #4
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
Example #5
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
Example #6
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('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
Example #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
Example #8
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
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
Example #10
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