Revision b82d7182
b/lib/masterd/iallocator.py | ||
---|---|---|
518 | 518 |
return node_results |
519 | 519 |
|
520 | 520 |
@staticmethod |
521 |
def _GetAttributeFromNodeData(node_data, node_name, attr):
|
|
522 |
"""Helper function to extract an attribute from the node data dictionary.
|
|
521 |
def _GetAttributeFromHypervisorNodeData(hv_info, node_name, attr):
|
|
522 |
"""Extract an attribute from the hypervisor's node information.
|
|
523 | 523 |
|
524 |
@type node_data: dict of strings |
|
525 |
@param node_data: result of C{rpc.MakeLegacyNodeInfo} |
|
524 |
This is a helper function to extract data from the hypervisor's information |
|
525 |
about the node, as part of the result of a node_info query. |
|
526 |
|
|
527 |
@type hv_info: dict of strings |
|
528 |
@param hv_info: dictionary of node information from the hypervisor |
|
526 | 529 |
@type node_name: string |
527 | 530 |
@param node_name: name of the node |
528 | 531 |
@type attr: string |
529 |
@param attr: key of the attribute in the node_data dictionary
|
|
532 |
@param attr: key of the attribute in the hv_info dictionary
|
|
530 | 533 |
@rtype: integer |
531 | 534 |
@return: the value of the attribute |
532 | 535 |
@raises errors.OpExecError: if key not in dictionary or value not |
533 | 536 |
integer |
534 | 537 |
|
535 | 538 |
""" |
536 |
if attr not in node_data:
|
|
539 |
if attr not in hv_info:
|
|
537 | 540 |
raise errors.OpExecError("Node '%s' didn't return attribute" |
538 | 541 |
" '%s'" % (node_name, attr)) |
539 |
value = node_data[attr]
|
|
542 |
value = hv_info[attr]
|
|
540 | 543 |
if not isinstance(value, int): |
541 | 544 |
raise errors.OpExecError("Node '%s' returned invalid value" |
542 | 545 |
" for '%s': %s" % |
... | ... | |
630 | 633 |
nresult.Raise("Can't get data for node %s" % ninfo.name) |
631 | 634 |
node_iinfo[nuuid].Raise("Can't get node instance info from node %s" % |
632 | 635 |
ninfo.name) |
633 |
remote_info = rpc.MakeLegacyNodeInfo(nresult.payload, |
|
634 |
require_vg_info=has_lvm) |
|
636 |
(_, _, (hv_info, )) = nresult.payload |
|
635 | 637 |
|
636 |
mem_free = self._GetAttributeFromNodeData(remote_info, ninfo.name,
|
|
637 |
"memory_free") |
|
638 |
mem_free = self._GetAttributeFromHypervisorNodeData(hv_info, ninfo.name,
|
|
639 |
"memory_free")
|
|
638 | 640 |
|
639 | 641 |
(i_p_mem, i_p_up_mem, mem_free) = self._ComputeInstanceMemory( |
640 | 642 |
i_list, node_iinfo, nuuid, mem_free) |
... | ... | |
644 | 646 |
|
645 | 647 |
# compute memory used by instances |
646 | 648 |
pnr_dyn = { |
647 |
"total_memory": self._GetAttributeFromNodeData( |
|
648 |
remote_info, ninfo.name, "memory_total"),
|
|
649 |
"reserved_memory": self._GetAttributeFromNodeData( |
|
650 |
remote_info, ninfo.name, "memory_dom0"),
|
|
649 |
"total_memory": self._GetAttributeFromHypervisorNodeData(
|
|
650 |
hv_info, ninfo.name, "memory_total"),
|
|
651 |
"reserved_memory": self._GetAttributeFromHypervisorNodeData(
|
|
652 |
hv_info, ninfo.name, "memory_dom0"),
|
|
651 | 653 |
"free_memory": mem_free, |
652 | 654 |
"total_disk": total_disk, |
653 | 655 |
"free_disk": free_disk, |
654 | 656 |
"total_spindles": total_spindles, |
655 | 657 |
"free_spindles": free_spindles, |
656 |
"total_cpus": self._GetAttributeFromNodeData( |
|
657 |
remote_info, ninfo.name, "cpu_total"),
|
|
658 |
"total_cpus": self._GetAttributeFromHypervisorNodeData(
|
|
659 |
hv_info, ninfo.name, "cpu_total"),
|
|
658 | 660 |
"i_pri_memory": i_p_mem, |
659 | 661 |
"i_pri_up_memory": i_p_up_mem, |
660 | 662 |
} |
Also available in: Unified diff