Ignore:
Timestamp:
Aug 2, 2008, 8:28:18 PM (16 years ago)
Author:
y_z
Message:
  • use invirt.config to get hostnames
  • refactoring: extracted bcast() function into invirt.remote package
  • fixed os.rename import bug
  • using correct default paths in invirt-getconf
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-create

    r665 r816  
    11#!/usr/bin/python
     2
    23"""
    34Picks a host to "create" (boot) a VM on, and does so.
     
    89"""
    910
    10 
     11from invirt.remote import bcast
    1112from subprocess import PIPE, Popen, call
    1213import sys
    1314import yaml
    1415
    15 
    1616def choose_host():
    1717    # Query each of the hosts.
    18     # TODO get `servers` from a real list of all the VM hosts (instead of
    19     # 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]
    3018    # 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]
    3421
    3522def main(argv):
    3623    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...>]"
    3825        return 2
    3926    machine_name = argv[1]
    4027    args = argv[2:]
    41 
    4228
    4329    p = Popen(['/usr/sbin/sipb-xen-remote-proxy-web', 'listvms'], stdout=PIPE)
     
    5036    if machine_name in vms:
    5137        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))
    5440        return 1
    55 
    5641
    5742    host = choose_host()
Note: See TracChangeset for help on using the changeset viewer.