Commit bd061c35 authored by Guido Trotter's avatar Guido Trotter
Browse files

Enforce consistency in disks and nics input dicts



With this change unknown disk and nic parameters will be refused, rather
than silently ignored, so that one can't pass them in by mistake and not
realize what went wrong.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 1b67be9b
......@@ -6116,9 +6116,15 @@ 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)
# check disk information: either all adopt, or no adopt
# check nics' parameter names
for nic in self.op.nics:
utils.ForceDictType(nic, constants.INIC_PARAMS_TYPES)
# check disks. parameter names and consistent adopt/no-adopt strategy
has_adopt = has_no_adopt = False
for disk in self.op.disks:
utils.ForceDictType(disk, constants.IDISK_PARAMS_TYPES)
if "adopt" in disk:
has_adopt = True
else:
......@@ -8170,6 +8176,7 @@ class LUSetInstanceParams(LogicalUnit):
# Disk validation
disk_addremove = 0
for disk_op, disk_dict in self.op.disks:
utils.ForceDictType(disk_dict, constants.IDISK_PARAMS_TYPES)
if disk_op == constants.DDM_REMOVE:
disk_addremove += 1
continue
......@@ -8223,6 +8230,7 @@ class LUSetInstanceParams(LogicalUnit):
# NIC validation
nic_addremove = 0
for nic_op, nic_dict in self.op.nics:
utils.ForceDictType(nic_dict, constants.INIC_PARAMS_TYPES)
if nic_op == constants.DDM_REMOVE:
nic_addremove += 1
continue
......
......@@ -512,6 +512,18 @@ NICS_PARAMETER_TYPES = {
NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys())
IDISK_SIZE = "size"
IDISK_MODE = "mode"
IDISK_PARAMS = frozenset([IDISK_SIZE, IDISK_MODE])
IDISK_PARAMS_TYPES = {IDISK_SIZE: VTYPE_SIZE, IDISK_MODE: VTYPE_STRING}
INIC_MAC = "mac"
INIC_IP = "ip"
INIC_MODE = "mode"
INIC_LINK = "link"
INIC_BRIDGE = "bridge"
INIC_PARAMS = frozenset([INIC_MAC, INIC_IP, INIC_MODE, INIC_LINK, INIC_BRIDGE])
INIC_PARAMS_TYPES = dict([(name, VTYPE_STRING) for name in INIC_PARAMS])
# Hypervisor constants
HT_XEN_PVM = "xen-pvm"
HT_FAKE = "fake"
......
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