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

_CheckInstanceBridgesExist: move to NIC parameters



Rather than checking all bridges, we check all links for bridged nics,
if any. Since this function is now slightly more complex than before,
it's been split into an auxiliary function, and more parameters are
used, so that it can be called from more places, rather than
reimplementing the same code there.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent cd098c41
...@@ -574,18 +574,32 @@ def _AdjustCandidatePool(lu): ...@@ -574,18 +574,32 @@ def _AdjustCandidatePool(lu):
(mc_now, mc_max)) (mc_now, mc_max))
def _CheckInstanceBridgesExist(lu, instance): def _CheckNicsBridgesExist(lu, target_nics, target_node,
profile=constants.PP_DEFAULT):
"""Check that the brigdes needed by a list of nics exist.
"""
c_nicparams = lu.cfg.GetClusterInfo().nicparams[profile]
paramslist = [objects.FillDict(c_nicparams, nic.nicparams)
for nic in target_nics]
brlist = [params[constants.NIC_LINK] for params in paramslist
if params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED]
if brlist:
result = lu.rpc.call_bridges_exist(target_node, brlist)
result.Raise()
if not result.data:
raise errors.OpPrereqError("One or more target bridges %s does not"
" exist on destination node '%s'" %
(brlist, target_node))
def _CheckInstanceBridgesExist(lu, instance, node=None):
"""Check that the brigdes needed by an instance exist. """Check that the brigdes needed by an instance exist.
""" """
# check bridges existance if node is None:
brlist = [nic.bridge for nic in instance.nics] node=instance.primary_node
result = lu.rpc.call_bridges_exist(instance.primary_node, brlist) _CheckNicsBridgesExist(lu, instance.nics, node)
result.Raise()
if not result.data:
raise errors.OpPrereqError("One or more target bridges %s does not"
" exist on destination node '%s'" %
(brlist, instance.primary_node))
class LUDestroyCluster(NoHooksLU): class LUDestroyCluster(NoHooksLU):
...@@ -3600,15 +3614,8 @@ class LUFailoverInstance(LogicalUnit): ...@@ -3600,15 +3614,8 @@ class LUFailoverInstance(LogicalUnit):
_CheckNodeFreeMemory(self, target_node, "failing over instance %s" % _CheckNodeFreeMemory(self, target_node, "failing over instance %s" %
instance.name, bep[constants.BE_MEMORY], instance.name, bep[constants.BE_MEMORY],
instance.hypervisor) instance.hypervisor)
# check bridge existance # check bridge existance
brlist = [nic.bridge for nic in instance.nics] _CheckInstanceBridgesExist(self, instance, node=target_node)
result = self.rpc.call_bridges_exist(target_node, brlist)
result.Raise()
if not result.data:
raise errors.OpPrereqError("One or more target bridges %s does not"
" exist on destination node '%s'" %
(brlist, target_node))
def Exec(self, feedback_fn): def Exec(self, feedback_fn):
"""Failover an instance. """Failover an instance.
...@@ -3740,12 +3747,7 @@ class LUMigrateInstance(LogicalUnit): ...@@ -3740,12 +3747,7 @@ class LUMigrateInstance(LogicalUnit):
instance.hypervisor) instance.hypervisor)
# check bridge existance # check bridge existance
brlist = [nic.bridge for nic in instance.nics] _CheckInstanceBridgesExist(self, instance, node=target_node)
result = self.rpc.call_bridges_exist(target_node, brlist)
if result.failed or not result.data:
raise errors.OpPrereqError("One or more target bridges %s does not"
" exist on destination node '%s'" %
(brlist, target_node))
if not self.op.cleanup: if not self.op.cleanup:
_CheckNodeNotDrained(self, target_node) _CheckNodeNotDrained(self, target_node)
...@@ -4795,14 +4797,7 @@ class LUCreateInstance(LogicalUnit): ...@@ -4795,14 +4797,7 @@ class LUCreateInstance(LogicalUnit):
raise errors.OpPrereqError("OS '%s' not in supported os list for" raise errors.OpPrereqError("OS '%s' not in supported os list for"
" primary node" % self.op.os_type) " primary node" % self.op.os_type)
# bridge check on primary node _CheckNicsBridgesExist(self, self.nics, self.pnode.name)
bridges = [n.bridge for n in self.nics]
result = self.rpc.call_bridges_exist(self.pnode.name, bridges)
result.Raise()
if not result.data:
raise errors.OpPrereqError("One of the target bridges '%s' does not"
" exist on destination node '%s'" %
(",".join(bridges), pnode.name))
# memory check on primary node # memory check on primary node
if self.op.start: if self.op.start:
......
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