From: Quentin Smith Date: Sun, 9 Aug 2009 23:16:25 +0000 (-0400) Subject: Port vnc page to Mako and CherryPy X-Git-Tag: 0.1.0^2~55 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/commitdiff_plain/a6b3091d1a405ce7ece30be84596cd37afce4911 Port vnc page to Mako and CherryPy svn path=/package_branches/invirt-web/cherrypy-rebased/; revision=2680 --- diff --git a/code/main.py b/code/main.py index 222520c..d938450 100755 --- a/code/main.py +++ b/code/main.py @@ -173,6 +173,48 @@ console will suffer artifacts. return d index = info + @cherrypy.expose + @cherrypy.tools.mako(filename="/vnc.mako") + def vnc(self, machine_id): + """VNC applet page. + + Note that due to same-domain restrictions, the applet connects to + the webserver, which needs to forward those requests to the xen + server. The Xen server runs another proxy that (1) authenticates + and (2) finds the correct port for the VM. + + You might want iptables like: + + -t nat -A PREROUTING -s ! 18.181.0.60 -i eth1 -p tcp -m tcp \ + --dport 10003 -j DNAT --to-destination 18.181.0.60:10003 + -t nat -A POSTROUTING -d 18.181.0.60 -o eth1 -p tcp -m tcp \ + --dport 10003 -j SNAT --to-source 18.187.7.142 + -A FORWARD -d 18.181.0.60 -i eth1 -o eth1 -p tcp -m tcp \ + --dport 10003 -j ACCEPT + + Remember to enable iptables! + echo 1 > /proc/sys/net/ipv4/ip_forward + """ + machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine + + token = controls.vnctoken(machine) + host = controls.listHost(machine) + if host: + port = 10003 + [h.hostname for h in config.hosts].index(host) + else: + port = 5900 # dummy + + status = controls.statusInfo(machine) + has_vnc = hasVnc(status) + + d = dict(on=status, + has_vnc=has_vnc, + machine=machine, + hostname=cherrypy.request.local.name, + port=port, + authtoken=token) + return d + machine = MachineView() def pathSplit(path): @@ -336,47 +378,6 @@ def getListDict(username, state): can_clone=can_clone) return d -def vnc(username, state, path, fields): - """VNC applet page. - - Note that due to same-domain restrictions, the applet connects to - the webserver, which needs to forward those requests to the xen - server. The Xen server runs another proxy that (1) authenticates - and (2) finds the correct port for the VM. - - You might want iptables like: - - -t nat -A PREROUTING -s ! 18.181.0.60 -i eth1 -p tcp -m tcp \ - --dport 10003 -j DNAT --to-destination 18.181.0.60:10003 - -t nat -A POSTROUTING -d 18.181.0.60 -o eth1 -p tcp -m tcp \ - --dport 10003 -j SNAT --to-source 18.187.7.142 - -A FORWARD -d 18.181.0.60 -i eth1 -o eth1 -p tcp -m tcp \ - --dport 10003 -j ACCEPT - - Remember to enable iptables! - echo 1 > /proc/sys/net/ipv4/ip_forward - """ - machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine - - token = controls.vnctoken(machine) - host = controls.listHost(machine) - if host: - port = 10003 + [h.hostname for h in config.hosts].index(host) - else: - port = 5900 # dummy - - status = controls.statusInfo(machine) - has_vnc = hasVnc(status) - - d = dict(user=username, - on=status, - has_vnc=has_vnc, - machine=machine, - hostname=state.environ.get('SERVER_NAME', 'localhost'), - port=port, - authtoken=token) - return templates.vnc(searchList=[d]) - def getHostname(nic): """Find the hostname associated with a NIC. @@ -649,7 +650,7 @@ def throwError(_, __, ___, ____): """Throw an error, to test the error-tracing mechanisms.""" raise RuntimeError("test of the emergency broadcast system") -mapping = dict(vnc=vnc, +mapping = dict( command=command, modify=modify, create=create, diff --git a/code/templates/vnc.mako b/code/templates/vnc.mako new file mode 100644 index 0000000..c211a32 --- /dev/null +++ b/code/templates/vnc.mako @@ -0,0 +1,24 @@ +<%page expression_filter="h" /> +<%inherit file="skeleton.mako" /> + +<%def name="title()"> +Console to ${machine.name} + + + +% if not on: +

Your machine appears to be off.

+% elif not has_vnc: +

Your machine appears to not be accepting VNC connections. Perhaps you have a ParaVM machine?

+% endif + +

See tips about framebuffer and other issues.

+ + + + + + + + diff --git a/code/templates/vnc.tmpl b/code/templates/vnc.tmpl deleted file mode 100644 index c61b4f6..0000000 --- a/code/templates/vnc.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -#from skeleton import skeleton -#extends skeleton - -#def title -Console to $machine.name -#end def - -#def body - -#if not $on -

Your machine appears to be off.

-#else if not $has_vnc -

Your machine appears to not be accepting VNC connections. Perhaps you have a ParaVM machine?

-#end if -

See tips about framebuffer and other issues.

- - - - - - - - -#end def