-
Notifications
You must be signed in to change notification settings - Fork 0
/
gg-jobs
executable file
·51 lines (39 loc) · 1.25 KB
/
gg-jobs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""A tool to list available images, doesn't need any arguments"""
from datetime import datetime
import getopt
import sys
from GoGridManager import GoGridManager
from GoGridClient import Error403
if __name__ == "__main__":
account = "default"
num_items = 20
try:
opts, args = getopt.getopt(sys.argv[1:], "p:n:")
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
for o, a in opts:
if o == "-p":
account = a
elif o == "-n":
num_items = a
manager = GoGridManager(account=account)
if len(args) < 1:
# list mode: display list of items
try:
jobs = manager.get_jobs(num_items=num_items)
except (Error403,), e:
print e
sys.exit(2)
for job in jobs:
print "%s\t%s\t%s\t%s" % (job.id, job.descr,
job.hist[-1].state ,job.owner)
else:
job_id = args[0]
job = manager.get_job(job_id)
print "%s\t%s\t%s" % (job.id, job.descr, job.owner)
print "Job States:"
for hist_item in job.hist:
print "%12s\t%s" % (hist_item.state,
str(datetime.fromtimestamp(float(hist_item.updatedon)/1000)))