blob: 335e9440891f5cdadbffc3bf7fb57be15a4199d5 [file] [log] [blame]
Monty Taylorf45f6ca2012-05-01 17:11:48 -04001import argparse
2import paramiko
3import json
4
5parser = argparse.ArgumentParser()
6parser.add_argument("--host", dest="host", default="review.openstack.org",
7 help="gerrit host to connect to")
8parser.add_argument("--port", dest="port", action='store', type=int,
9 default=29418, help="gerrit port to connect to")
10parser.add_argument("groups", nargs=1)
11
12options = parser.parse_args()
13
14
15client = paramiko.SSHClient()
16client.load_system_host_keys()
17client.set_missing_host_key_policy(paramiko.WarningPolicy())
18client.connect(options.host, port=options.port)
19
20group = options.groups[0]
21query = "select group_uuid from account_groups where name = '%s'" % group
22command = 'gerrit gsql --format JSON -c "%s"' % query
23stdin, stdout, stderr = client.exec_command(command)
24
25for line in stdout:
26 row = json.loads(line)
27 if row['type'] == 'row':
28 print row['columns']['group_uuid']
29 ret = stdout.channel.recv_exit_status()