Revision 572e52bf lib/hypervisor/hv_kvm.py
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
618 | 618 |
def GetNodeInfo(self): |
619 | 619 |
"""Return information about the node. |
620 | 620 |
|
621 |
This is just a wrapper over the base GetLinuxNodeInfo method. |
|
622 |
|
|
621 | 623 |
@return: a dict with the following keys (values in MiB): |
622 | 624 |
- memory_total: the total memory size on the node |
623 | 625 |
- memory_free: the available memory on the node for instances |
624 | 626 |
- memory_dom0: the memory used by the node itself, if available |
625 | 627 |
|
626 | 628 |
""" |
627 |
# global ram usage from the xm info command |
|
628 |
# memory : 3583 |
|
629 |
# free_memory : 747 |
|
630 |
# note: in xen 3, memory has changed to total_memory |
|
631 |
try: |
|
632 |
fh = file("/proc/meminfo") |
|
633 |
try: |
|
634 |
data = fh.readlines() |
|
635 |
finally: |
|
636 |
fh.close() |
|
637 |
except EnvironmentError, err: |
|
638 |
raise errors.HypervisorError("Failed to list node info: %s" % err) |
|
639 |
|
|
640 |
result = {} |
|
641 |
sum_free = 0 |
|
642 |
for line in data: |
|
643 |
splitfields = line.split(":", 1) |
|
644 |
|
|
645 |
if len(splitfields) > 1: |
|
646 |
key = splitfields[0].strip() |
|
647 |
val = splitfields[1].strip() |
|
648 |
if key == 'MemTotal': |
|
649 |
result['memory_total'] = int(val.split()[0])/1024 |
|
650 |
elif key in ('MemFree', 'Buffers', 'Cached'): |
|
651 |
sum_free += int(val.split()[0])/1024 |
|
652 |
elif key == 'Active': |
|
653 |
result['memory_dom0'] = int(val.split()[0])/1024 |
|
654 |
result['memory_free'] = sum_free |
|
655 |
|
|
656 |
cpu_total = 0 |
|
657 |
try: |
|
658 |
fh = open("/proc/cpuinfo") |
|
659 |
try: |
|
660 |
cpu_total = len(re.findall("(?m)^processor\s*:\s*[0-9]+\s*$", |
|
661 |
fh.read())) |
|
662 |
finally: |
|
663 |
fh.close() |
|
664 |
except EnvironmentError, err: |
|
665 |
raise errors.HypervisorError("Failed to list node info: %s" % err) |
|
666 |
result['cpu_total'] = cpu_total |
|
667 |
# FIXME: export correct data here |
|
668 |
result['cpu_nodes'] = 1 |
|
669 |
result['cpu_sockets'] = 1 |
|
670 |
|
|
671 |
return result |
|
629 |
return self.GetLinuxNodeInfo() |
|
672 | 630 |
|
673 | 631 |
@classmethod |
674 | 632 |
def GetShellCommandForConsole(cls, instance, hvparams, beparams): |
Also available in: Unified diff