#!/usr/bin/env python

from getters import wait_for_first
import sys
import argparse

parser = argparse.ArgumentParser(description='Lock a single server')
parser.add_argument('pool', nargs='?', help='The pool to lock from', default="")
parser.add_argument('--reason', dest='reason', 
                   help='Reason for the lock (optional)')

args = parser.parse_args()

pool = args.pool
def is_server_in_pool(item):
    try:
        return bool(item.get("POOL", "") == pool)
    except:
        return False


server_data, lock = wait_for_first(is_server_in_pool, args.reason)

for item in server_data.items():
    print '%s=%s' % item

print "LOCK=%s" % lock
