Revision 1c3231aa lib/masterd/iallocator.py
b/lib/masterd/iallocator.py | ||
---|---|---|
234 | 234 |
MODE = constants.IALLOCATOR_MODE_RELOC |
235 | 235 |
REQ_PARAMS = [ |
236 | 236 |
_INST_NAME, |
237 |
("relocate_from", _STRING_LIST), |
|
237 |
("relocate_from_node_uuids", _STRING_LIST),
|
|
238 | 238 |
] |
239 | 239 |
REQ_RESULT = ht.TList |
240 | 240 |
|
... | ... | |
266 | 266 |
"name": self.name, |
267 | 267 |
"disk_space_total": disk_space, |
268 | 268 |
"required_nodes": 1, |
269 |
"relocate_from": self.relocate_from,
|
|
269 |
"relocate_from": cfg.GetNodeNames(self.relocate_from_node_uuids),
|
|
270 | 270 |
} |
271 | 271 |
|
272 | 272 |
def ValidateResult(self, ia, result): |
... | ... | |
282 | 282 |
ia.in_data["nodegroups"]) |
283 | 283 |
|
284 | 284 |
instance = ia.cfg.GetInstanceInfo(self.name) |
285 |
request_groups = fn(self.relocate_from + [instance.primary_node]) |
|
286 |
result_groups = fn(result + [instance.primary_node]) |
|
285 |
request_groups = fn(ia.cfg.GetNodeNames(self.relocate_from_node_uuids) + |
|
286 |
ia.cfg.GetNodeNames([instance.primary_node])) |
|
287 |
result_groups = fn(result + ia.cfg.GetNodeNames([instance.primary_node])) |
|
287 | 288 |
|
288 | 289 |
if ia.success and not set(result_groups).issubset(request_groups): |
289 | 290 |
raise errors.ResultValidationError("Groups of nodes returned by" |
290 |
"iallocator (%s) differ from original" |
|
291 |
" iallocator (%s) differ from original"
|
|
291 | 292 |
" groups (%s)" % |
292 | 293 |
(utils.CommaJoin(result_groups), |
293 | 294 |
utils.CommaJoin(request_groups))) |
... | ... | |
418 | 419 |
i_list = [(inst, cluster_info.FillBE(inst)) for inst in iinfo] |
419 | 420 |
|
420 | 421 |
# node data |
421 |
node_list = [n.name for n in ninfo.values() if n.vm_capable]
|
|
422 |
node_list = [n.uuid for n in ninfo.values() if n.vm_capable]
|
|
422 | 423 |
|
423 | 424 |
if isinstance(self.req, IAReqInstanceAlloc): |
424 | 425 |
hypervisor_name = self.req.hypervisor |
... | ... | |
430 | 431 |
hypervisor_name = cluster_info.primary_hypervisor |
431 | 432 |
node_whitelist = None |
432 | 433 |
|
433 |
es_flags = rpc.GetExclusiveStorageForNodeNames(cfg, node_list)
|
|
434 |
es_flags = rpc.GetExclusiveStorageForNodes(cfg, node_list) |
|
434 | 435 |
vg_req = rpc.BuildVgInfoQuery(cfg) |
435 | 436 |
has_lvm = bool(vg_req) |
436 | 437 |
hvspecs = [(hypervisor_name, cluster_info.hvparams[hypervisor_name])] |
... | ... | |
449 | 450 |
assert len(data["nodes"]) == len(ninfo), \ |
450 | 451 |
"Incomplete node data computed" |
451 | 452 |
|
452 |
data["instances"] = self._ComputeInstanceData(cluster_info, i_list) |
|
453 |
data["instances"] = self._ComputeInstanceData(cfg, cluster_info, i_list)
|
|
453 | 454 |
|
454 | 455 |
self.in_data = data |
455 | 456 |
|
... | ... | |
508 | 509 |
#TODO(dynmem): compute the right data on MAX and MIN memory |
509 | 510 |
# make a copy of the current dict |
510 | 511 |
node_results = dict(node_results) |
511 |
for nname, nresult in node_data.items(): |
|
512 |
assert nname in node_results, "Missing basic data for node %s" % nname |
|
513 |
ninfo = node_cfg[nname] |
|
512 |
for nuuid, nresult in node_data.items(): |
|
513 |
ninfo = node_cfg[nuuid] |
|
514 |
assert ninfo.name in node_results, "Missing basic data for node %s" % \ |
|
515 |
ninfo.name |
|
514 | 516 |
|
515 | 517 |
if not (ninfo.offline or ninfo.drained): |
516 |
nresult.Raise("Can't get data for node %s" % nname) |
|
517 |
node_iinfo[nname].Raise("Can't get node instance info from node %s" %
|
|
518 |
nname) |
|
518 |
nresult.Raise("Can't get data for node %s" % ninfo.name)
|
|
519 |
node_iinfo[nuuid].Raise("Can't get node instance info from node %s" %
|
|
520 |
ninfo.name)
|
|
519 | 521 |
remote_info = rpc.MakeLegacyNodeInfo(nresult.payload, |
520 | 522 |
require_vg_info=has_lvm) |
521 | 523 |
|
522 | 524 |
def get_attr(attr): |
523 | 525 |
if attr not in remote_info: |
524 | 526 |
raise errors.OpExecError("Node '%s' didn't return attribute" |
525 |
" '%s'" % (nname, attr)) |
|
527 |
" '%s'" % (ninfo.name, attr))
|
|
526 | 528 |
value = remote_info[attr] |
527 | 529 |
if not isinstance(value, int): |
528 | 530 |
raise errors.OpExecError("Node '%s' returned invalid value" |
529 | 531 |
" for '%s': %s" % |
530 |
(nname, attr, value)) |
|
532 |
(ninfo.name, attr, value))
|
|
531 | 533 |
return value |
532 | 534 |
|
533 | 535 |
mem_free = get_attr("memory_free") |
... | ... | |
535 | 537 |
# compute memory used by primary instances |
536 | 538 |
i_p_mem = i_p_up_mem = 0 |
537 | 539 |
for iinfo, beinfo in i_list: |
538 |
if iinfo.primary_node == nname:
|
|
540 |
if iinfo.primary_node == nuuid:
|
|
539 | 541 |
i_p_mem += beinfo[constants.BE_MAXMEM] |
540 |
if iinfo.name not in node_iinfo[nname].payload:
|
|
542 |
if iinfo.name not in node_iinfo[nuuid].payload:
|
|
541 | 543 |
i_used_mem = 0 |
542 | 544 |
else: |
543 |
i_used_mem = int(node_iinfo[nname].payload[iinfo.name]["memory"])
|
|
545 |
i_used_mem = int(node_iinfo[nuuid].payload[iinfo.name]["memory"])
|
|
544 | 546 |
i_mem_diff = beinfo[constants.BE_MAXMEM] - i_used_mem |
545 | 547 |
mem_free -= max(0, i_mem_diff) |
546 | 548 |
|
... | ... | |
571 | 573 |
"i_pri_memory": i_p_mem, |
572 | 574 |
"i_pri_up_memory": i_p_up_mem, |
573 | 575 |
} |
574 |
pnr_dyn.update(node_results[nname]) |
|
575 |
node_results[nname] = pnr_dyn |
|
576 |
pnr_dyn.update(node_results[ninfo.name])
|
|
577 |
node_results[ninfo.name] = pnr_dyn
|
|
576 | 578 |
|
577 | 579 |
return node_results |
578 | 580 |
|
579 | 581 |
@staticmethod |
580 |
def _ComputeInstanceData(cluster_info, i_list): |
|
582 |
def _ComputeInstanceData(cfg, cluster_info, i_list):
|
|
581 | 583 |
"""Compute global instance data. |
582 | 584 |
|
583 | 585 |
""" |
... | ... | |
602 | 604 |
"memory": beinfo[constants.BE_MAXMEM], |
603 | 605 |
"spindle_use": beinfo[constants.BE_SPINDLE_USE], |
604 | 606 |
"os": iinfo.os, |
605 |
"nodes": [iinfo.primary_node] + list(iinfo.secondary_nodes), |
|
607 |
"nodes": [cfg.GetNodeName(iinfo.primary_node)] + |
|
608 |
cfg.GetNodeNames(iinfo.secondary_nodes), |
|
606 | 609 |
"nics": nic_data, |
607 | 610 |
"disks": [{constants.IDISK_SIZE: dsk.size, |
608 | 611 |
constants.IDISK_MODE: dsk.mode, |
Also available in: Unified diff