Revision 2cfbc784 lib/cli.py
b/lib/cli.py | ||
---|---|---|
416 | 416 |
constants.TAG_NODE, |
417 | 417 |
constants.TAG_INSTANCE): |
418 | 418 |
if not args: |
419 |
raise errors.OpPrereqError("no arguments passed to the command") |
|
419 |
raise errors.OpPrereqError("no arguments passed to the command", |
|
420 |
errors.ECODE_INVAL) |
|
420 | 421 |
name = args.pop(0) |
421 | 422 |
retval = kind, name |
422 | 423 |
else: |
... | ... | |
483 | 484 |
kind, name = _ExtractTagsObject(opts, args) |
484 | 485 |
_ExtendTags(opts, args) |
485 | 486 |
if not args: |
486 |
raise errors.OpPrereqError("No tags to be added") |
|
487 |
raise errors.OpPrereqError("No tags to be added", errors.ECODE_INVAL)
|
|
487 | 488 |
op = opcodes.OpTagsSet(kind=kind, name=name, tags=args) |
488 | 489 |
SubmitOrSend(op, opts) |
489 | 490 |
|
... | ... | |
500 | 501 |
kind, name = _ExtractTagsObject(opts, args) |
501 | 502 |
_ExtendTags(opts, args) |
502 | 503 |
if not args: |
503 |
raise errors.OpPrereqError("No tags to be removed") |
|
504 |
raise errors.OpPrereqError("No tags to be removed", errors.ECODE_INVAL)
|
|
504 | 505 |
op = opcodes.OpTagsDel(kind=kind, name=name, tags=args) |
505 | 506 |
SubmitOrSend(op, opts) |
506 | 507 |
|
... | ... | |
2091 | 2092 |
ss.GetMasterNode() |
2092 | 2093 |
except errors.ConfigurationError: |
2093 | 2094 |
raise errors.OpPrereqError("Cluster not initialized or this machine is" |
2094 |
" not part of a cluster") |
|
2095 |
" not part of a cluster", |
|
2096 |
errors.ECODE_INVAL) |
|
2095 | 2097 |
|
2096 | 2098 |
master, myself = ssconf.GetMasterAndMyself(ss=ss) |
2097 | 2099 |
if master != myself: |
2098 | 2100 |
raise errors.OpPrereqError("This is not the master node, please connect" |
2099 | 2101 |
" to node '%s' and rerun the command" % |
2100 |
master) |
|
2102 |
master, errors.ECODE_INVAL)
|
|
2101 | 2103 |
raise |
2102 | 2104 |
return client |
2103 | 2105 |
|
... | ... | |
2271 | 2273 |
try: |
2272 | 2274 |
nic_max = max(int(nidx[0]) + 1 for nidx in optvalue) |
2273 | 2275 |
except (TypeError, ValueError), err: |
2274 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) |
|
2276 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err), |
|
2277 |
errors.ECODE_INVAL) |
|
2275 | 2278 |
|
2276 | 2279 |
nics = [{}] * nic_max |
2277 | 2280 |
for nidx, ndict in optvalue: |
... | ... | |
2279 | 2282 |
|
2280 | 2283 |
if not isinstance(ndict, dict): |
2281 | 2284 |
raise errors.OpPrereqError("Invalid nic/%d value: expected dict," |
2282 |
" got %s" % (nidx, ndict)) |
|
2285 |
" got %s" % (nidx, ndict), errors.ECODE_INVAL)
|
|
2283 | 2286 |
|
2284 | 2287 |
utils.ForceDictType(ndict, constants.INIC_PARAMS_TYPES) |
2285 | 2288 |
|
... | ... | |
2323 | 2326 |
if opts.disk_template == constants.DT_DISKLESS: |
2324 | 2327 |
if opts.disks or opts.sd_size is not None: |
2325 | 2328 |
raise errors.OpPrereqError("Diskless instance but disk" |
2326 |
" information passed") |
|
2329 |
" information passed", errors.ECODE_INVAL)
|
|
2327 | 2330 |
disks = [] |
2328 | 2331 |
else: |
2329 | 2332 |
if (not opts.disks and not opts.sd_size |
2330 | 2333 |
and mode == constants.INSTANCE_CREATE): |
2331 |
raise errors.OpPrereqError("No disk information specified") |
|
2334 |
raise errors.OpPrereqError("No disk information specified", |
|
2335 |
errors.ECODE_INVAL) |
|
2332 | 2336 |
if opts.disks and opts.sd_size is not None: |
2333 | 2337 |
raise errors.OpPrereqError("Please use either the '--disk' or" |
2334 |
" '-s' option") |
|
2338 |
" '-s' option", errors.ECODE_INVAL)
|
|
2335 | 2339 |
if opts.sd_size is not None: |
2336 | 2340 |
opts.disks = [(0, {constants.IDISK_SIZE: opts.sd_size})] |
2337 | 2341 |
|
... | ... | |
2339 | 2343 |
try: |
2340 | 2344 |
disk_max = max(int(didx[0]) + 1 for didx in opts.disks) |
2341 | 2345 |
except ValueError, err: |
2342 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
2346 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err), |
|
2347 |
errors.ECODE_INVAL) |
|
2343 | 2348 |
disks = [{}] * disk_max |
2344 | 2349 |
else: |
2345 | 2350 |
disks = [] |
... | ... | |
2347 | 2352 |
didx = int(didx) |
2348 | 2353 |
if not isinstance(ddict, dict): |
2349 | 2354 |
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) |
2350 |
raise errors.OpPrereqError(msg) |
|
2355 |
raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
|
2351 | 2356 |
elif constants.IDISK_SIZE in ddict: |
2352 | 2357 |
if constants.IDISK_ADOPT in ddict: |
2353 | 2358 |
raise errors.OpPrereqError("Only one of 'size' and 'adopt' allowed" |
2354 |
" (disk %d)" % didx) |
|
2359 |
" (disk %d)" % didx, errors.ECODE_INVAL)
|
|
2355 | 2360 |
try: |
2356 | 2361 |
ddict[constants.IDISK_SIZE] = \ |
2357 | 2362 |
utils.ParseUnit(ddict[constants.IDISK_SIZE]) |
2358 | 2363 |
except ValueError, err: |
2359 | 2364 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
2360 |
(didx, err)) |
|
2365 |
(didx, err), errors.ECODE_INVAL)
|
|
2361 | 2366 |
elif constants.IDISK_ADOPT in ddict: |
2362 | 2367 |
if mode == constants.INSTANCE_IMPORT: |
2363 | 2368 |
raise errors.OpPrereqError("Disk adoption not allowed for instance" |
2364 |
" import") |
|
2369 |
" import", errors.ECODE_INVAL)
|
|
2365 | 2370 |
ddict[constants.IDISK_SIZE] = 0 |
2366 | 2371 |
else: |
2367 | 2372 |
raise errors.OpPrereqError("Missing size or adoption source for" |
2368 |
" disk %d" % didx) |
|
2373 |
" disk %d" % didx, errors.ECODE_INVAL)
|
|
2369 | 2374 |
disks[didx] = ddict |
2370 | 2375 |
|
2371 | 2376 |
if opts.tags is not None: |
... | ... | |
3074 | 3079 |
""" |
3075 | 3080 |
value = str(value) |
3076 | 3081 |
if not value: |
3077 |
raise errors.OpPrereqError("Empty time specification passed") |
|
3082 |
raise errors.OpPrereqError("Empty time specification passed", |
|
3083 |
errors.ECODE_INVAL) |
|
3078 | 3084 |
suffix_map = { |
3079 | 3085 |
"s": 1, |
3080 | 3086 |
"m": 60, |
... | ... | |
3086 | 3092 |
try: |
3087 | 3093 |
value = int(value) |
3088 | 3094 |
except (TypeError, ValueError): |
3089 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value) |
|
3095 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value, |
|
3096 |
errors.ECODE_INVAL) |
|
3090 | 3097 |
else: |
3091 | 3098 |
multiplier = suffix_map[value[-1]] |
3092 | 3099 |
value = value[:-1] |
3093 | 3100 |
if not value: # no data left after stripping the suffix |
3094 | 3101 |
raise errors.OpPrereqError("Invalid time specification (only" |
3095 |
" suffix passed)") |
|
3102 |
" suffix passed)", errors.ECODE_INVAL)
|
|
3096 | 3103 |
try: |
3097 | 3104 |
value = int(value) * multiplier |
3098 | 3105 |
except (TypeError, ValueError): |
3099 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value) |
|
3106 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value, |
|
3107 |
errors.ECODE_INVAL) |
|
3100 | 3108 |
return value |
3101 | 3109 |
|
3102 | 3110 |
|
Also available in: Unified diff