Added remote web availability remctl and script to calculate memory available to...
authorPeter Iannucci <iannucci@mit.edu>
Fri, 13 Feb 2009 03:42:32 +0000 (22:42 -0500)
committerPeter Iannucci <iannucci@mit.edu>
Fri, 13 Feb 2009 03:42:32 +0000 (22:42 -0500)
svn path=/trunk/packages/invirt-remote/; revision=2104

host/usr/sbin/invirt-availability [new file with mode: 0644]
host/usr/sbin/invirt-remote

diff --git a/host/usr/sbin/invirt-availability b/host/usr/sbin/invirt-availability
new file mode 100644 (file)
index 0000000..2afd5ea
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+"""
+Gathers availability data for the VM host it's running on.
+"""
+
+from subprocess import PIPE, Popen, call
+import sys
+import yaml
+
+# return the amount of memory in kilobytes represented by s
+def parseUnits(s):
+    num, unit = s.split(' ')
+    return int(num) * {'kb':1, 'mb':1024}[unit.lower()]
+
+def main(argv):
+    p = Popen(['/usr/sbin/xm', 'info'], stdout=PIPE)
+    output = p.communicate()[0]
+    if p.returncode != 0:
+        raise RuntimeError("Command '%s' returned non-zero exit status %d"
+                           % ('invirt-availability', p.returncode)) 
+    xminfo = yaml.load(output, yaml.CSafeLoader)
+
+    # In kilobytes
+    free_memory = int(xminfo['free_memory']) * 1024
+
+    f = open('/proc/xen/balloon', 'r')
+    ballooninfo = yaml.load(f.read())
+    f.close()
+    currentallocation = parseUnits(ballooninfo['Current allocation'])
+    minimumtarget = parseUnits(ballooninfo['Minimum target'])
+
+    p = Popen(['/usr/sbin/xm', 'info', '-c'], stdout=PIPE)
+    output = p.communicate()[0]
+    if p.returncode != 0:
+        raise RuntimeError("Command '%s' returned non-zero exit status %d"
+                           % ('invirt-availability', p.returncode)) 
+    xminfoc = yaml.load(output, yaml.CSafeLoader)
+
+    # In kilobytes
+    dom0minmem = int(xminfoc['dom0-min-mem']) * 1024
+
+    dom0_spare_memory = currentallocation - max(minimumtarget, dom0minmem)
+    print int((free_memory + dom0_spare_memory)/1024)
+    return 0
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
index 8511f60..948d0f0 100755 (executable)
@@ -20,9 +20,12 @@ case "$TYPE" in
             listvms)
                 COMMAND=/usr/sbin/invirt-listvms
                ;;
-           info)
-               COMMAND=/usr/sbin/xm
-               ;;
+               info)
+                COMMAND=/usr/sbin/xm
+            ;;
+            availability)
+                COMMAND=/usr/sbin/invirt-availability
+            ;;
             vnccert)
                 COMMAND=/usr/bin/invirt-vnc-getcert
                 ;;