示例#1
0
        if not target_device:  # We couldn't match that up with a udev identified device.
            sys.exit('smart2json: Invalid device node: %s' % options.device)

    else:  # Otherwise, query the user which device node to operate on.
        print('Select a device node:\n')
        for i in range(0, len(devices)):
            print(' %d) %s' % (i + 1, devices[i]))
            for child in devices[i].children:
                print(' \- %s' % child)
            print('')

        def select(i):
            if 1 <= i <= len(devices):
                return devices[i - 1]

        target_device = prompt('Choice: ', lambda i: select(int(i)))

    # We now have all of the device-specific information we need to operate.
    print('Selected:\n%s' % target_device)

    # Define a quick inline function to respond to both long and short yes/no.
    def select_yes_no(i):
        i = i.lower()
        if i in ('y', 'yes'):
            return 'y'
        elif i in ('n', 'no'):
            return 'n'

    # Sanity check, we're gonna operate on your device in a second.
    if options.force or prompt(
                    'WARNING: continuing on device %s may result in data loss!\nContinue? [Y/N]: '
示例#2
0
    # Define command line options we'll respond to.
    parser.add_option('-l', '--list', action='store_true', dest='do_list', help='List known objects.')
    parser.add_option('-d', '--dead', action='store_true', dest='do_dead', help='Mark known objects as dead.')
    parser.add_option('-t', '--target', action='store', dest='target',
                      help='Manually select a target. Omitting this option will present a menu of valid nodes.')
    parser.add_option('-f', '--force', action='store_true', dest='force',
                      help='Force the action. This option will not prompt for confirmation before continuing.')

    # If -h or --help are passed, the above will be displayed.
    options, args = parser.parse_args()


    # Sanity check, we're gonna operate on your device in a second.
    if options.force or prompt(
                    'WARNING: continuing on target %s may result in data loss!\nContinue? [Y/N]: '
                    % options.target, select_yes_no) == 'y':

        hostname = "localhost"
        manager = rdbtools.ClusterAccess([(str(hostname), 8181)])
        # Do Stuff Here
        if options.do_list:
            manager.print_machines()
            #print(manager)
        # And Here
        if options.do_dead:
            if options.target:
                manager.declare_machine_dead(options.target)
            else:
                sys.exit("\nrdbutil: Require a target for that action.")