Commit 9b12ed0f authored by Iustin Pop's avatar Iustin Pop
Browse files

Reuse disk information from export



If the user doesn't pass the disk information on import, automatically
reuse the number and size of disks. This loses the iv_name attribute,
but that is only cosmetic and cannot be changed by the user.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 9f88b0e8
......@@ -1546,18 +1546,23 @@ def GenericInstanceCreate(mode, opts, args):
" information passed")
disks = []
else:
if not opts.disks and not opts.sd_size:
if (not opts.disks and not opts.sd_size
and mode == constants.INSTANCE_CREATE):
raise errors.OpPrereqError("No disk information specified")
if opts.disks and opts.sd_size is not None:
raise errors.OpPrereqError("Please use either the '--disk' or"
" '-s' option")
if opts.sd_size is not None:
opts.disks = [(0, {"size": opts.sd_size})]
try:
disk_max = max(int(didx[0]) + 1 for didx in opts.disks)
except ValueError, err:
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err))
disks = [{}] * disk_max
if opts.disks:
try:
disk_max = max(int(didx[0]) + 1 for didx in opts.disks)
except ValueError, err:
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err))
disks = [{}] * disk_max
else:
disks = []
for didx, ddict in opts.disks:
didx = int(didx)
if not isinstance(ddict, dict):
......
......@@ -6265,6 +6265,19 @@ class LUCreateInstance(LogicalUnit):
" is missing the disk_template information",
errors.ECODE_INVAL)
if not self.op.disks:
if einfo.has_option(constants.INISECT_INS, "disk_count"):
disks = []
# TODO: import the disk iv_name too
for idx in range(einfo.getint(constants.INISECT_INS, "disk_count")):
disk_sz = einfo.getint(constants.INISECT_INS, "disk%d_size" % idx)
disks.append({"size": disk_sz})
self.op.disks = disks
else:
raise errors.OpPrereqError("No disk info specified and the export"
" is missing the disk information",
errors.ECODE_INVAL)
if (self.op.hypervisor is None and
einfo.has_option(constants.INISECT_INS, "hypervisor")):
self.op.hypervisor = einfo.get(constants.INISECT_INS, "hypervisor")
......
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