diff --git a/lib/cli.py b/lib/cli.py index a647f73131725d82e38454f66b3962d1494ffdcf..591926d53d3fab857af2a747479d4f04266fc9a5 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 4d91dd80fd85c2880724b0e7eb9890c34fc9359b..984b1d0a59fc06f54e795a2fa95802f0449df978 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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")