Changeset 816 for trunk/packages


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
Location:
trunk/packages
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-base/files/usr/sbin/invirt-getconf

    r802 r816  
    1717"""
    1818
    19 from invirt.config import load
     19from invirt.config import default_src_path, default_cache_path, load
    2020from sys import argv, exit, stderr, stdout
    2121from optparse import OptionParser
     
    2828                description = __doc__.strip().split('\n\n')[0])
    2929        parser.add_option('-s', '--src',
    30                 default = '/etc/invirt/master.yaml',
     30                default = default_src_path,
    3131                help = 'the source YAML configuration file to read from')
    3232        parser.add_option('-c', '--cache',
    33                 default = '/var/lib/invirt/invirt.json',
     33                default = default_cache_path,
    3434                help = 'path to the JSON cache')
    3535        parser.add_option('-r', '--refresh',
     
    8181            else:
    8282                import yaml
     83                try:    dumper = yaml.CSafeDumper
     84                except: dumper = yaml.SafeDumper
    8385                yaml.dump(conf, stdout,
    84                           Dumper=yaml.CSafeDumper, default_flow_style=False)
     86                          Dumper = dumper, default_flow_style = False)
    8587    except invirt_exception, ex:
    8688        print >> stderr, ex
  • trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/config.py

    r807 r816  
    11import json
    22from invirt.common import *
     3from os import rename
    34from os.path import getmtime
    45
     
    7576                        lambda f: f.write(json.write(ns.cfg)))
    7677                except: pass # silent failure
    77                 else: os.rename(cache_path + '.tmp', cache_path)
     78                else: rename(cache_path + '.tmp', cache_path)
    7879        except IOError:
    7980            ns.cfg = with_closing(file(src_path)) (
  • trunk/packages/sipb-xen-remote-server/config.todo

    r810 r816  
    22files/usr/sbin/sipb-xen-remconffs: db uri
    33files/usr/sbin/sipb-xen-remote-proxy: any one host name
    4 files/usr/sbin/sipb-xen-remote-create: host hostnames
    5 files/usr/sbin/sipb-xen-remote-listvms: host hostnames
    64files/usr/sbin/sipb-xen-remctl-help: remote-proxy hostname
  • 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()
  • trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-listvms

    r623 r816  
    66"""
    77
    8 from subprocess import PIPE, Popen
     8from invirt.remote import bcast
    99import sys
    1010import yaml
    1111
    1212def 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'))
    2815
    2916    # Merge the results and print.
     
    3724
    3825if __name__ == '__main__':
    39     main(sys.argv)
     26    sys.exit(main(sys.argv))
    4027
    4128# vim:et:sw=4:ts=4
Note: See TracChangeset for help on using the changeset viewer.