3 Gathers availability data for the VM host it's running on.
6 from subprocess import PIPE, Popen, call
10 # return the amount of memory in kilobytes represented by s
12 num, unit = s.split(' ')
13 return int(num) * {'kb':1, 'mb':1024}[unit.lower()]
16 p = Popen(['/usr/sbin/xm', 'info'], stdout=PIPE)
17 output = p.communicate()[0]
19 raise RuntimeError("Command '%s' returned non-zero exit status %d"
20 % ('invirt-availability', p.returncode))
21 xminfo = yaml.load(output, yaml.CSafeLoader)
24 free_memory = int(xminfo['free_memory']) * 1024
26 f = open('/proc/xen/balloon', 'r')
27 ballooninfo = yaml.load(f.read())
29 currentallocation = parseUnits(ballooninfo['Current allocation'])
30 minimumtarget = parseUnits(ballooninfo['Minimum target'])
32 p = Popen(['/usr/sbin/xm', 'info', '-c'], stdout=PIPE)
33 output = p.communicate()[0]
35 raise RuntimeError("Command '%s' returned non-zero exit status %d"
36 % ('invirt-availability', p.returncode))
37 xminfoc = yaml.load(output, yaml.CSafeLoader)
40 dom0minmem = int(xminfoc['dom0-min-mem']) * 1024
42 dom0_spare_memory = currentallocation - max(minimumtarget, dom0minmem)
43 print int((free_memory + dom0_spare_memory)/1024)
46 if __name__ == '__main__':
47 sys.exit(main(sys.argv))