Revision 32389d91 lib/rpc.py
b/lib/rpc.py | ||
---|---|---|
592 | 592 |
return [(d.ToDict(), uid) for d, uid in value] |
593 | 593 |
|
594 | 594 |
|
595 |
def BuildVgInfoQuery(cfg): |
|
596 |
"""Build a query about the default VG for C{node_info}. |
|
595 |
def _AddSpindlesToLegacyNodeInfo(result, space_info): |
|
596 |
"""Extracts the spindle information from the space info and adds |
|
597 |
it to the result dictionary. |
|
598 |
|
|
599 |
@type result: dict of strings |
|
600 |
@param result: dictionary holding the result of the legacy node info |
|
601 |
@type space_info: list of dicts of strings |
|
602 |
@param space_info: list, each row holding space information of one storage |
|
603 |
unit |
|
604 |
@rtype: None |
|
605 |
@return: does not return anything, manipulates the C{result} variable |
|
597 | 606 |
|
598 |
The result of the RPC can be parsed with L{MakeLegacyNodeInfo}. |
|
607 |
""" |
|
608 |
lvm_pv_info = utils.storage.LookupSpaceInfoByStorageType( |
|
609 |
space_info, constants.ST_LVM_PV) |
|
610 |
if lvm_pv_info: |
|
611 |
result["spindles_free"] = lvm_pv_info["storage_free"] |
|
612 |
result["spindles_total"] = lvm_pv_info["storage_size"] |
|
599 | 613 |
|
600 |
@type cfg: L{config.ConfigWriter} |
|
601 |
@param cfg: Cluster configuration |
|
602 |
@rtype: list |
|
603 |
@return: argument suitable for L{rpc.RpcRunner.call_node_info} |
|
614 |
|
|
615 |
def _AddDefaultStorageInfoToLegacyNodeInfo(result, space_info, |
|
616 |
require_vg_info=True): |
|
617 |
"""Extracts the storage space information of the default storage type from |
|
618 |
the space info and adds it to the result dictionary. |
|
619 |
|
|
620 |
@see: C{_AddSpindlesToLegacyNodeInfo} for parameter information. |
|
621 |
@type require_vg_info: boolean |
|
622 |
@param require_vg_info: indicates whether volume group information is |
|
623 |
required or not |
|
604 | 624 |
|
605 | 625 |
""" |
606 |
vg_name = cfg.GetVGName() |
|
607 |
if vg_name: |
|
608 |
ret = [ |
|
609 |
(constants.ST_LVM_VG, vg_name), |
|
610 |
(constants.ST_LVM_PV, vg_name), |
|
611 |
] |
|
626 |
# Check if there is at least one row for non-spindle storage info. |
|
627 |
no_defaults = (len(space_info) < 1) or \ |
|
628 |
(space_info[0]["type"] == constants.ST_LVM_PV and len(space_info) == 1) |
|
629 |
|
|
630 |
default_space_info = None |
|
631 |
if no_defaults: |
|
632 |
logging.warning("No storage info provided for default storage type.") |
|
612 | 633 |
else: |
613 |
ret = [] |
|
614 |
return ret |
|
634 |
default_space_info = space_info[0] |
|
635 |
|
|
636 |
if require_vg_info: |
|
637 |
if no_defaults or not default_space_info["type"] == constants.ST_LVM_VG: |
|
638 |
raise errors.OpExecError("LVM volume group info required, but not" |
|
639 |
" provided.") |
|
640 |
|
|
641 |
if default_space_info: |
|
642 |
result["name"] = default_space_info["name"] |
|
643 |
result["storage_free"] = default_space_info["storage_free"] |
|
644 |
result["storage_size"] = default_space_info["storage_size"] |
|
615 | 645 |
|
616 | 646 |
|
617 | 647 |
def MakeLegacyNodeInfo(data, require_vg_info=True): |
... | ... | |
624 | 654 |
doesn't have any values |
625 | 655 |
|
626 | 656 |
""" |
627 |
(bootid, vgs_info, (hv_info, )) = data
|
|
657 |
(bootid, space_info, (hv_info, )) = data
|
|
628 | 658 |
|
629 | 659 |
ret = utils.JoinDisjointDicts(hv_info, {"bootid": bootid}) |
630 | 660 |
|
631 |
if require_vg_info or vgs_info: |
|
632 |
(vg0_info, vg0_spindles) = vgs_info |
|
633 |
ret = utils.JoinDisjointDicts(vg0_info, ret) |
|
634 |
ret["spindles_free"] = vg0_spindles["vg_free"] |
|
635 |
ret["spindles_total"] = vg0_spindles["vg_size"] |
|
661 |
_AddSpindlesToLegacyNodeInfo(ret, space_info) |
|
662 |
_AddDefaultStorageInfoToLegacyNodeInfo(ret, space_info, |
|
663 |
require_vg_info=require_vg_info) |
|
636 | 664 |
|
637 | 665 |
return ret |
638 | 666 |
|
Also available in: Unified diff