projects
/
invirt/packages/invirt-remote.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Clean-up suggestions from price. Whitespace fixes.
[invirt/packages/invirt-remote.git]
/
host
/
usr
/
sbin
/
invirt-availability
diff --git
a/host/usr/sbin/invirt-availability
b/host/usr/sbin/invirt-availability
index
2afd5ea
..
93ef381
100644
(file)
--- a/
host/usr/sbin/invirt-availability
+++ b/
host/usr/sbin/invirt-availability
@@
-13,19
+13,23
@@
def parseUnits(s):
return int(num) * {'kb':1, 'mb':1024}[unit.lower()]
def main(argv):
return int(num) * {'kb':1, 'mb':1024}[unit.lower()]
def main(argv):
+ """
+ Calculate the amount of memory available for new VMs
+ The numbers returned by xm info and xm info -c are in MB
+ The numbers in /proc/xen/balloon have nice units
+ All math is done in kilobytes for consistency
+ Output is in MB
+ """
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"
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))
+ % ('/usr/sbin/xm info', p.returncode))
xminfo = yaml.load(output, yaml.CSafeLoader)
xminfo = yaml.load(output, yaml.CSafeLoader)
- # In kilobytes
free_memory = int(xminfo['free_memory']) * 1024
free_memory = int(xminfo['free_memory']) * 1024
- f = open('/proc/xen/balloon', 'r')
- ballooninfo = yaml.load(f.read())
- f.close()
+ ballooninfo = yaml.load(open('/proc/xen/balloon', 'r').read())
currentallocation = parseUnits(ballooninfo['Current allocation'])
minimumtarget = parseUnits(ballooninfo['Minimum target'])
currentallocation = parseUnits(ballooninfo['Current allocation'])
minimumtarget = parseUnits(ballooninfo['Minimum target'])
@@
-33,7
+37,7
@@
def main(argv):
output = p.communicate()[0]
if p.returncode != 0:
raise RuntimeError("Command '%s' returned non-zero exit status %d"
output = p.communicate()[0]
if p.returncode != 0:
raise RuntimeError("Command '%s' returned non-zero exit status %d"
- % ('invirt-availability', p.returncode))
+ % ('/usr/sbin/xm info -c', p.returncode))
xminfoc = yaml.load(output, yaml.CSafeLoader)
# In kilobytes
xminfoc = yaml.load(output, yaml.CSafeLoader)
# In kilobytes