Changeset 2449 for package_branches
- Timestamp:
- Aug 21, 2009, 12:13:42 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
package_branches/invirt-web/cherrypy/code/main.py
r2440 r2449 1 1 #!/usr/bin/python 2 2 """Main CGI script for web interface""" 3 4 from __future__ import with_statement 3 5 4 6 import base64 … … 11 13 import simplejson 12 14 import sys 15 import threading 13 16 import time 14 17 import urllib … … 16 19 import cherrypy 17 20 from StringIO import StringIO 21 18 22 def revertStandardError(): 19 23 """Move stderr to stdout, and return the contents of the old stderr.""" … … 282 286 atmulti = ajaxterm.Multiplex() 283 287 atsessions = {} 288 atsessions_lock = threading.Lock() 284 289 285 290 @cherrypy.expose … … 301 306 def at(self, machine_id, k=None, c=0, force=0): 302 307 machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine 303 if machine_id in self.atsessions: 304 term = self.atsessions[machine_id] 305 else: 306 print >>sys.stderr, "spawning new session for terminal to ",machine_id 307 term = self.atsessions[machine_id] = self.atmulti.create( 308 ["ssh", "-e","none", "-l", machine.name, config.console.hostname] 309 ) 310 if k: 311 self.atmulti.proc_write(term,k) 312 time.sleep(0.002) 313 dump=self.atmulti.dump(term,c,int(force)) 314 cherrypy.response.headers['Content-Type']='text/xml' 315 if isinstance(dump,str): 316 return dump 317 else: 318 print "Removing session for", machine_id 319 del self.atsessions[machine_id] 320 return '<?xml version="1.0"?><idem></idem>' 308 with self.atsessions_lock: 309 if machine_id in self.atsessions: 310 term = self.atsessions[machine_id] 311 else: 312 print >>sys.stderr, "spawning new session for terminal to ",machine_id 313 term = self.atsessions[machine_id] = self.atmulti.create( 314 ["ssh", "-e","none", "-l", machine.name, config.console.hostname] 315 ) 316 if k: 317 self.atmulti.proc_write(term,k) 318 time.sleep(0.002) 319 dump=self.atmulti.dump(term,c,int(force)) 320 cherrypy.response.headers['Content-Type']='text/xml' 321 if isinstance(dump,str): 322 return dump 323 else: 324 print "Removing session for", machine_id 325 del self.atsessions[machine_id] 326 return '<?xml version="1.0"?><idem></idem>' 321 327 322 328 machine = MachineView()
Note: See TracChangeset
for help on using the changeset viewer.