Commit c59bb92f authored by Alex Pyrgiotis's avatar Alex Pyrgiotis

(ext) Allow passing ext params on disk remove

Remove any restriction regarding ext params during the removal of a
disk.
parent 6070be5b
......@@ -1298,10 +1298,6 @@ def _ConvertNicDiskModifications(mods):
assert not (constants.DDMS_VALUES_WITH_MODIFY & set(params.keys()))
if action == constants.DDM_REMOVE and params:
raise errors.OpPrereqError("Not accepting parameters on removal",
errors.ECODE_INVAL)
result.append((action, identifier, params))
return result
......
......@@ -64,7 +64,7 @@ from ganeti.cmdlib.instance_storage import CreateDisks, \
IsExclusiveStorageEnabledNodeUuid, CreateSingleBlockDev, ComputeDisks, \
CheckRADOSFreeSpace, ComputeDiskSizePerVG, GenerateDiskTemplate, \
StartInstanceDisks, ShutdownInstanceDisks, AssembleInstanceDisks, \
CheckSpindlesExclusiveStorage
CheckSpindlesExclusiveStorage, ExtractDiskParams
from ganeti.cmdlib.instance_utils import BuildInstanceHookEnvByObject, \
GetClusterDomainSecret, BuildInstanceHookEnv, NICListToTuple, \
NICToTuple, CheckNodeNotDrained, RemoveInstance, CopyLockList, \
......@@ -2288,12 +2288,11 @@ def _ApplyContainerMods(kind, container, chgdesc, mods,
(absidx, item) = GetItemFromContainer(identifier, kind, container)
if op == constants.DDM_REMOVE:
assert not params
changes = [("%s/%s" % (kind, absidx), "remove")]
if remove_fn is not None:
msg = remove_fn(absidx, item, private)
msg = remove_fn(absidx, item, private, params)
if msg:
changes.append(("%s/%s" % (kind, absidx), msg))
......@@ -2369,12 +2368,8 @@ class LUInstanceSetParams(LogicalUnit):
if key_types:
utils.ForceDictType(params, key_types)
if op == constants.DDM_REMOVE:
if params:
raise errors.OpPrereqError("No settings should be passed when"
" removing a %s" % kind,
errors.ECODE_INVAL)
elif op in (constants.DDM_ADD, constants.DDM_MODIFY):
if op in (constants.DDM_ADD, constants.DDM_MODIFY, constants.DDM_REMOVE):
item_fn(op, params)
else:
raise errors.ProgrammerError("Unhandled operation '%s'" % op)
......@@ -3449,10 +3444,16 @@ class LUInstanceSetParams(LogicalUnit):
return changes
def _RemoveDisk(self, idx, root, _):
def _RemoveDisk(self, idx, root, _, params):
"""Removes a disk.
"""
disk_params = ExtractDiskParams(params, self.instance.disk_template)
if root.params is None:
root.params = disk_params
else:
root.params.update(disk_params)
hotmsg = ""
if self.op.hotplug:
hotmsg = self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE,
......@@ -3539,7 +3540,7 @@ class LUInstanceSetParams(LogicalUnit):
return changes
def _RemoveNic(self, idx, nic, _):
def _RemoveNic(self, idx, nic, _, __):
if self.op.hotplug:
return self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE,
constants.HOTPLUG_TARGET_NIC,
......
......@@ -385,6 +385,24 @@ def CheckRADOSFreeSpace():
pass
def ExtractDiskParams(disk, template_name):
"""Extract disk parameters from the provided disk information."""
params = {}
# Only for the Ext template add disk_info to params
if template_name == constants.DT_EXT:
# FIXME: Check if the disk provider exists first
params[constants.IDISK_PROVIDER] = disk[constants.IDISK_PROVIDER]
for key in disk:
if key not in constants.IDISK_PARAMS:
params[key] = disk[key]
# Add IDISK_ACCESS param to disk params
if (template_name in constants.DTS_HAVE_ACCESS and
constants.IDISK_ACCESS in disk):
params[constants.IDISK_ACCESS] = disk[constants.IDISK_ACCESS]
return params
def _GenerateDRBD8Branch(lu, primary_uuid, secondary_uuid, size, vgnames, names,
iv_name, p_minor, s_minor):
"""Generate a drbd8 device complete with its children.
......@@ -500,17 +518,7 @@ def GenerateDiskTemplate(
dev_type = template_name
for idx, disk in enumerate(disk_info):
params = {}
# Only for the Ext template add disk_info to params
if template_name == constants.DT_EXT:
params[constants.IDISK_PROVIDER] = disk[constants.IDISK_PROVIDER]
for key in disk:
if key not in constants.IDISK_PARAMS:
params[key] = disk[key]
# Add IDISK_ACCESS param to disk params
if (template_name in constants.DTS_HAVE_ACCESS and
constants.IDISK_ACCESS in disk):
params[constants.IDISK_ACCESS] = disk[constants.IDISK_ACCESS]
params = ExtractDiskParams(disk, template_name)
disk_index = idx + base_index
size = disk[constants.IDISK_SIZE]
feedback_fn("* disk %s, size %s" %
......
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