Ignore:
Timestamp:
Dec 20, 2009, 9:44:57 PM (15 years ago)
Author:
broder
Message:

Port vnc page to Mako and CherryPy?

Location:
package_branches/invirt-web/cherrypy-rebased/code
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • package_branches/invirt-web/cherrypy-rebased/code/main.py

    r2679 r2680  
    173173            return d
    174174        index = info
     175
     176        @cherrypy.expose
     177        @cherrypy.tools.mako(filename="/vnc.mako")
     178        def vnc(self, machine_id):
     179            """VNC applet page.
     180
     181            Note that due to same-domain restrictions, the applet connects to
     182            the webserver, which needs to forward those requests to the xen
     183            server.  The Xen server runs another proxy that (1) authenticates
     184            and (2) finds the correct port for the VM.
     185
     186            You might want iptables like:
     187
     188            -t nat -A PREROUTING -s ! 18.181.0.60 -i eth1 -p tcp -m tcp \
     189            --dport 10003 -j DNAT --to-destination 18.181.0.60:10003
     190            -t nat -A POSTROUTING -d 18.181.0.60 -o eth1 -p tcp -m tcp \
     191            --dport 10003 -j SNAT --to-source 18.187.7.142
     192            -A FORWARD -d 18.181.0.60 -i eth1 -o eth1 -p tcp -m tcp \
     193            --dport 10003 -j ACCEPT
     194
     195            Remember to enable iptables!
     196            echo 1 > /proc/sys/net/ipv4/ip_forward
     197            """
     198            machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine
     199
     200            token = controls.vnctoken(machine)
     201            host = controls.listHost(machine)
     202            if host:
     203                port = 10003 + [h.hostname for h in config.hosts].index(host)
     204            else:
     205                port = 5900 # dummy
     206
     207            status = controls.statusInfo(machine)
     208            has_vnc = hasVnc(status)
     209
     210            d = dict(on=status,
     211                     has_vnc=has_vnc,
     212                     machine=machine,
     213                     hostname=cherrypy.request.local.name,
     214                     port=port,
     215                     authtoken=token)
     216            return d
    175217
    176218    machine = MachineView()
     
    337379    return d
    338380
    339 def vnc(username, state, path, fields):
    340     """VNC applet page.
    341 
    342     Note that due to same-domain restrictions, the applet connects to
    343     the webserver, which needs to forward those requests to the xen
    344     server.  The Xen server runs another proxy that (1) authenticates
    345     and (2) finds the correct port for the VM.
    346 
    347     You might want iptables like:
    348 
    349     -t nat -A PREROUTING -s ! 18.181.0.60 -i eth1 -p tcp -m tcp \
    350       --dport 10003 -j DNAT --to-destination 18.181.0.60:10003
    351     -t nat -A POSTROUTING -d 18.181.0.60 -o eth1 -p tcp -m tcp \
    352       --dport 10003 -j SNAT --to-source 18.187.7.142
    353     -A FORWARD -d 18.181.0.60 -i eth1 -o eth1 -p tcp -m tcp \
    354       --dport 10003 -j ACCEPT
    355 
    356     Remember to enable iptables!
    357     echo 1 > /proc/sys/net/ipv4/ip_forward
    358     """
    359     machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
    360 
    361     token = controls.vnctoken(machine)
    362     host = controls.listHost(machine)
    363     if host:
    364         port = 10003 + [h.hostname for h in config.hosts].index(host)
    365     else:
    366         port = 5900 # dummy
    367 
    368     status = controls.statusInfo(machine)
    369     has_vnc = hasVnc(status)
    370 
    371     d = dict(user=username,
    372              on=status,
    373              has_vnc=has_vnc,
    374              machine=machine,
    375              hostname=state.environ.get('SERVER_NAME', 'localhost'),
    376              port=port,
    377              authtoken=token)
    378     return templates.vnc(searchList=[d])
    379 
    380381def getHostname(nic):
    381382    """Find the hostname associated with a NIC.
     
    650651    raise RuntimeError("test of the emergency broadcast system")
    651652
    652 mapping = dict(vnc=vnc,
     653mapping = dict(
    653654               command=command,
    654655               modify=modify,
Note: See TracChangeset for help on using the changeset viewer.