From 90b704a118cd101164e75b47b48a06476f8af1f3 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 12 Nov 2009 16:35:14 +0000 Subject: [PATCH] Fix change of cluster nic parameters To stay on the safe side, we check for errors in all instances, and refuse to act, reporting on the errors we found, if there are any problems. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cmdlib.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index aebb616d0..14df5b15b 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -1970,6 +1970,29 @@ class LUSetClusterParams(LogicalUnit): self.new_nicparams = objects.FillDict( cluster.nicparams[constants.PP_DEFAULT], self.op.nicparams) objects.NIC.CheckParameterSyntax(self.new_nicparams) + nic_errors = [] + + # check all instances for consistency + for instance in self.cfg.GetAllInstancesInfo().values(): + for nic_idx, nic in enumerate(instance.nics): + params_copy = copy.deepcopy(nic.nicparams) + params_filled = objects.FillDict(self.new_nicparams, params_copy) + + # check parameter syntax + try: + objects.NIC.CheckParameterSyntax(params_filled) + except errors.ConfigurationError, err: + nic_errors.append("Instance %s, nic/%d: %s" % + (instance.name, nic_idx, err)) + + # if we're moving instances to routed, check that they have an ip + target_mode = params_filled[constants.NIC_MODE] + if target_mode == constants.NIC_MODE_ROUTED and not nic.ip: + nic_errors.append("Instance %s, nic/%d: routed nick with no ip" % + (instance.name, nic_idx)) + if nic_errors: + raise errors.OpPrereqError("Cannot apply the change, errors:\n%s" % + "\n".join(nic_errors)) # hypervisor list/parameters self.new_hvparams = objects.FillDict(cluster.hvparams, {}) -- GitLab