From: Peter Iannucci Date: Fri, 13 Feb 2009 03:42:32 +0000 (-0500) Subject: Added remote web availability remctl and script to calculate memory available to... X-Git-Tag: 0.3.3~3 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/commitdiff_plain/b28ef7ddcb14f44c694a55dc547571ff30c3c5cc Added remote web availability remctl and script to calculate memory available to new VMs svn path=/trunk/packages/invirt-remote/; revision=2104 --- diff --git a/host/usr/sbin/invirt-availability b/host/usr/sbin/invirt-availability new file mode 100644 index 0000000..2afd5ea --- /dev/null +++ b/host/usr/sbin/invirt-availability @@ -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)) diff --git a/host/usr/sbin/invirt-remote b/host/usr/sbin/invirt-remote index 8511f60..948d0f0 100755 --- a/host/usr/sbin/invirt-remote +++ b/host/usr/sbin/invirt-remote @@ -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 ;;