Changeset 552 for trunk/packages/sipb-xen-remote-server/files
- Timestamp:
- Jun 1, 2008, 6:57:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-listvms
r549 r552 9 9 from subprocess import CalledProcessError, PIPE, Popen 10 10 from sys import argv, stdout 11 from cPickle import dump, loads 12 13 ### 14 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 11 from yaml import safe_dump, safe_load 77 12 78 13 ### … … 91 26 def main(argv): 92 27 # Query each of the server for their VMs. 93 # run('kinit -k host/sipb-vm-58.mit.edu'.split())94 28 # TODO get `servers` from a real list of all the VM hosts (instead of 95 29 # hardcoding the list here) 96 30 servers = [ 'black-mesa.mit.edu', 'sx-blade-2.mit.edu' ] 97 31 # XXX 98 results = [ loads(run(['remctl', server, 'remote', 'web', 'listvms', '--pickle']))32 results = [ safe_load(run(['remctl', server, 'remote', 'web', 'listvms'])) 99 33 for server in servers ] 100 34 results = filter( lambda x: x is not None, results ) … … 103 37 merged = {} 104 38 for result in results: merged.update(result) 105 if argv[1:] == ['--pickle']: 106 dump(merged, stdout) 107 else: 108 print merged 109 print '.' 39 print safe_dump(merged, default_flow_style=False) 110 40 111 41 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.