- Timestamp:
- Jun 1, 2008, 5:33:57 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-listvms
r538 r549 8 8 from itertools import chain 9 9 from subprocess import CalledProcessError, PIPE, Popen 10 from sys import argv 10 from sys import argv, stdout 11 from cPickle import dump, loads 11 12 12 13 ### 13 14 14 import compiler15 16 class Unsafe_Source_Error(Exception):17 def __init__(self,error,descr = None,node = None):18 self.error = error19 self.descr = descr20 self.node = node21 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 = default39 40 def visitConst(self, node, **kw):41 return node.value42 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 None60 raise Unsafe_Source_Error("Strings must be quoted",61 node.name, node)62 63 # Add more specific errors if desired64 65 def safe_eval(source, fail_on_error = True):66 if source.strip() == '': return None67 walker = fail_on_error and SafeEvalWithErrors() or SafeEval()68 try:69 ast = compiler.parse(source,"eval")70 except SyntaxError, err:71 raise72 try:73 return walker.visit(ast)74 except Unsafe_Source_Error, err:75 raise15 #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 76 77 77 78 ### … … 95 96 servers = [ 'black-mesa.mit.edu', 'sx-blade-2.mit.edu' ] 96 97 # XXX 97 results = [ safe_eval(run(['remctl', server, 'remote', 'web', 'listvms'] + argv[1:]))98 results = [ loads(run(['remctl', server, 'remote', 'web', 'listvms', '--pickle'])) 98 99 for server in servers ] 99 100 results = filter( lambda x: x is not None, results ) … … 102 103 merged = {} 103 104 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 '.' 106 110 107 111 if __name__ == '__main__': -
trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-proxy
r502 r549 1 1 #!/bin/sh 2 2 # invoke as sipb-xen-remote-proxy-$TYPE, with "TYPE" in the remctl sense. 3 k init -k host/sipb-vm-58.mit.edu3 klist -s || kinit -k host/remote.mit.edu 4 4 #echo remctl black-mesa remote ${0##*-} "$@" 5 remctl black-mesa remote ${0##*-} "$@" 5 if false ; then 6 remctl black-mesa remote ${0##*-} "$@" 7 else 8 case "$1" in 9 listvms ) shift; sipb-xen-remote-listvms "$@" ;; 10 * ) remctl black-mesa remote ${0##*-} "$@" ;; 11 esac 12 fi
Note: See TracChangeset
for help on using the changeset viewer.