Revision eba4d783 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
11262 | 11262 |
" pnode/snode while others do not", |
11263 | 11263 |
errors.ECODE_INVAL) |
11264 | 11264 |
|
11265 |
if self.op.iallocator is None: |
|
11265 |
if not has_nodes and self.op.iallocator is None:
|
|
11266 | 11266 |
default_iallocator = self.cfg.GetDefaultIAllocator() |
11267 |
if default_iallocator and has_nodes:
|
|
11267 |
if default_iallocator: |
|
11268 | 11268 |
self.op.iallocator = default_iallocator |
11269 | 11269 |
else: |
11270 | 11270 |
raise errors.OpPrereqError("No iallocator or nodes on the instances" |
... | ... | |
11317 | 11317 |
"""Check prerequisite. |
11318 | 11318 |
|
11319 | 11319 |
""" |
11320 |
cluster = self.cfg.GetClusterInfo() |
|
11321 |
default_vg = self.cfg.GetVGName() |
|
11322 |
ec_id = self.proc.GetECId() |
|
11320 |
if self.op.iallocator: |
|
11321 |
cluster = self.cfg.GetClusterInfo() |
|
11322 |
default_vg = self.cfg.GetVGName() |
|
11323 |
ec_id = self.proc.GetECId() |
|
11323 | 11324 |
|
11324 |
if self.op.opportunistic_locking: |
|
11325 |
# Only consider nodes for which a lock is held |
|
11326 |
node_whitelist = list(self.owned_locks(locking.LEVEL_NODE)) |
|
11327 |
else: |
|
11328 |
node_whitelist = None |
|
11325 |
if self.op.opportunistic_locking:
|
|
11326 |
# Only consider nodes for which a lock is held
|
|
11327 |
node_whitelist = list(self.owned_locks(locking.LEVEL_NODE))
|
|
11328 |
else:
|
|
11329 |
node_whitelist = None
|
|
11329 | 11330 |
|
11330 |
insts = [_CreateInstanceAllocRequest(op, _ComputeDisks(op, default_vg), |
|
11331 |
_ComputeNics(op, cluster, None, |
|
11332 |
self.cfg, ec_id), |
|
11333 |
_ComputeFullBeParams(op, cluster), |
|
11334 |
node_whitelist) |
|
11335 |
for op in self.op.instances] |
|
11331 |
insts = [_CreateInstanceAllocRequest(op, _ComputeDisks(op, default_vg),
|
|
11332 |
_ComputeNics(op, cluster, None,
|
|
11333 |
self.cfg, ec_id),
|
|
11334 |
_ComputeFullBeParams(op, cluster),
|
|
11335 |
node_whitelist)
|
|
11336 |
for op in self.op.instances]
|
|
11336 | 11337 |
|
11337 |
req = iallocator.IAReqMultiInstanceAlloc(instances=insts) |
|
11338 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
11338 |
req = iallocator.IAReqMultiInstanceAlloc(instances=insts)
|
|
11339 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req)
|
|
11339 | 11340 |
|
11340 |
ial.Run(self.op.iallocator) |
|
11341 |
ial.Run(self.op.iallocator)
|
|
11341 | 11342 |
|
11342 |
if not ial.success: |
|
11343 |
raise errors.OpPrereqError("Can't compute nodes using" |
|
11344 |
" iallocator '%s': %s" % |
|
11345 |
(self.op.iallocator, ial.info), |
|
11346 |
errors.ECODE_NORES) |
|
11343 |
if not ial.success:
|
|
11344 |
raise errors.OpPrereqError("Can't compute nodes using"
|
|
11345 |
" iallocator '%s': %s" %
|
|
11346 |
(self.op.iallocator, ial.info),
|
|
11347 |
errors.ECODE_NORES)
|
|
11347 | 11348 |
|
11348 |
self.ia_result = ial.result |
|
11349 |
self.ia_result = ial.result
|
|
11349 | 11350 |
|
11350 | 11351 |
if self.op.dry_run: |
11351 | 11352 |
self.dry_run_result = objects.FillDict(self._ConstructPartialResult(), { |
... | ... | |
11356 | 11357 |
"""Contructs the partial result. |
11357 | 11358 |
|
11358 | 11359 |
""" |
11359 |
(allocatable, failed) = self.ia_result |
|
11360 |
if self.op.iallocator: |
|
11361 |
(allocatable, failed_insts) = self.ia_result |
|
11362 |
allocatable_insts = map(compat.fst, allocatable) |
|
11363 |
else: |
|
11364 |
allocatable_insts = [op.instance_name for op in self.op.instances] |
|
11365 |
failed_insts = [] |
|
11366 |
|
|
11360 | 11367 |
return { |
11361 |
opcodes.OpInstanceMultiAlloc.ALLOCATABLE_KEY: |
|
11362 |
map(compat.fst, allocatable), |
|
11363 |
opcodes.OpInstanceMultiAlloc.FAILED_KEY: failed, |
|
11368 |
opcodes.OpInstanceMultiAlloc.ALLOCATABLE_KEY: allocatable_insts, |
|
11369 |
opcodes.OpInstanceMultiAlloc.FAILED_KEY: failed_insts, |
|
11364 | 11370 |
} |
11365 | 11371 |
|
11366 | 11372 |
def Exec(self, feedback_fn): |
11367 | 11373 |
"""Executes the opcode. |
11368 | 11374 |
|
11369 | 11375 |
""" |
11370 |
op2inst = dict((op.instance_name, op) for op in self.op.instances) |
|
11371 |
(allocatable, failed) = self.ia_result |
|
11372 |
|
|
11373 | 11376 |
jobs = [] |
11374 |
for (name, nodes) in allocatable: |
|
11375 |
op = op2inst.pop(name) |
|
11377 |
if self.op.iallocator: |
|
11378 |
op2inst = dict((op.instance_name, op) for op in self.op.instances) |
|
11379 |
(allocatable, failed) = self.ia_result |
|
11376 | 11380 |
|
11377 |
if len(nodes) > 1: |
|
11378 |
(op.pnode, op.snode) = nodes |
|
11379 |
else: |
|
11380 |
(op.pnode,) = nodes |
|
11381 |
for (name, nodes) in allocatable: |
|
11382 |
op = op2inst.pop(name) |
|
11383 |
|
|
11384 |
if len(nodes) > 1: |
|
11385 |
(op.pnode, op.snode) = nodes |
|
11386 |
else: |
|
11387 |
(op.pnode,) = nodes |
|
11381 | 11388 |
|
11382 |
jobs.append([op]) |
|
11389 |
jobs.append([op])
|
|
11383 | 11390 |
|
11384 |
missing = set(op2inst.keys()) - set(failed) |
|
11385 |
assert not missing, \ |
|
11386 |
"Iallocator did return incomplete result: %s" % utils.CommaJoin(missing) |
|
11391 |
missing = set(op2inst.keys()) - set(failed) |
|
11392 |
assert not missing, \ |
|
11393 |
"Iallocator did return incomplete result: %s" % \ |
|
11394 |
utils.CommaJoin(missing) |
|
11395 |
else: |
|
11396 |
jobs.extend([op] for op in self.op.instances) |
|
11387 | 11397 |
|
11388 | 11398 |
return ResultWithJobs(jobs, **self._ConstructPartialResult()) |
11389 | 11399 |
|
Also available in: Unified diff