Revision 21d70642 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
9754 | 9754 |
(self.op.name, self.op.node_name)) |
9755 | 9755 |
|
9756 | 9756 |
|
9757 |
class LUNodeEvacStrategy(NoHooksLU): |
|
9758 |
"""Computes the node evacuation strategy. |
|
9759 |
|
|
9760 |
""" |
|
9761 |
REQ_BGL = False |
|
9762 |
|
|
9763 |
def CheckArguments(self): |
|
9764 |
_CheckIAllocatorOrNode(self, "iallocator", "remote_node") |
|
9765 |
|
|
9766 |
def ExpandNames(self): |
|
9767 |
self.op.nodes = _GetWantedNodes(self, self.op.nodes) |
|
9768 |
self.needed_locks = locks = {} |
|
9769 |
if self.op.remote_node is None: |
|
9770 |
locks[locking.LEVEL_NODE] = locking.ALL_SET |
|
9771 |
else: |
|
9772 |
self.op.remote_node = _ExpandNodeName(self.cfg, self.op.remote_node) |
|
9773 |
locks[locking.LEVEL_NODE] = self.op.nodes + [self.op.remote_node] |
|
9774 |
|
|
9775 |
def Exec(self, feedback_fn): |
|
9776 |
instances = [] |
|
9777 |
for node in self.op.nodes: |
|
9778 |
instances.extend(_GetNodeSecondaryInstances(self.cfg, node)) |
|
9779 |
if not instances: |
|
9780 |
return [] |
|
9781 |
|
|
9782 |
if self.op.remote_node is not None: |
|
9783 |
result = [] |
|
9784 |
for i in instances: |
|
9785 |
if i.primary_node == self.op.remote_node: |
|
9786 |
raise errors.OpPrereqError("Node %s is the primary node of" |
|
9787 |
" instance %s, cannot use it as" |
|
9788 |
" secondary" % |
|
9789 |
(self.op.remote_node, i.name), |
|
9790 |
errors.ECODE_INVAL) |
|
9791 |
result.append([i.name, self.op.remote_node]) |
|
9792 |
else: |
|
9793 |
ial = IAllocator(self.cfg, self.rpc, |
|
9794 |
mode=constants.IALLOCATOR_MODE_MEVAC, |
|
9795 |
evac_nodes=self.op.nodes) |
|
9796 |
ial.Run(self.op.iallocator, validate=True) |
|
9797 |
if not ial.success: |
|
9798 |
raise errors.OpExecError("No valid evacuation solution: %s" % ial.info, |
|
9799 |
errors.ECODE_NORES) |
|
9800 |
result = ial.result |
|
9801 |
return result |
|
9802 |
|
|
9803 |
|
|
9804 | 9757 |
class LUNodeEvacuate(NoHooksLU): |
9805 | 9758 |
"""Evacuates instances off a list of nodes. |
9806 | 9759 |
|
Also available in: Unified diff