Ignore:
Timestamp:
Jun 1, 2008, 5:33:57 PM (16 years ago)
Author:
y_z
Message:

before migrating to yaml; things seem to be working, --pickle supported

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-listvms

    r538 r549  
    88from itertools import chain
    99from subprocess import CalledProcessError, PIPE, Popen
    10 from sys import argv
     10from sys import argv, stdout
     11from cPickle import dump, loads
    1112
    1213###
    1314
    14 import compiler
    15 
    16 class Unsafe_Source_Error(Exception):
    17     def __init__(self,error,descr = None,node = None):
    18         self.error = error
    19         self.descr = descr
    20         self.node = node
    21         self.lineno = getattr(node,"lineno",None)
    22        
    23     def __repr__(self):
    24         return "Line %d.  %s: %s" % (self.lineno, self.error, self.descr)
    25     __str__ = __repr__   
    26            
    27 class SafeEval(object):
    28    
    29     def visit(self, node,**kw):
    30         cls = node.__class__
    31         meth = getattr(self,'visit'+cls.__name__,self.default)
    32         return meth(node, **kw)
    33            
    34     def default(self, node, **kw):
    35         for child in node.getChildNodes():
    36             return self.visit(child, **kw)
    37            
    38     visitExpression = default
    39    
    40     def visitConst(self, node, **kw):
    41         return node.value
    42 
    43     def visitDict(self,node,**kw):
    44         return dict([(self.visit(k),self.visit(v)) for k,v in node.items])
    45        
    46     def visitTuple(self,node, **kw):
    47         return tuple(self.visit(i) for i in node.nodes)
    48        
    49     def visitList(self,node, **kw):
    50         return [self.visit(i) for i in node.nodes]
    51 
    52 class SafeEvalWithErrors(SafeEval):
    53 
    54     def default(self, node, **kw):
    55         raise Unsafe_Source_Error("Unsupported source construct",
    56                                 node.__class__,node)
    57            
    58     def visitName(self,node, **kw):
    59         if node.name == 'None': return None
    60         raise Unsafe_Source_Error("Strings must be quoted",
    61                                  node.name, node)
    62                                  
    63     # Add more specific errors if desired
    64            
    65 def safe_eval(source, fail_on_error = True):
    66     if source.strip() == '': return None
    67     walker = fail_on_error and SafeEvalWithErrors() or SafeEval()
    68     try:
    69         ast = compiler.parse(source,"eval")
    70     except SyntaxError, err:
    71         raise
    72     try:
    73         return walker.visit(ast)
    74     except Unsafe_Source_Error, err:
    75         raise
     15#import compiler
     16#
     17#class Unsafe_Source_Error(Exception):
     18#    def __init__(self,error,descr = None,node = None):
     19#        self.error = error
     20#        self.descr = descr
     21#        self.node = node
     22#        self.lineno = getattr(node,"lineno",None)
     23#       
     24#    def __repr__(self):
     25#        return "Line %d.  %s: %s" % (self.lineno, self.error, self.descr)
     26#    __str__ = __repr__   
     27#           
     28#class SafeEval(object):
     29#   
     30#    def visit(self, node,**kw):
     31#        cls = node.__class__
     32#        meth = getattr(self,'visit'+cls.__name__,self.default)
     33#        return meth(node, **kw)
     34#           
     35#    def default(self, node, **kw):
     36#        for child in node.getChildNodes():
     37#            return self.visit(child, **kw)
     38#           
     39#    visitExpression = default
     40#   
     41#    def visitConst(self, node, **kw):
     42#        return node.value
     43#
     44#    def visitDict(self,node,**kw):
     45#        return dict([(self.visit(k),self.visit(v)) for k,v in node.items])
     46#       
     47#    def visitTuple(self,node, **kw):
     48#        return tuple(self.visit(i) for i in node.nodes)
     49#       
     50#    def visitList(self,node, **kw):
     51#        return [self.visit(i) for i in node.nodes]
     52#
     53#class SafeEvalWithErrors(SafeEval):
     54#
     55#    def default(self, node, **kw):
     56#        raise Unsafe_Source_Error("Unsupported source construct",
     57#                                node.__class__,node)
     58#           
     59#    def visitName(self,node, **kw):
     60#        if node.name == 'None': return None
     61#        raise Unsafe_Source_Error("Strings must be quoted",
     62#                                 node.name, node)
     63#                                 
     64#    # Add more specific errors if desired
     65#           
     66#def safe_eval(source, fail_on_error = True):
     67#    if source.strip() == '': return None
     68#    walker = fail_on_error and SafeEvalWithErrors() or SafeEval()
     69#    try:
     70#        ast = compiler.parse(source,"eval")
     71#    except SyntaxError, err:
     72#        raise
     73#    try:
     74#        return walker.visit(ast)
     75#    except Unsafe_Source_Error, err:
     76#        raise
    7677
    7778###
     
    9596  servers = [ 'black-mesa.mit.edu', 'sx-blade-2.mit.edu' ]
    9697  # XXX
    97   results = [ safe_eval(run(['remctl', server, 'remote', 'web', 'listvms'] + argv[1:]))
     98  results = [ loads(run(['remctl', server, 'remote', 'web', 'listvms', '--pickle']))
    9899              for server in servers ]
    99100  results = filter( lambda x: x is not None, results )
     
    102103  merged = {}
    103104  for result in results: merged.update(result)
    104   print merged
    105   print '.'
     105  if argv[1:] == ['--pickle']:
     106    dump(merged, stdout)
     107  else:
     108    print merged
     109    print '.'
    106110
    107111if __name__ == '__main__':
  • trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-proxy

    r502 r549  
    11#!/bin/sh
    22# invoke as sipb-xen-remote-proxy-$TYPE, with "TYPE" in the remctl sense.
    3 kinit -k host/sipb-vm-58.mit.edu
     3klist -s || kinit -k host/remote.mit.edu
    44#echo remctl black-mesa remote ${0##*-} "$@"
    5 remctl black-mesa remote ${0##*-} "$@"
     5if false ; then
     6  remctl black-mesa remote ${0##*-} "$@"
     7else
     8  case "$1" in
     9    listvms ) shift; sipb-xen-remote-listvms "$@" ;;
     10    *       ) remctl black-mesa remote ${0##*-} "$@" ;;
     11  esac
     12fi
Note: See TracChangeset for help on using the changeset viewer.