[Libvirt-cim] [PATCH 3 of 4] [TEST] Adding functions to live.py

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Fri Jul 11 12:21:36 UTC 2008


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1215777594 25200
# Node ID 9155858d4e5aa69393e652e7fd340ab12a63a153
# Parent  65b1865d10a0570ec785e78affc0f69877bc8189
[TEST] Adding functions to live.py.

Added the following functions:
1) virsh_nodeinfo_cpucount() to get the number of processors on the machine.
2) virsh_nodeinfo_memsize() to get the  memory capacity on the machine.
3) virsh_dominfo_usedmem() to get the memory used by the guest.

Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r 65b1865d10a0 -r 9155858d4e5a lib/VirtLib/live.py
--- a/lib/VirtLib/live.py	Fri Jul 11 04:52:56 2008 -0700
+++ b/lib/VirtLib/live.py	Fri Jul 11 04:59:54 2008 -0700
@@ -347,3 +347,56 @@
         return out
     return None
 
+def virsh_nodeinfo_cpucount(server, virt="Xen"):
+    """
+       Returns the number of processors on the machine.
+    """
+
+    cmd = "virsh -c %s nodeinfo |  awk '/CPU\(s\)/ { print \$2 }'" \
+          % (utils.virt2uri(virt))
+
+    rc, out = utils.run_remote(server, cmd)
+    if rc != 0:
+        return -1
+
+    try:
+        cpus = int(out)
+        return cpus
+    except ValueError:
+        return -1
+
+def virsh_nodeinfo_memsize(server, virt="Xen"):
+    """
+       Returns the memory capacity on the machine.
+    """
+
+    cmd = "virsh -c %s nodeinfo |  awk '/Memory size/ { print \$3 }'" \
+           % (utils.virt2uri(virt))
+
+    rc, out = utils.run_remote(server, cmd)
+    if rc != 0:
+        return -1
+
+    try:
+        msize = int(out)
+        return msize
+    except ValueError:
+        return -1
+
+def virsh_dominfo_usedmem(server, vs_name, virt="Xen"):
+    """
+       Returns the memory used by the guest.
+    """
+
+    guest_cmd = "virsh -c %s dominfo %s |  awk '/Used memory/ { print \$3 }'" \
+                % (utils.virt2uri(virt), vs_name)
+    
+    rc, out = utils.run_remote(server, guest_cmd)
+    if rc != 0:
+        return -1
+
+    try:
+        usedmem = int(out)
+        return usedmem
+    except ValueError:
+        return -1




More information about the Libvirt-cim mailing list