- Timestamp:
- Aug 2, 2008, 8:28:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-create
r665 r816 1 1 #!/usr/bin/python 2 2 3 """ 3 4 Picks a host to "create" (boot) a VM on, and does so. … … 8 9 """ 9 10 10 11 from invirt.remote import bcast 11 12 from subprocess import PIPE, Popen, call 12 13 import sys 13 14 import yaml 14 15 15 16 16 def choose_host(): 17 17 # Query each of the hosts. 18 # TODO get `servers` from a real list of all the VM hosts (instead of19 # hardcoding the list here)20 servers = ['black-mesa.mit.edu', 'sx-blade-2.mit.edu']21 pipes = [(server,22 Popen(['remctl', server, 'remote', 'web', 'info'], stdout=PIPE))23 for server in servers]24 outputs = [(s, p.communicate()[0]) for (s, p) in pipes]25 for (s, p) in pipes:26 if p.returncode != 0:27 raise RuntimeError("remctl to host %s returned non-zero exit status %d"28 % (s, p.returncode))29 results = [(s, yaml.load(o, yaml.CSafeLoader)) for (s, o) in outputs]30 18 # XXX will the output of 'xm info' always be parseable YAML? 31 32 return max( (int(o['free_memory']), s) for (s, o) in results )[1] 33 19 results = bcast('info') 20 return max((int(o['free_memory']), s) for (s, o) in results)[1] 34 21 35 22 def main(argv): 36 23 if len(argv) < 2: 37 print >> sys.stderr, "usage: sipb-xen-remote-create <machine> [<other args...>]"24 print >> sys.stderr, "usage: sipb-xen-remote-create <machine> [<other args...>]" 38 25 return 2 39 26 machine_name = argv[1] 40 27 args = argv[2:] 41 42 28 43 29 p = Popen(['/usr/sbin/sipb-xen-remote-proxy-web', 'listvms'], stdout=PIPE) … … 50 36 if machine_name in vms: 51 37 host = vms[machine_name]['host'] 52 print >> sys.stderr, ("machine '%s' is already running on host %s"53 % (machine_name, host))38 print >> sys.stderr, ("machine '%s' is already running on host %s" 39 % (machine_name, host)) 54 40 return 1 55 56 41 57 42 host = choose_host()
Note: See TracChangeset
for help on using the changeset viewer.