Commit 45fe090b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Disk template is no longer required when importing instance

… provided that disk_template value is set in the config.ini file.
Signed-off-by: default avatarAgata Murawska <>
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 3db199ea
......@@ -8402,6 +8402,10 @@ class LUInstanceCreate(LogicalUnit):
if einfo.has_option(constants.INISECT_INS, "disk_template"):
self.op.disk_template = einfo.get(constants.INISECT_INS,
if self.op.disk_template not in constants.DISK_TEMPLATES:
raise errors.OpPrereqError("Disk template specified in configuration"
" file is not one of the allowed values:"
" %s" % " ".join(constants.DISK_TEMPLATES))
raise errors.OpPrereqError("No disk template specified and the export"
" is missing the disk_template information",
......@@ -237,8 +237,20 @@ def _CheckFileStorage(value):
return True
_CheckDiskTemplate = ht.TAnd(ht.TElemOf(constants.DISK_TEMPLATES),
def _BuildDiskTemplateCheck(accept_none):
"""Builds check for disk template.
@type accept_none: bool
@param accept_none: whether to accept None as a correct value
@rtype: callable
template_check = ht.TElemOf(constants.DISK_TEMPLATES)
if accept_none:
template_check = ht.TOr(template_check, ht.TNone)
return ht.TAnd(template_check, _CheckFileStorage)
def _CheckStorageType(storage_type):
......@@ -1038,7 +1050,8 @@ class OpInstanceCreate(OpCode):
(constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
" or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
("disk_template", ht.NoDefault, _CheckDiskTemplate, "Disk template"),
("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
"Disk template"),
("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
"Driver for file-backed disks"),
("file_storage_dir", None, ht.TMaybeString,
......@@ -1306,7 +1319,7 @@ class OpInstanceSetParams(OpCode):
("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
("hvparams", ht.EmptyDict, ht.TDict,
"Per-instance hypervisor parameters, hypervisor-dependent"),
("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate),
("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
"Disk template for instance"),
("remote_node", None, ht.TMaybeString,
"Secondary node (used when changing disk template)"),
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