From 6bb939a2171bcfa554736260543c0bd7b5ae0e51 Mon Sep 17 00:00:00 2001 From: Helga Velroyen <helgav@google.com> Date: Wed, 30 Jan 2013 17:12:26 +0100 Subject: [PATCH] Force conflicts check in LUNetworkDisconnect Until now if one disconnects a network with --no-conflicts-check and then remove it, there is a possibility to leave instances with NICs referencing non-existing networks. This causes network queries, instance removal and modification to fail. This patch allows a network to be disconnected from a nodegroup, only if instances residing in the nodegroup do not have NICs attached to the network. Otherwise OpPrereqError is raised. The --no-conflicts-check option is removed from the gnt-network disconnect command as well. Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr> Reviewed-by: Helga Velroyen <helgav@google.com> --- lib/client/gnt_network.py | 5 ++--- lib/cmdlib.py | 10 ++++------ lib/opcodes.py | 1 - 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py index b07aa7a8a..a51d51198 100644 --- a/lib/client/gnt_network.py +++ b/lib/client/gnt_network.py @@ -144,8 +144,7 @@ def DisconnectNetwork(opts, args): # TODO: Change logic to support "--submit" for group in groups: op = opcodes.OpNetworkDisconnect(group_name=group, - network_name=network, - conflicts_check=opts.conflicts_check) + network_name=network) SubmitOpCode(op, opts=opts, cl=cl) @@ -349,7 +348,7 @@ commands = { "disconnect": ( DisconnectNetwork, [ArgNetwork(min=1, max=1), ArgGroup()], - [NOCONFLICTSCHECK_OPT, PRIORITY_OPT], + [PRIORITY_OPT], "<network_name> [<node_group>...]", "Unmap a given network from a specified node group"), "remove": ( diff --git a/lib/cmdlib.py b/lib/cmdlib.py index d14bb65e0..5798c6fa9 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -16811,9 +16811,8 @@ class LUNetworkDisconnect(LogicalUnit): # Lock instances optimistically, needs verification once group lock has # been acquired - if self.op.conflicts_check: - self.needed_locks[locking.LEVEL_INSTANCE] = \ - self.cfg.GetNodeGroupInstances(self.group_uuid) + self.needed_locks[locking.LEVEL_INSTANCE] = \ + self.cfg.GetNodeGroupInstances(self.group_uuid) def BuildHooksEnv(self): ret = { @@ -16838,9 +16837,8 @@ class LUNetworkDisconnect(LogicalUnit): self.connected = False return - if self.op.conflicts_check: - _NetworkConflictCheck(self, lambda nic: nic.network == self.network_name, - "disconnect from") + _NetworkConflictCheck(self, lambda nic: nic.network == self.network_name, + "disconnect from") def Exec(self, feedback_fn): if not self.connected: diff --git a/lib/opcodes.py b/lib/opcodes.py index 2c88363b1..e53331003 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -2143,7 +2143,6 @@ class OpNetworkDisconnect(OpCode): OP_PARAMS = [ _PGroupName, _PNetworkName, - ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"), ] OP_RESULT = ht.TNone -- GitLab