X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/e4854da750615c45d19dbffa1643dc36bfc86048..134d4e881d540fbe492687aac00b8aab2ce7c728:/code/main.py diff --git a/code/main.py b/code/main.py index 593b9f0..d938450 100755 --- a/code/main.py +++ b/code/main.py @@ -139,8 +139,7 @@ console will suffer artifacts. if not isinstance(subject, list): subject = [subject] - return dict(user=cherrypy.request.login, - simple=simple, + return dict(simple=simple, subjects=subject, mapping=help_mapping) help._cp_config['tools.require_login.on'] = False @@ -151,6 +150,73 @@ console will suffer artifacts. return {'request': cherrypy.request, 'kwargs': kwargs} helloworld._cp_config['tools.require_login.on'] = False + class MachineView(View): + # This is hairy. Fix when CherryPy 3.2 is out. (rename to + # _cp_dispatch, and parse the argument as a list instead of + # string + + def __getattr__(self, name): + try: + machine_id = int(name) + cherrypy.request.params['machine_id'] = machine_id + return self + except ValueError: + return None + + @cherrypy.expose + @cherrypy.tools.mako(filename="/info.mako") + def info(self, machine_id): + """Handler for info on a single VM.""" + machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine + d = infoDict(cherrypy.request.login, cherrypy.request.state, machine) + checkpoint.checkpoint('Got infodict') + 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): if path.startswith('/'): path = path[1:] @@ -291,7 +357,7 @@ def getListDict(username, state): elif m.type.hvm: has_vnc[m] = "WTF?" else: - has_vnc[m] = "ParaVM"+helppopup("ParaVM Console") + has_vnc[m] = "ParaVM" max_memory = validation.maxMemory(username, state) max_disk = validation.maxDisk(username) checkpoint.checkpoint('Got max mem/disk') @@ -312,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. @@ -548,7 +573,6 @@ def infoDict(username, state, machine): ('memory', 'RAM'), 'DISK_INFO', ('state', 'state (xen format)'), - ('cpu_weight', 'CPU weight'+helppopup('CPU Weight')), ] fields = [] machine_info = {} @@ -602,17 +626,9 @@ def infoDict(username, state, machine): ram=machine.memory, max_mem=max_mem, max_disk=max_disk, - owner_help=helppopup("Owner"), fields = fields) return d -def info(username, state, path, fields): - """Handler for info on a single VM.""" - machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine - d = infoDict(username, state, machine) - checkpoint.checkpoint('Got infodict') - return templates.info(searchList=[d]) - def unauthFront(_, _2, _3, fields): """Information for unauth'd users.""" return templates.unauth(searchList=[{'simple' : True, @@ -634,10 +650,9 @@ 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, - info=info, create=create, unauth=unauthFront, admin=admin,