Commit 6bb939a2 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

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: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent ea2bcb82
......@@ -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": (
......
......@@ -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:
......
......@@ -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
......
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