Revision 78519c10 lib/backend.py
b/lib/backend.py | ||
---|---|---|
522 | 522 |
raise errors.QuitGanetiException(True, "Shutdown scheduled") |
523 | 523 |
|
524 | 524 |
|
525 |
def GetNodeInfo(vgname, hypervisor_type): |
|
525 |
def _GetVgInfo(name): |
|
526 |
"""Retrieves information about a LVM volume group. |
|
527 |
|
|
528 |
""" |
|
529 |
# TODO: GetVGInfo supports returning information for multiple VGs at once |
|
530 |
vginfo = bdev.LogicalVolume.GetVGInfo([name]) |
|
531 |
if vginfo: |
|
532 |
vg_free = int(round(vginfo[0][0], 0)) |
|
533 |
vg_size = int(round(vginfo[0][1], 0)) |
|
534 |
else: |
|
535 |
vg_free = None |
|
536 |
vg_size = None |
|
537 |
|
|
538 |
return { |
|
539 |
"name": name, |
|
540 |
"free": vg_free, |
|
541 |
"size": vg_size, |
|
542 |
} |
|
543 |
|
|
544 |
|
|
545 |
def _GetHvInfo(name): |
|
546 |
"""Retrieves node information from a hypervisor. |
|
547 |
|
|
548 |
The information returned depends on the hypervisor. Common items: |
|
549 |
|
|
550 |
- vg_size is the size of the configured volume group in MiB |
|
551 |
- vg_free is the free size of the volume group in MiB |
|
552 |
- memory_dom0 is the memory allocated for domain0 in MiB |
|
553 |
- memory_free is the currently available (free) ram in MiB |
|
554 |
- memory_total is the total number of ram in MiB |
|
555 |
- hv_version: the hypervisor version, if available |
|
556 |
|
|
557 |
""" |
|
558 |
return hypervisor.GetHypervisor(name).GetNodeInfo() |
|
559 |
|
|
560 |
|
|
561 |
def _GetNamedNodeInfo(names, fn): |
|
562 |
"""Calls C{fn} for all names in C{names} and returns a dictionary. |
|
563 |
|
|
564 |
@rtype: None or dict |
|
565 |
|
|
566 |
""" |
|
567 |
if names is None: |
|
568 |
return None |
|
569 |
else: |
|
570 |
return dict((name, fn(name)) for name in names) |
|
571 |
|
|
572 |
|
|
573 |
def GetNodeInfo(vg_names, hv_names): |
|
526 | 574 |
"""Gives back a hash with different information about the node. |
527 | 575 |
|
528 |
@type vgname: C{string} |
|
529 |
@param vgname: the name of the volume group to ask for disk space information |
|
530 |
@type hypervisor_type: C{str} |
|
531 |
@param hypervisor_type: the name of the hypervisor to ask for |
|
532 |
memory information |
|
533 |
@rtype: C{dict} |
|
534 |
@return: dictionary with the following keys: |
|
535 |
- vg_size is the size of the configured volume group in MiB |
|
536 |
- vg_free is the free size of the volume group in MiB |
|
537 |
- memory_dom0 is the memory allocated for domain0 in MiB |
|
538 |
- memory_free is the currently available (free) ram in MiB |
|
539 |
- memory_total is the total number of ram in MiB |
|
540 |
- hv_version: the hypervisor version, if available |
|
541 |
|
|
542 |
""" |
|
543 |
outputarray = {} |
|
544 |
|
|
545 |
if vgname is not None: |
|
546 |
vginfo = bdev.LogicalVolume.GetVGInfo([vgname]) |
|
547 |
vg_free = vg_size = None |
|
548 |
if vginfo: |
|
549 |
vg_free = int(round(vginfo[0][0], 0)) |
|
550 |
vg_size = int(round(vginfo[0][1], 0)) |
|
551 |
outputarray["vg_size"] = vg_size |
|
552 |
outputarray["vg_free"] = vg_free |
|
553 |
|
|
554 |
if hypervisor_type is not None: |
|
555 |
hyper = hypervisor.GetHypervisor(hypervisor_type) |
|
556 |
hyp_info = hyper.GetNodeInfo() |
|
557 |
if hyp_info is not None: |
|
558 |
outputarray.update(hyp_info) |
|
559 |
|
|
560 |
outputarray["bootid"] = utils.ReadFile(_BOOT_ID_PATH, size=128).rstrip("\n") |
|
561 |
|
|
562 |
return outputarray |
|
576 |
@type vg_names: list of string |
|
577 |
@param vg_names: Names of the volume groups to ask for disk space information |
|
578 |
@type hv_names: list of string |
|
579 |
@param hv_names: Names of the hypervisors to ask for node information |
|
580 |
@rtype: tuple; (string, None/dict, None/dict) |
|
581 |
@return: Tuple containing boot ID, volume group information and hypervisor |
|
582 |
information |
|
583 |
|
|
584 |
""" |
|
585 |
bootid = utils.ReadFile(_BOOT_ID_PATH, size=128).rstrip("\n") |
|
586 |
vg_info = _GetNamedNodeInfo(vg_names, _GetVgInfo) |
|
587 |
hv_info = _GetNamedNodeInfo(hv_names, _GetHvInfo) |
|
588 |
|
|
589 |
return (bootid, vg_info, hv_info) |
|
563 | 590 |
|
564 | 591 |
|
565 | 592 |
def VerifyNode(what, cluster_name): |
Also available in: Unified diff