Commit ccfa86ba authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli: Replace hardcoded strings with constants


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent c352b0a9
...@@ -2045,7 +2045,7 @@ def GenericInstanceCreate(mode, opts, args): ...@@ -2045,7 +2045,7 @@ def GenericInstanceCreate(mode, opts, args):
raise errors.OpPrereqError("Please use either the '--disk' or" raise errors.OpPrereqError("Please use either the '--disk' or"
" '-s' option") " '-s' option")
if opts.sd_size is not None: if opts.sd_size is not None:
opts.disks = [(0, {"size": opts.sd_size})] opts.disks = [(0, {constants.IDISK_SIZE: opts.sd_size})]
if opts.disks: if opts.disks:
try: try:
...@@ -2060,20 +2060,21 @@ def GenericInstanceCreate(mode, opts, args): ...@@ -2060,20 +2060,21 @@ def GenericInstanceCreate(mode, opts, args):
if not isinstance(ddict, dict): if not isinstance(ddict, dict):
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict)
raise errors.OpPrereqError(msg) raise errors.OpPrereqError(msg)
elif "size" in ddict: elif constants.IDISK_SIZE in ddict:
if "adopt" in ddict: if constants.IDISK_ADOPT in ddict:
raise errors.OpPrereqError("Only one of 'size' and 'adopt' allowed" raise errors.OpPrereqError("Only one of 'size' and 'adopt' allowed"
" (disk %d)" % didx) " (disk %d)" % didx)
try: try:
ddict["size"] = utils.ParseUnit(ddict["size"]) ddict[constants.IDISK_SIZE] = \
utils.ParseUnit(ddict[constants.IDISK_SIZE])
except ValueError, err: except ValueError, err:
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % raise errors.OpPrereqError("Invalid disk size for disk %d: %s" %
(didx, err)) (didx, err))
elif "adopt" in ddict: elif constants.IDISK_ADOPT in ddict:
if mode == constants.INSTANCE_IMPORT: if mode == constants.INSTANCE_IMPORT:
raise errors.OpPrereqError("Disk adoption not allowed for instance" raise errors.OpPrereqError("Disk adoption not allowed for instance"
" import") " import")
ddict["size"] = 0 ddict[constants.IDISK_SIZE] = 0
else: else:
raise errors.OpPrereqError("Missing size or adoption source for" raise errors.OpPrereqError("Missing size or adoption source for"
" disk %d" % didx) " disk %d" % didx)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment