From d5c709a5a9d53bbff6fae1e3eab6e0a4acf294bf Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Sun, 9 Aug 2009 18:45:35 -0400 Subject: [PATCH] Upgrade info page to Mako, and use REST-style URLs. svn path=/package_branches/invirt-web/cherrypy-rebased/; revision=2678 --- code/main.py | 33 +++++++--- code/templates/info.mako | 102 ++++++++++++++++++++++++++++++ code/templates/info.tmpl | 142 ------------------------------------------ code/templates/list.mako | 6 +- code/templates/skeleton.mako | 5 +- 5 files changed, 134 insertions(+), 154 deletions(-) create mode 100644 code/templates/info.mako delete mode 100644 code/templates/info.tmpl diff --git a/code/main.py b/code/main.py index 47f9b01..656c209 100755 --- a/code/main.py +++ b/code/main.py @@ -150,6 +150,31 @@ 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 + + machine = MachineView() + def pathSplit(path): if path.startswith('/'): path = path[1:] @@ -605,13 +630,6 @@ def infoDict(username, state, machine): 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, @@ -636,7 +654,6 @@ def throwError(_, __, ___, ____): mapping = dict(vnc=vnc, command=command, modify=modify, - info=info, create=create, unauth=unauthFront, admin=admin, diff --git a/code/templates/info.mako b/code/templates/info.mako new file mode 100644 index 0000000..5af29bb --- /dev/null +++ b/code/templates/info.mako @@ -0,0 +1,102 @@ +<%page expression_filter="h"/> +<%inherit file="skeleton.mako" /> + +<%def name="title()"> +Info on ${machine.name} + + +<%def name="infoTable()"> +

Info

+ + % for key, value in fields: + + % endfor +
${key}:${value}
+ + +<%def name="commands()"> +% if on: + % if not machine.type.hvm: + Console access: type + ssh ${machine.name}@${config.console.hostname} + on Athena. (more info) + % elif has_vnc: + Get Console + % else: + VNC console not enabled; still booting? + % endif +% endif +
+ + +
+ % if on: + + + + % else: + + % endif +
+
+ Boot CD: +${self.fn.cdromList()} +
+
+ +
+
+ + +<%def name="modifyForm()"> +% if err: +

We had a problem with your request:

+% elif new_machine: +

Successfully modified.

+% endif +% if on: +(To edit ram, disk size, or machine name, turn off the machine first.) +% endif +
+ + + + +${self.fn.errorRow('owner', err)} + +${self.fn.errorRow('administrator', err)} + +${self.fn.errorRow('contact', err)} +% if not on: + +${self.fn.errorRow('name', err)} + + + + + +${self.fn.errorRow('memory', err)} + +${self.fn.errorRow('disk', err)} +% else: +${self.fn.errorRow('name', err)} +${self.fn.errorRow('memory', err)} +${self.fn.errorRow('disk', err)} +% endif + +
Description:
Owner${self.fn.helppopup("Owner")}:
Administrator${self.fn.helppopup("Administrator")}:
Contact email:
Machine Name:.${config.dns.domains[0]}
HVM/ParaVM${self.fn.helppopup('HVM/ParaVM')}${self.fn.vmTypeList(defaults.type)}
Ram:MiB (max ${max_mem})
Disk:GiB (max ${max_disk})WARNING: Modifying disk size may corrupt your data.
+
+ + +
+ ${infoTable()} +
+ +

Commands

+
+ ${commands()} +
+

Settings

+
+ ${modifyForm()} +
diff --git a/code/templates/info.tmpl b/code/templates/info.tmpl deleted file mode 100644 index d872fce..0000000 --- a/code/templates/info.tmpl +++ /dev/null @@ -1,142 +0,0 @@ -#from skeleton import skeleton -#extends skeleton - -#def title -Info on $machine.name -#end def - -#def infoTable() -

Info

- - #for $key, $value in $fields - - #end for -
$key:$value
-#end def - -#def commands() -#if $on - #if not $machine.type.hvm - Console access: type - ssh $machine.name@$config.console.hostname - on Athena. (more info) - #elif $has_vnc - Get Console - #else - VNC console not enabled; still booting? - #end if -#end if -
- - -
- #if $on - - - - #else - - #end if -
-
- Boot CD: -#filter None -$cdromList()#slurp -#end filter -
-
- -
-
-#end def - -#def modifyForm() -#if $err -

We had a problem with your request:

-#else if $varExists('new_machine') -

Successfully modified.

-#end if -#if $on -(To edit ram, disk size, or machine name, turn off the machine first.) -#end if -
- - - - -#filter None -$errorRow('owner', $err) -#end filter - -#filter None -$errorRow('administrator', $err) -#end filter - -#filter None -$errorRow('contact', $err) -#end filter -#if not $on - -#filter None -$errorRow('name', $err) -#end filter - - - - - -#filter None -$errorRow('memory', $err) -#end filter - -#filter None -$errorRow('disk', $err) -#end filter -#else -#filter None -$errorRow('name', $err) -$errorRow('memory', $err) -$errorRow('disk', $err) -#end filter -#end if - -
Description:
Owner#slurp -#filter None -$helppopup("Owner")#slurp -#end filter -:
Administrator#slurp -#filter None -$helppopup("Administrator")#slurp -#end filter -:
Contact email:
Machine Name:.${config.dns.domains[0]}
HVM/ParaVM#slurp -#filter None -$helppopup('HVM/ParaVM')#slurp -#end filter -#slurp -#filter None -$vmTypeList($defaults.type)#slurp -#end filter -
Ram:MiB (max $max_mem)
Disk:GiB (max $max_disk)WARNING: Modifying disk size may corrupt your data.
-
-#end def - -#def body -
-#filter None - $infoTable() -#end filter -
- -

Commands

-
-#filter None - $commands() -#end filter -
-

Settings

-
-#filter None - $modifyForm() -#end filter -
-#end def diff --git a/code/templates/list.mako b/code/templates/list.mako index b03a04f..e500896 100644 --- a/code/templates/list.mako +++ b/code/templates/list.mako @@ -95,7 +95,7 @@ ${self.fn.cdromList(defaults.cdrom, "$('cd_or_auto_cd').checked = true;$('autoin /> - ${machine.name} + ${machine.name} ${machine.memory}M ${machine.owner} ${machine.administrator} @@ -111,7 +111,9 @@ ${datetime.timedelta(seconds=int(machine.uptime))}\ \ % if has_vnc[machine] == True: -Console\ +Console\ +% elif has_vnc[machine] == 'ParaVM': +ParaVM${self.fn.helppopup("ParaVM Console")} % elif has_vnc[machine] != 'Off': ${has_vnc[machine]} % endif diff --git a/code/templates/skeleton.mako b/code/templates/skeleton.mako index a619a67..9c60c56 100644 --- a/code/templates/skeleton.mako +++ b/code/templates/skeleton.mako @@ -5,6 +5,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ${self.title()} — XVM + @@ -53,8 +54,8 @@ function helppopup(name){ -- 1.7.9.5