Revision 7736a5f2
b/lib/cmdlib.py | ||
---|---|---|
500 | 500 |
setattr(op, name, val) |
501 | 501 |
|
502 | 502 |
|
503 |
def _CheckGlobalHvParams(params): |
|
504 |
"""Validates that given hypervisor params are not global ones. |
|
505 |
|
|
506 |
This will ensure that instances don't get customised versions of |
|
507 |
global params. |
|
508 |
|
|
509 |
""" |
|
510 |
used_globals = constants.HVC_GLOBALS.intersection(params) |
|
511 |
if used_globals: |
|
512 |
msg = ("The following hypervisor parameters are global and cannot" |
|
513 |
" be customized at instance level, please modify them at" |
|
514 |
" cluster level: %s" % ", ".join(used_globals)) |
|
515 |
raise errors.OpPrereqError(msg, errors.ECODE_INVAL) |
|
516 |
|
|
517 |
|
|
503 | 518 |
def _CheckNodeOnline(lu, node): |
504 | 519 |
"""Ensure that a given node is online. |
505 | 520 |
|
... | ... | |
4200 | 4215 |
"hvparams", |
4201 | 4216 |
] + _SIMPLE_FIELDS + |
4202 | 4217 |
["hv/%s" % name |
4203 |
for name in constants.HVS_PARAMETERS] + |
|
4218 |
for name in constants.HVS_PARAMETERS |
|
4219 |
if name not in constants.HVC_GLOBALS] + |
|
4204 | 4220 |
["be/%s" % name |
4205 | 4221 |
for name in constants.BES_PARAMETERS]) |
4206 | 4222 |
_FIELDS_DYNAMIC = utils.FieldSet("oper_state", "oper_ram", "status") |
... | ... | |
4295 | 4311 |
cluster = self.cfg.GetClusterInfo() |
4296 | 4312 |
for instance in instance_list: |
4297 | 4313 |
iout = [] |
4298 |
i_hv = cluster.FillHV(instance) |
|
4314 |
i_hv = cluster.FillHV(instance, skip_globals=True)
|
|
4299 | 4315 |
i_be = cluster.FillBE(instance) |
4300 | 4316 |
i_nicp = [objects.FillDict(cluster.nicparams[constants.PP_DEFAULT], |
4301 | 4317 |
nic.nicparams) for nic in instance.nics] |
... | ... | |
4382 | 4398 |
elif field == "hvparams": |
4383 | 4399 |
val = i_hv |
4384 | 4400 |
elif (field.startswith(HVPREFIX) and |
4385 |
field[len(HVPREFIX):] in constants.HVS_PARAMETERS): |
|
4401 |
field[len(HVPREFIX):] in constants.HVS_PARAMETERS and |
|
4402 |
field[len(HVPREFIX):] not in constants.HVC_GLOBALS): |
|
4386 | 4403 |
val = i_hv.get(field[len(HVPREFIX):], None) |
4387 | 4404 |
elif field == "beparams": |
4388 | 4405 |
val = i_be |
... | ... | |
5599 | 5616 |
hv_type = hypervisor.GetHypervisor(self.op.hypervisor) |
5600 | 5617 |
hv_type.CheckParameterSyntax(filled_hvp) |
5601 | 5618 |
self.hv_full = filled_hvp |
5619 |
# check that we don't specify global parameters on an instance |
|
5620 |
_CheckGlobalHvParams(self.op.hvparams) |
|
5602 | 5621 |
|
5603 | 5622 |
# fill and remember the beparams dict |
5604 | 5623 |
utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES) |
... | ... | |
7292 | 7311 |
"hypervisor": instance.hypervisor, |
7293 | 7312 |
"network_port": instance.network_port, |
7294 | 7313 |
"hv_instance": instance.hvparams, |
7295 |
"hv_actual": cluster.FillHV(instance), |
|
7314 |
"hv_actual": cluster.FillHV(instance, skip_globals=True),
|
|
7296 | 7315 |
"be_instance": instance.beparams, |
7297 | 7316 |
"be_actual": cluster.FillBE(instance), |
7298 | 7317 |
"serial_no": instance.serial_no, |
... | ... | |
7329 | 7348 |
self.op.hvparams or self.op.beparams): |
7330 | 7349 |
raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL) |
7331 | 7350 |
|
7351 |
if self.op.hvparams: |
|
7352 |
_CheckGlobalHvParams(self.op.hvparams) |
|
7353 |
|
|
7332 | 7354 |
# Disk validation |
7333 | 7355 |
disk_addremove = 0 |
7334 | 7356 |
for disk_op, disk_dict in self.op.disks: |
b/lib/constants.py | ||
---|---|---|
650 | 650 |
}, |
651 | 651 |
} |
652 | 652 |
|
653 |
HVC_GLOBALS = frozenset([ |
|
654 |
HV_MIGRATION_PORT, |
|
655 |
]) |
|
656 |
|
|
653 | 657 |
BEC_DEFAULTS = { |
654 | 658 |
BE_MEMORY: 128, |
655 | 659 |
BE_VCPUS: 1, |
b/lib/objects.py | ||
---|---|---|
42 | 42 |
_TIMESTAMPS = ["ctime", "mtime"] |
43 | 43 |
_UUID = ["uuid"] |
44 | 44 |
|
45 |
def FillDict(defaults_dict, custom_dict): |
|
45 |
def FillDict(defaults_dict, custom_dict, skip_keys=[]):
|
|
46 | 46 |
"""Basic function to apply settings on top a default dict. |
47 | 47 |
|
48 | 48 |
@type defaults_dict: dict |
49 | 49 |
@param defaults_dict: dictionary holding the default values |
50 | 50 |
@type custom_dict: dict |
51 | 51 |
@param custom_dict: dictionary holding customized value |
52 |
@type skip_keys: list |
|
53 |
@param skip_keys: which keys not to fill |
|
52 | 54 |
@rtype: dict |
53 | 55 |
@return: dict with the 'full' values |
54 | 56 |
|
55 | 57 |
""" |
56 | 58 |
ret_dict = copy.deepcopy(defaults_dict) |
57 | 59 |
ret_dict.update(custom_dict) |
60 |
for k in skip_keys: |
|
61 |
try: |
|
62 |
del ret_dict[k] |
|
63 |
except KeyError: |
|
64 |
pass |
|
58 | 65 |
return ret_dict |
59 | 66 |
|
60 | 67 |
|
... | ... | |
777 | 784 |
nic.UpgradeConfig() |
778 | 785 |
for disk in self.disks: |
779 | 786 |
disk.UpgradeConfig() |
787 |
if self.hvparams: |
|
788 |
for key in constants.HVC_GLOBALS: |
|
789 |
try: |
|
790 |
del self.hvparams[key] |
|
791 |
except KeyError: |
|
792 |
pass |
|
780 | 793 |
|
781 | 794 |
|
782 | 795 |
class OS(ConfigObject): |
... | ... | |
887 | 900 |
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool) |
888 | 901 |
return obj |
889 | 902 |
|
890 |
def FillHV(self, instance): |
|
903 |
def FillHV(self, instance, skip_globals=False):
|
|
891 | 904 |
"""Fill an instance's hvparams dict. |
892 | 905 |
|
893 | 906 |
@type instance: L{objects.Instance} |
894 | 907 |
@param instance: the instance parameter to fill |
908 |
@type skip_globals: boolean |
|
909 |
@param skip_globals: if True, the global hypervisor parameters will |
|
910 |
not be filled |
|
895 | 911 |
@rtype: dict |
896 | 912 |
@return: a copy of the instance's hvparams with missing keys filled from |
897 | 913 |
the cluster defaults |
898 | 914 |
|
899 | 915 |
""" |
916 |
if skip_globals: |
|
917 |
skip_keys = constants.HVC_GLOBALS |
|
918 |
else: |
|
919 |
skip_keys = [] |
|
900 | 920 |
return FillDict(self.hvparams.get(instance.hypervisor, {}), |
901 |
instance.hvparams)
|
|
921 |
instance.hvparams, skip_keys=skip_keys)
|
|
902 | 922 |
|
903 | 923 |
def FillBE(self, instance): |
904 | 924 |
"""Fill an instance's beparams dict. |
... | ... | |
911 | 931 |
|
912 | 932 |
""" |
913 | 933 |
return FillDict(self.beparams.get(constants.PP_DEFAULT, {}), |
914 |
instance.beparams)
|
|
934 |
instance.beparams) |
|
915 | 935 |
|
916 | 936 |
|
917 | 937 |
class BlockDevStatus(ConfigObject): |
Also available in: Unified diff