Changeset 816 for trunk/packages/sipb-xen-remote-server/files/usr/sbin
- Timestamp:
- Aug 2, 2008, 8:28:18 PM (16 years ago)
- Location:
- trunk/packages/sipb-xen-remote-server/files/usr/sbin
- Files:
-
- 2 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() -
trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-listvms
r623 r816 6 6 """ 7 7 8 from subprocess import PIPE, Popen8 from invirt.remote import bcast 9 9 import sys 10 10 import yaml 11 11 12 12 def main(argv): 13 # Query each of the server for their VMs. 14 # TODO get `servers` from a real list of all the VM hosts (instead of 15 # hardcoding the list here) 16 servers = ['black-mesa.mit.edu', 'sx-blade-2.mit.edu'] 17 # XXX 18 pipes = [(server, 19 Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE)) 20 for server in servers] 21 outputs = [(s, p.communicate()[0]) for (s, p) in pipes] 22 for (s, p) in pipes: 23 if p.returncode != 0: 24 raise RuntimeError("remctl to host %s returned non-zero exit status %d" 25 % (s, p.returncode)) 26 results = [(s, yaml.load(o, yaml.CSafeLoader)) for (s, o) in outputs] 27 results = filter(lambda (_, x): x is not None, results) 13 # Query each of the hosts. 14 results = filter(lambda (_, x): x is not None, bcast('listvms')) 28 15 29 16 # Merge the results and print. … … 37 24 38 25 if __name__ == '__main__': 39 main(sys.argv)26 sys.exit(main(sys.argv)) 40 27 41 28 # vim:et:sw=4:ts=4
Note: See TracChangeset
for help on using the changeset viewer.