diff --git a/lib/cmdlib.py b/lib/cmdlib.py index f5bce93b1cc97d6df7b63a7b3f3be95b898bfb12..0551bfbde2b5b1e9e5adf12b459ab2da0b53215e 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -568,6 +568,9 @@ def _CheckDiskTemplate(template): msg = ("Invalid disk template name '%s', valid templates are: %s" % (template, utils.CommaJoin(constants.DISK_TEMPLATES))) raise errors.OpPrereqError(msg, errors.ECODE_INVAL) + if template == constants.DT_FILE and not constants.ENABLE_FILE_STORAGE: + raise errors.OpPrereqError("File storage disabled at configure time", + errors.ECODE_INVAL) def _CheckInstanceDown(lu, instance, reason): @@ -5973,7 +5976,7 @@ class LUCreateInstance(LogicalUnit): """ HPATH = "instance-add" HTYPE = constants.HTYPE_INSTANCE - _OP_REQP = ["instance_name", "disks", "disk_template", + _OP_REQP = ["instance_name", "disks", "mode", "start", "wait_for_sync", "ip_check", "nics", "hvparams", "beparams"] @@ -5984,7 +5987,8 @@ class LUCreateInstance(LogicalUnit): """ # set optional parameters to none if they don't exist - for attr in ["pnode", "snode", "iallocator", "hypervisor"]: + for attr in ["pnode", "snode", "iallocator", "hypervisor", + "disk_template"]: if not hasattr(self.op, attr): setattr(self.op, attr, None) @@ -6003,10 +6007,6 @@ class LUCreateInstance(LogicalUnit): # TODO: make the ip check more flexible and not depend on the name check raise errors.OpPrereqError("Cannot do ip checks without a name check", errors.ECODE_INVAL) - if (self.op.disk_template == constants.DT_FILE and - not constants.ENABLE_FILE_STORAGE): - raise errors.OpPrereqError("File storage disabled at configure time", - errors.ECODE_INVAL) # check disk information: either all adopt, or no adopt has_adopt = has_no_adopt = False for disk in self.op.disks: @@ -6037,9 +6037,6 @@ class LUCreateInstance(LogicalUnit): raise errors.OpPrereqError("Invalid instance creation mode '%s'" % self.op.mode, errors.ECODE_INVAL) - # disk template - _CheckDiskTemplate(self.op.disk_template) - # instance name verification if self.op.name_check: self.hostname1 = utils.GetHostInfo(self.op.instance_name) @@ -6079,6 +6076,9 @@ class LUCreateInstance(LogicalUnit): raise errors.OpPrereqError("No guest OS specified", errors.ECODE_INVAL) self.op.force_variant = getattr(self.op, "force_variant", False) + if self.op.disk_template is None: + raise errors.OpPrereqError("No disk template specified", + errors.ECODE_INVAL) def ExpandNames(self): """ExpandNames for CreateInstance. @@ -6248,12 +6248,32 @@ class LUCreateInstance(LogicalUnit): errors.ECODE_ENVIRON) return export_info + def _ReadExportParams(self, einfo): + """Use export parameters as defaults. + + In case the opcode doesn't specify (as in override) some instance + parameters, then try to use them from the export information, if + that declares them. + + """ + if self.op.disk_template is None: + if einfo.has_option(constants.INISECT_INS, "disk_template"): + self.op.disk_template = einfo.get(constants.INISECT_INS, + "disk_template") + else: + raise errors.OpPrereqError("No disk template specified and the export" + " is missing the disk_template information", + errors.ECODE_INVAL) + def CheckPrereq(self): """Check prerequisites. """ if self.op.mode == constants.INSTANCE_IMPORT: export_info = self._ReadExportInfo() + self._ReadExportParams(export_info) + + _CheckDiskTemplate(self.op.disk_template) if (not self.cfg.GetVGName() and self.op.disk_template not in constants.DTS_NOT_LVM):