Revision 191712c0
b/scripts/gnt-job | ||
---|---|---|
114 | 114 |
return 0 |
115 | 115 |
|
116 | 116 |
|
117 |
def ShowJobs(opts, args): |
|
118 |
"""List the jobs |
|
119 |
|
|
120 |
""" |
|
121 |
def format(level, text): |
|
122 |
"""Display the text indented.""" |
|
123 |
print "%s%s" % (" " * level, text) |
|
124 |
|
|
125 |
def result_helper(value): |
|
126 |
"""Format a result field in a nice way.""" |
|
127 |
if isinstance(value, (tuple, list)): |
|
128 |
return "[%s]" % (", ".join(str(elem) for elem in value)) |
|
129 |
else: |
|
130 |
return str(value) |
|
131 |
|
|
132 |
selected_fields = ["id", "status", "ops", "opresult", "opstatus"] |
|
133 |
|
|
134 |
result = GetClient().QueryJobs(args, selected_fields) |
|
135 |
|
|
136 |
first = True |
|
137 |
|
|
138 |
for job_id, status, ops, opresult, opstatus in result: |
|
139 |
if not first: |
|
140 |
format(0, "") |
|
141 |
else: |
|
142 |
first = False |
|
143 |
format(0, "Job ID: %s" % job_id) |
|
144 |
if status in _USER_JOB_STATUS: |
|
145 |
status = _USER_JOB_STATUS[status] |
|
146 |
else: |
|
147 |
raise errors.ProgrammerError("Unknown job status code '%s'" % val) |
|
148 |
|
|
149 |
format(1, "Status: %s" % status) |
|
150 |
format(1, "Opcodes:") |
|
151 |
for opcode, result, status in zip(ops, opresult, opstatus): |
|
152 |
format(2, "%s" % opcode["OP_ID"]) |
|
153 |
format(3, "Status: %s" % status) |
|
154 |
format(3, "Input fields:") |
|
155 |
for key, val in opcode.iteritems(): |
|
156 |
if key == "OP_ID": |
|
157 |
continue |
|
158 |
if isinstance(val, (tuple, list)): |
|
159 |
val = ",".join(val) |
|
160 |
format(4, "%s: %s" % (key, val)) |
|
161 |
if result is None: |
|
162 |
format(3, "No output data") |
|
163 |
elif isinstance(result, (tuple, list)): |
|
164 |
if not result: |
|
165 |
format(3, "Result: empty sequence") |
|
166 |
else: |
|
167 |
format(3, "Result:") |
|
168 |
for elem in result: |
|
169 |
format(4, result_helper(elem)) |
|
170 |
elif isinstance(result, dict): |
|
171 |
if not result: |
|
172 |
format(3, "Result: empty dictionary") |
|
173 |
else: |
|
174 |
for key, val in result.iteritems(): |
|
175 |
format(4, "%s: %s" % (key, result_helper(val))) |
|
176 |
else: |
|
177 |
format(3, "Result: %s" % result) |
|
178 |
return 0 |
|
179 |
|
|
180 |
|
|
117 | 181 |
commands = { |
118 | 182 |
'list': (ListJobs, ARGS_NONE, |
119 | 183 |
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT], |
... | ... | |
130 | 194 |
[DEBUG_OPT], |
131 | 195 |
"<job-id> [<job-id> ...]", |
132 | 196 |
"Cancel specified jobs"), |
197 |
'info': (ShowJobs, ARGS_ANY, [DEBUG_OPT], |
|
198 |
"<job-id> [<job-id> ...]", |
|
199 |
"Show detailed information about the specified jobs"), |
|
133 | 200 |
} |
134 | 201 |
|
135 | 202 |
|
Also available in: Unified diff