def do_summary(ctx):
lockd = collections.defaultdict(lambda: [0, 0, 'unknown'])
- for l in list_locks(machine_type=ctx.machine_type):
+ if ctx.machine_type:
+ locks = list_locks(machine_type=ctx.machine_type)
+ else:
+ locks = list_locks()
+ for l in locks:
who = l['locked_by'] if l['locked'] == 1 \
else '(free)', l['machine_type']
lockd[who][0] += 1
def get_arch(machine_type):
"""
Based on a given machine_type, return its architecture by querying the lock
- server. Sound expensive? It is!
+ server.
:returns: A string or None
"""
- locks = lock.list_locks()
- for machine in locks:
- if machine['type'] == machine_type:
- arch = machine['arch']
- return arch
- return None
+ result = lock.list_locks(machine_type=machine_type, count=1)
+ if not result:
+ log.warn("No machines found with machine_type %s!", machine_type)
+ else:
+ return result[0]['arch']
class Placeholder(object):