Commit 92ff96e8 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

cmdlib: Add a helper function for a set of violating instances



This helper will be used with the Op*SetParams and ipolicy verifications
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent d04c9d45
...@@ -1196,6 +1196,19 @@ def _CheckTargetNodeIPolicy(lu, ipolicy, instance, node, ignore=False, ...@@ -1196,6 +1196,19 @@ def _CheckTargetNodeIPolicy(lu, ipolicy, instance, node, ignore=False,
raise errors.OpPrereqError(msg, errors.ECODE_INVAL) raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
   
   
def _ComputeNewInstanceViolations(old_ipolicy, new_ipolicy, instances):
"""Computes a set of any instances that would violate the new ipolicy.
@param old_ipolicy: The current (still in-place) ipolicy
@param new_ipolicy: The new (to become) ipolicy
@param instances: List of instances to verify
@return: A list of instances which violates the new ipolicy but did not before
"""
return (_ComputeViolatingInstances(old_ipolicy, instances) -
_ComputeViolatingInstances(new_ipolicy, instances))
def _ExpandItemName(fn, name, kind): def _ExpandItemName(fn, name, kind):
"""Expand an item name. """Expand an item name.
   
...@@ -1416,6 +1429,19 @@ def _CalculateGroupIPolicy(cluster, group): ...@@ -1416,6 +1429,19 @@ def _CalculateGroupIPolicy(cluster, group):
return cluster.SimpleFillIPolicy(group.ipolicy) return cluster.SimpleFillIPolicy(group.ipolicy)
   
   
def _ComputeViolatingInstances(ipolicy, instances):
"""Computes a set of instances who violates given ipolicy.
@param ipolicy: The ipolicy to verify
@type instances: object.Instance
@param instances: List of instances to verify
@return: A frozenset of instance names violating the ipolicy
"""
return frozenset([inst.name for inst in instances
if _ComputeIPolicyInstanceViolation(ipolicy, inst)])
def _CheckNicsBridgesExist(lu, target_nics, target_node): def _CheckNicsBridgesExist(lu, target_nics, target_node):
"""Check that the brigdes needed by a list of nics exist. """Check that the brigdes needed by a list of nics exist.
   
......
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