예제 #1
0
def main(args):
    agent = client.RestAgent(reactor, args.apiurl)

    # get first
    path = 'slaves/%s?byname=1' % args.slave
    slave = yield agent.restRequest('GET', path, {})
    if not slave:
        raise exceptions.CmdlineError("No slave found named '%s'." %
                                      args.slave)
    assert slave['name'] == args.slave
    slaveid = slave['slaveid']
    if args.message is None:
        if slave['notes']:
            print slave['notes']
        return
    else:
        print >> sys.stderr, "previous slave notes: '%s'" % slave['notes']

    # set the notes
    set_result = yield agent.restRequest('PUT', 'slaves/%d' % slaveid,
                                         {'notes': args.message})
    success = set_result.get('success')
    if not success:
        raise exceptions.CmdlineError("Operation failed on server.")
    print >> sys.stderr, "notes set to '%s'" % args.message
예제 #2
0
파일: disable.py 프로젝트: tsl143/browser-f
def set_enabled(args, slavename, enabled, message):
    """
    Set the enabled status for a slave, and optionally (if C{message} is not
    None) the notes as well.
    """
    agent = client.RestAgent(reactor, args.apiurl)

    # first get the slaveid
    path = 'slaves/%s?byname=1' % slavename
    slave = yield agent.restRequest('GET', path, {})
    if not slave:
        raise exceptions.CmdlineError("No slave found named '%s'." % slavename)
    assert slave['name'] == slavename
    slaveid = slave['slaveid']
    if slave['notes']:
        print >> sys.stderr, "previous slave notes: '%s'" % slave['notes']

    # then set its state, if not already set
    if ((enabled and not slave['enabled'])
            or (not enabled and slave['enabled'])):
        to_set = {'enabled': enabled}
        if message is not None:
            to_set['notes'] = message
        set_result = yield agent.restRequest('PUT', 'slaves/%d' % slaveid,
                                             to_set)
        success = set_result.get('success')
        if not success:
            raise exceptions.CmdlineError("Operation failed on server.")
        print >> sys.stderr, "%s %s" % (slavename, bool_to_word(enabled))
    else:
        print >> sys.stderr, "%s is already %s" % (slavename,
                                                   bool_to_word(enabled))
예제 #3
0
def main(args):
    agent = client.RestAgent(reactor, args.apiurl)

    for slave in args.slave:
        path = 'gettac/%s' % slave
        res = yield agent.restRequest('GET', path, {})

        if not res.get('success'):
            raise exceptions.CmdlineError(
                "could not generate TAC for %s" % slave)

        print res['tac']
예제 #4
0
def main(args):
    agent = client.RestAgent(reactor, args.apiurl)

    # first get the slaveid
    path = 'slaves/%s?byname=1' % args.slave
    slave = yield agent.restRequest('GET', path, {})
    if not slave:
        raise exceptions.CmdlineError(
                "No slave found named '%s'." % args.slave)
    assert slave['name'] == args.slave
    slaveid = slave['slaveid']

    if args.unlock:
        if not slave['locked_masterid']:
            raise exceptions.CmdlineError("Slave is not locked")

        set_result = yield agent.restRequest('PUT',
                    'slaves/%d' % slaveid,
                    { 'locked_masterid' : None })
        success = set_result.get('success')
        if not success:
            raise exceptions.CmdlineError("Operation failed on server.")

        print >>sys.stderr, "Slave '%s' unlocked" % args.slave
    else:
        # get the masterid
        path = 'masters/%s?byname=1' % args.master
        master = yield agent.restRequest('GET', path, {})
        if not master:
            raise exceptions.CmdlineError(
                    "No master found named '%s'." % args.master)
        masterid = master['masterid']

        set_result = yield agent.restRequest('PUT',
                    'slaves/%d' % slaveid,
                    { 'locked_masterid' : masterid })
        success = set_result.get('success')
        if not success:
            raise exceptions.CmdlineError("Operation failed on server.")

        print >>sys.stderr, "Locked '%s' to '%s' (%s:%s)" % (args.slave,
            master['nickname'], master['fqdn'], master['pb_port'])