Revision 36a566e8 lib/masterd/iallocator.py
b/lib/masterd/iallocator.py | ||
---|---|---|
431 | 431 |
node_whitelist = None |
432 | 432 |
|
433 | 433 |
es_flags = rpc.GetExclusiveStorageForNodeNames(cfg, node_list) |
434 |
node_data = self.rpc.call_node_info(node_list, [cfg.GetVGName()], |
|
434 |
vg_name = cfg.GetVGName() |
|
435 |
if vg_name is not None: |
|
436 |
has_lvm = True |
|
437 |
vg_req = [vg_name] |
|
438 |
else: |
|
439 |
has_lvm = False |
|
440 |
vg_req = [] |
|
441 |
node_data = self.rpc.call_node_info(node_list, vg_req, |
|
435 | 442 |
[hypervisor_name], es_flags) |
436 | 443 |
node_iinfo = \ |
437 | 444 |
self.rpc.call_all_instances_info(node_list, |
... | ... | |
441 | 448 |
|
442 | 449 |
config_ndata = self._ComputeBasicNodeData(cfg, ninfo, node_whitelist) |
443 | 450 |
data["nodes"] = self._ComputeDynamicNodeData(ninfo, node_data, node_iinfo, |
444 |
i_list, config_ndata) |
|
451 |
i_list, config_ndata, has_lvm)
|
|
445 | 452 |
assert len(data["nodes"]) == len(ninfo), \ |
446 | 453 |
"Incomplete node data computed" |
447 | 454 |
|
... | ... | |
494 | 501 |
|
495 | 502 |
@staticmethod |
496 | 503 |
def _ComputeDynamicNodeData(node_cfg, node_data, node_iinfo, i_list, |
497 |
node_results): |
|
504 |
node_results, has_lvm):
|
|
498 | 505 |
"""Compute global node data. |
499 | 506 |
|
500 | 507 |
@param node_results: the basic node structures as filled from the config |
... | ... | |
511 | 518 |
nresult.Raise("Can't get data for node %s" % nname) |
512 | 519 |
node_iinfo[nname].Raise("Can't get node instance info from node %s" % |
513 | 520 |
nname) |
514 |
remote_info = rpc.MakeLegacyNodeInfo(nresult.payload) |
|
521 |
remote_info = rpc.MakeLegacyNodeInfo(nresult.payload, |
|
522 |
require_vg_info=has_lvm) |
|
515 | 523 |
|
516 |
for attr in ["memory_total", "memory_free", "memory_dom0", |
|
517 |
"vg_size", "vg_free", "cpu_total"]: |
|
524 |
def get_attr(attr): |
|
518 | 525 |
if attr not in remote_info: |
519 | 526 |
raise errors.OpExecError("Node '%s' didn't return attribute" |
520 | 527 |
" '%s'" % (nname, attr)) |
521 |
if not isinstance(remote_info[attr], int): |
|
528 |
value = remote_info[attr] |
|
529 |
if not isinstance(value, int): |
|
522 | 530 |
raise errors.OpExecError("Node '%s' returned invalid value" |
523 | 531 |
" for '%s': %s" % |
524 |
(nname, attr, remote_info[attr])) |
|
532 |
(nname, attr, value)) |
|
533 |
return value |
|
534 |
|
|
535 |
mem_free = get_attr("memory_free") |
|
536 |
|
|
525 | 537 |
# compute memory used by primary instances |
526 | 538 |
i_p_mem = i_p_up_mem = 0 |
527 | 539 |
for iinfo, beinfo in i_list: |
... | ... | |
532 | 544 |
else: |
533 | 545 |
i_used_mem = int(node_iinfo[nname].payload[iinfo.name]["memory"]) |
534 | 546 |
i_mem_diff = beinfo[constants.BE_MAXMEM] - i_used_mem |
535 |
remote_info["memory_free"] -= max(0, i_mem_diff)
|
|
547 |
mem_free -= max(0, i_mem_diff)
|
|
536 | 548 |
|
537 | 549 |
if iinfo.admin_state == constants.ADMINST_UP: |
538 | 550 |
i_p_up_mem += beinfo[constants.BE_MAXMEM] |
539 | 551 |
|
552 |
# TODO: replace this with proper storage reporting |
|
553 |
if has_lvm: |
|
554 |
total_disk = get_attr("vg_size") |
|
555 |
free_disk = get_attr("vg_free") |
|
556 |
else: |
|
557 |
# we didn't even ask the node for VG status, so use zeros |
|
558 |
total_disk = free_disk = 0 |
|
559 |
|
|
540 | 560 |
# compute memory used by instances |
541 | 561 |
pnr_dyn = { |
542 |
"total_memory": remote_info["memory_total"],
|
|
543 |
"reserved_memory": remote_info["memory_dom0"],
|
|
544 |
"free_memory": remote_info["memory_free"],
|
|
545 |
"total_disk": remote_info["vg_size"],
|
|
546 |
"free_disk": remote_info["vg_free"],
|
|
547 |
"total_cpus": remote_info["cpu_total"],
|
|
562 |
"total_memory": get_attr("memory_total"),
|
|
563 |
"reserved_memory": get_attr("memory_dom0"),
|
|
564 |
"free_memory": mem_free,
|
|
565 |
"total_disk": total_disk,
|
|
566 |
"free_disk": free_disk,
|
|
567 |
"total_cpus": get_attr("cpu_total"),
|
|
548 | 568 |
"i_pri_memory": i_p_mem, |
549 | 569 |
"i_pri_up_memory": i_p_up_mem, |
550 | 570 |
} |
Also available in: Unified diff