Commit c5c72215 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Michele Tartara

Allow modification of arbitrary params for ext

Disks of ext template are allowed to have arbitrary parameters
stored in the Disk object's params slot. Those parameters can be
passed during creation of a new disk, either in LUInstanceCreate()
or in LUInsanceSetParams(). Still those parameters can not be
changed afterwards. With this patch we override this limitation.

Currently, for the other disk templates we allow modifying only
'name' and 'mode'. Therefore, we introduce new constants
MODIFIABLE_IDISK_PARAM* to include those params. If any other
parameter is passed, _VerifyDiskModification() will raise an
exception.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 54666867
......@@ -2277,8 +2277,7 @@ class LUInstanceSetParams(LogicalUnit):
else:
raise errors.ProgrammerError("Unhandled operation '%s'" % op)
@staticmethod
def _VerifyDiskModification(op, params):
def _VerifyDiskModification(self, op, params):
"""Verifies a disk modification.
"""
......@@ -2308,10 +2307,12 @@ class LUInstanceSetParams(LogicalUnit):
if constants.IDISK_SIZE in params:
raise errors.OpPrereqError("Disk size change not possible, use"
" grow-disk", errors.ECODE_INVAL)
if len(params) > 2:
raise errors.OpPrereqError("Disk modification doesn't support"
" additional arbitrary parameters",
errors.ECODE_INVAL)
# Disk modification supports changing only the disk name and mode.
# Changing arbitrary parameters is allowed only for ext disk template",
if self.instance.disk_template != constants.DT_EXT:
utils.ForceDictType(params, constants.MODIFIABLE_IDISK_PARAMS_TYPES)
name = params.get(constants.IDISK_NAME, None)
if name is not None and name.lower() == constants.VALUE_NONE:
params[constants.IDISK_NAME] = None
......@@ -3182,8 +3183,7 @@ class LUInstanceSetParams(LogicalUnit):
("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)),
])
@staticmethod
def _ModifyDisk(idx, disk, params, _):
def _ModifyDisk(self, idx, disk, params, _):
"""Modifies a disk.
"""
......@@ -3196,6 +3196,13 @@ class LUInstanceSetParams(LogicalUnit):
disk.name = params.get(constants.IDISK_NAME)
changes.append(("disk.name/%d" % idx, disk.name))
# Modify arbitrary params in case instance template is ext
for key, value in params.iteritems():
if (key not in constants.MODIFIABLE_IDISK_PARAMS and
self.instance.disk_template == constants.DT_EXT):
disk.params[key] = value
changes.append(("disk.params:%s/%d" % (key, idx), value))
return changes
def _RemoveDisk(self, idx, root, _):
......
......@@ -1354,6 +1354,12 @@ IDISK_PARAMS_TYPES = {
}
IDISK_PARAMS = frozenset(IDISK_PARAMS_TYPES.keys())
MODIFIABLE_IDISK_PARAMS_TYPES = {
IDISK_MODE: VTYPE_STRING,
IDISK_NAME: VTYPE_STRING,
}
MODIFIABLE_IDISK_PARAMS = frozenset(MODIFIABLE_IDISK_PARAMS_TYPES.keys())
# INIC_* constants are used in opcodes, to create/change nics
INIC_MAC = "mac"
INIC_IP = "ip"
......
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