Revision a4ebd726
b/lib/cli.py | ||
---|---|---|
195 | 195 |
"cli_option", |
196 | 196 |
"SplitNodeOption", |
197 | 197 |
"CalculateOSNames", |
198 |
"ParseFields", |
|
198 | 199 |
] |
199 | 200 |
|
200 | 201 |
NO_PREFIX = "no_" |
... | ... | |
1200 | 1201 |
return [os_name] |
1201 | 1202 |
|
1202 | 1203 |
|
1204 |
def ParseFields(selected, default): |
|
1205 |
"""Parses the values of "--field"-like options. |
|
1206 |
|
|
1207 |
@type selected: string or None |
|
1208 |
@param selected: User-selected options |
|
1209 |
@type default: list |
|
1210 |
@param default: Default fields |
|
1211 |
|
|
1212 |
""" |
|
1213 |
if selected is None: |
|
1214 |
return default |
|
1215 |
|
|
1216 |
if selected.startswith("+"): |
|
1217 |
return default + selected[1:].split(",") |
|
1218 |
|
|
1219 |
return selected.split(",") |
|
1220 |
|
|
1221 |
|
|
1203 | 1222 |
UsesRPC = rpc.RunWithRPC |
1204 | 1223 |
|
1205 | 1224 |
|
b/scripts/gnt-instance | ||
---|---|---|
244 | 244 |
@return: the desired exit code |
245 | 245 |
|
246 | 246 |
""" |
247 |
if opts.output is None: |
|
248 |
selected_fields = _LIST_DEF_FIELDS |
|
249 |
elif opts.output.startswith("+"): |
|
250 |
selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",") |
|
251 |
else: |
|
252 |
selected_fields = opts.output.split(",") |
|
247 |
selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS) |
|
253 | 248 |
|
254 | 249 |
output = GetClient().QueryInstances(args, selected_fields, opts.do_locking) |
255 | 250 |
|
b/scripts/gnt-job | ||
---|---|---|
61 | 61 |
@return: the desired exit code |
62 | 62 |
|
63 | 63 |
""" |
64 |
if opts.output is None: |
|
65 |
selected_fields = _LIST_DEF_FIELDS |
|
66 |
elif opts.output.startswith("+"): |
|
67 |
selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",") |
|
68 |
else: |
|
69 |
selected_fields = opts.output.split(",") |
|
64 |
selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS) |
|
70 | 65 |
|
71 | 66 |
output = GetClient().QueryJobs(args, selected_fields) |
72 | 67 |
if not opts.no_headers: |
b/scripts/gnt-node | ||
---|---|---|
46 | 46 |
] |
47 | 47 |
|
48 | 48 |
|
49 |
#: Default field list for L{ListVolumes} |
|
50 |
_LIST_VOL_DEF_FIELDS = ["node", "phys", "vg", "name", "size", "instance"] |
|
51 |
|
|
52 |
|
|
49 | 53 |
#: default list of field for L{ListStorage} |
50 | 54 |
_LIST_STOR_DEF_FIELDS = [ |
51 | 55 |
constants.SF_NODE, |
... | ... | |
188 | 192 |
@return: the desired exit code |
189 | 193 |
|
190 | 194 |
""" |
191 |
if opts.output is None: |
|
192 |
selected_fields = _LIST_DEF_FIELDS |
|
193 |
elif opts.output.startswith("+"): |
|
194 |
selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",") |
|
195 |
else: |
|
196 |
selected_fields = opts.output.split(",") |
|
195 |
selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS) |
|
197 | 196 |
|
198 | 197 |
output = GetClient().QueryNodes(args, selected_fields, opts.do_locking) |
199 | 198 |
|
... | ... | |
466 | 465 |
@return: the desired exit code |
467 | 466 |
|
468 | 467 |
""" |
469 |
if opts.output is None: |
|
470 |
selected_fields = ["node", "phys", "vg", |
|
471 |
"name", "size", "instance"] |
|
472 |
else: |
|
473 |
selected_fields = opts.output.split(",") |
|
468 |
selected_fields = ParseFields(opts.output, _LIST_VOL_DEF_FIELDS) |
|
474 | 469 |
|
475 | 470 |
op = opcodes.OpQueryNodeVolumes(nodes=args, output_fields=selected_fields) |
476 | 471 |
output = SubmitOpCode(op, opts=opts) |
... | ... | |
514 | 509 |
|
515 | 510 |
storage_type = ConvertStorageType(opts.user_storage_type) |
516 | 511 |
|
517 |
if opts.output is None: |
|
518 |
selected_fields = _LIST_STOR_DEF_FIELDS |
|
519 |
elif opts.output.startswith("+"): |
|
520 |
selected_fields = _LIST_STOR_DEF_FIELDS + opts.output[1:].split(",") |
|
521 |
else: |
|
522 |
selected_fields = opts.output.split(",") |
|
512 |
selected_fields = ParseFields(opts.output, _LIST_STOR_DEF_FIELDS) |
|
523 | 513 |
|
524 | 514 |
op = opcodes.OpQueryNodeStorage(nodes=args, |
525 | 515 |
storage_type=storage_type, |
b/test/ganeti.cli_unittest.py | ||
---|---|---|
429 | 429 |
self.assert_(cli.FormatLogMessage("some other type", (1, 2, 3))) |
430 | 430 |
|
431 | 431 |
|
432 |
class TestParseFields(unittest.TestCase): |
|
433 |
def test(self): |
|
434 |
self.assertEqual(cli.ParseFields(None, []), []) |
|
435 |
self.assertEqual(cli.ParseFields("name,foo,hello", []), |
|
436 |
["name", "foo", "hello"]) |
|
437 |
self.assertEqual(cli.ParseFields(None, ["def", "ault", "fields", "here"]), |
|
438 |
["def", "ault", "fields", "here"]) |
|
439 |
self.assertEqual(cli.ParseFields("name,foo", ["def", "ault"]), |
|
440 |
["name", "foo"]) |
|
441 |
self.assertEqual(cli.ParseFields("+name,foo", ["def", "ault"]), |
|
442 |
["def", "ault", "name", "foo"]) |
|
443 |
|
|
444 |
|
|
432 | 445 |
if __name__ == '__main__': |
433 | 446 |
testutils.GanetiTestProgram() |
Also available in: Unified diff