Revision 50722bfd lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
10114 | 10114 |
locking.LEVEL_NODE: [], |
10115 | 10115 |
} |
10116 | 10116 |
|
10117 |
# Determine nodes (via group) optimistically, needs verification once locks |
|
10118 |
# have been acquired |
|
10119 |
self.lock_nodes = self._DetermineNodes() |
|
10120 |
|
|
10121 |
def _DetermineNodes(self): |
|
10122 |
"""Gets the list of nodes to operate on. |
|
10123 |
|
|
10124 |
""" |
|
10117 | 10125 |
if self.op.remote_node is None: |
10118 | 10126 |
# Iallocator will choose any node(s) in the same group |
10119 | 10127 |
group_nodes = self.cfg.GetNodeGroupMembersByNodes([self.op.node_name]) |
... | ... | |
10121 | 10129 |
group_nodes = frozenset([self.op.remote_node]) |
10122 | 10130 |
|
10123 | 10131 |
# Determine nodes to be locked |
10124 |
self.lock_nodes = set([self.op.node_name]) | group_nodes
|
|
10132 |
return set([self.op.node_name]) | group_nodes
|
|
10125 | 10133 |
|
10126 | 10134 |
def _DetermineInstances(self): |
10127 | 10135 |
"""Builds list of instances to operate on. |
... | ... | |
10152 | 10160 |
set(i.name for i in self._DetermineInstances()) |
10153 | 10161 |
|
10154 | 10162 |
elif level == locking.LEVEL_NODEGROUP: |
10155 |
# Lock node groups optimistically, needs verification once nodes have
|
|
10156 |
# been acquired |
|
10163 |
# Lock node groups for all potential target nodes optimistically, needs
|
|
10164 |
# verification once nodes have been acquired
|
|
10157 | 10165 |
self.needed_locks[locking.LEVEL_NODEGROUP] = \ |
10158 | 10166 |
self.cfg.GetNodeGroupsFromNodes(self.lock_nodes) |
10159 | 10167 |
|
... | ... | |
10166 | 10174 |
owned_nodes = self.owned_locks(locking.LEVEL_NODE) |
10167 | 10175 |
owned_groups = self.owned_locks(locking.LEVEL_NODEGROUP) |
10168 | 10176 |
|
10169 |
assert owned_nodes == self.lock_nodes |
|
10177 |
need_nodes = self._DetermineNodes() |
|
10178 |
|
|
10179 |
if not owned_nodes.issuperset(need_nodes): |
|
10180 |
raise errors.OpPrereqError("Nodes in same group as '%s' changed since" |
|
10181 |
" locks were acquired, current nodes are" |
|
10182 |
" are '%s', used to be '%s'; retry the" |
|
10183 |
" operation" % |
|
10184 |
(self.op.node_name, |
|
10185 |
utils.CommaJoin(need_nodes), |
|
10186 |
utils.CommaJoin(owned_nodes)), |
|
10187 |
errors.ECODE_STATE) |
|
10170 | 10188 |
|
10171 | 10189 |
wanted_groups = self.cfg.GetNodeGroupsFromNodes(owned_nodes) |
10172 | 10190 |
if owned_groups != wanted_groups: |
10173 | 10191 |
raise errors.OpExecError("Node groups changed since locks were acquired," |
10174 |
" current groups are '%s', used to be '%s'" % |
|
10192 |
" current groups are '%s', used to be '%s';" |
|
10193 |
" retry the operation" % |
|
10175 | 10194 |
(utils.CommaJoin(wanted_groups), |
10176 | 10195 |
utils.CommaJoin(owned_groups))) |
10177 | 10196 |
|
... | ... | |
10182 | 10201 |
if set(self.instance_names) != owned_instances: |
10183 | 10202 |
raise errors.OpExecError("Instances on node '%s' changed since locks" |
10184 | 10203 |
" were acquired, current instances are '%s'," |
10185 |
" used to be '%s'" % |
|
10204 |
" used to be '%s'; retry the operation" %
|
|
10186 | 10205 |
(self.op.node_name, |
10187 | 10206 |
utils.CommaJoin(self.instance_names), |
10188 | 10207 |
utils.CommaJoin(owned_instances))) |
Also available in: Unified diff