10220 |
10220 |
|
10221 |
10221 |
# We want to lock all the affected nodes and groups. We have readily
|
10222 |
10222 |
# available the list of nodes, and the *destination* group. To gather the
|
10223 |
|
# list of "source" groups, we need to fetch node information.
|
10224 |
|
self.node_data = self.cfg.GetAllNodesInfo()
|
10225 |
|
affected_groups = set(self.node_data[node].group for node in self.op.nodes)
|
10226 |
|
affected_groups.add(self.group_uuid)
|
10227 |
|
|
|
10223 |
# list of "source" groups, we need to fetch node information later on.
|
10228 |
10224 |
self.needed_locks = {
|
10229 |
|
locking.LEVEL_NODEGROUP: list(affected_groups),
|
|
10225 |
locking.LEVEL_NODEGROUP: set([self.group_uuid]),
|
10230 |
10226 |
locking.LEVEL_NODE: self.op.nodes,
|
10231 |
10227 |
}
|
10232 |
10228 |
|
|
10229 |
def DeclareLocks(self, level):
|
|
10230 |
if level == locking.LEVEL_NODEGROUP:
|
|
10231 |
assert len(self.needed_locks[locking.LEVEL_NODEGROUP]) == 1
|
|
10232 |
|
|
10233 |
# Try to get all affected nodes' groups without having the group or node
|
|
10234 |
# lock yet. Needs verification later in the code flow.
|
|
10235 |
groups = self.cfg.GetNodeGroupsFromNodes(self.op.nodes)
|
|
10236 |
|
|
10237 |
self.needed_locks[locking.LEVEL_NODEGROUP].update(groups)
|
|
10238 |
|
10233 |
10239 |
def CheckPrereq(self):
|
10234 |
10240 |
"""Check prerequisites.
|
10235 |
10241 |
|
10236 |
10242 |
"""
|
|
10243 |
assert self.needed_locks[locking.LEVEL_NODEGROUP]
|
|
10244 |
assert (frozenset(self.acquired_locks[locking.LEVEL_NODE]) ==
|
|
10245 |
frozenset(self.op.nodes))
|
|
10246 |
|
|
10247 |
expected_locks = (set([self.group_uuid]) |
|
|
10248 |
self.cfg.GetNodeGroupsFromNodes(self.op.nodes))
|
|
10249 |
actual_locks = self.acquired_locks[locking.LEVEL_NODEGROUP]
|
|
10250 |
if actual_locks != expected_locks:
|
|
10251 |
raise errors.OpExecError("Nodes changed groups since locks were acquired,"
|
|
10252 |
" current groups are '%s', used to be '%s'" %
|
|
10253 |
(utils.CommaJoin(expected_locks),
|
|
10254 |
utils.CommaJoin(actual_locks)))
|
|
10255 |
|
|
10256 |
self.node_data = self.cfg.GetAllNodesInfo()
|
10237 |
10257 |
self.group = self.cfg.GetNodeGroup(self.group_uuid)
|
10238 |
10258 |
instance_data = self.cfg.GetAllInstancesInfo()
|
10239 |
10259 |
|
... | ... | |
10269 |
10289 |
for node in self.op.nodes:
|
10270 |
10290 |
self.node_data[node].group = self.group_uuid
|
10271 |
10291 |
|
|
10292 |
# FIXME: Depends on side-effects of modifying the result of
|
|
10293 |
# C{cfg.GetAllNodesInfo}
|
|
10294 |
|
10272 |
10295 |
self.cfg.Update(self.group, feedback_fn) # Saves all modified nodes.
|
10273 |
10296 |
|
10274 |
10297 |
@staticmethod
|