Skip to content

Instantly share code, notes, and snippets.

@kisielk
Created June 8, 2011 20:34
Show Gist options
  • Select an option

  • Save kisielk/1015336 to your computer and use it in GitHub Desktop.

Select an option

Save kisielk/1015336 to your computer and use it in GitHub Desktop.
Sets the h_vmem complex value on hosts in gridengine based on mem_free
#!/usr/bin/env python
"""Script to set node h_vmem resource to be equal to the node's actual physical
memory.
Usage:
qhost -xml | ./node_hvmem.py
"""
import sys
import shlex
from xml.etree import ElementTree
from subprocess import Popen
def main(argv):
tree = ElementTree.parse(sys.stdin)
for host in tree.findall('host'):
for hostvalue in host.findall('.//hostvalue'):
if hostvalue.get('name') == 'mem_total':
mem = hostvalue.text
if mem != '-':
name = host.get('name').split('.')[0]
cmd = "qconf -mattr exechost complex_values h_vmem={0} {1}".format(mem, name)
print "Setting h_vmem for {0} to {1}".format(name, mem)
Popen(shlex.split(cmd))
if __name__ == "__main__":
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment