Help!
authorEric Price <ecprice@mit.edu>
Mon, 8 Oct 2007 07:37:59 +0000 (03:37 -0400)
committerEric Price <ecprice@mit.edu>
Mon, 8 Oct 2007 07:37:59 +0000 (03:37 -0400)
svn path=/trunk/web/; revision=139

templates/help.tmpl [new file with mode: 0644]
templates/list.tmpl
templates/main.py
templates/skeleton.py
templates/skeleton.tmpl

diff --git a/templates/help.tmpl b/templates/help.tmpl
new file mode 100644 (file)
index 0000000..9998922
--- /dev/null
@@ -0,0 +1,16 @@
+#from skeleton import skeleton
+#extends skeleton
+
+#def title
+Help
+#end def
+
+
+#def body
+#if not $simple
+<h1>Help</h1>
+#end if
+#for $subject in $subjects
+<p>$mapping[$subject]</p>
+#end for
+#end def
index 7dd0da0..19b108e 100644 (file)
@@ -79,7 +79,7 @@ $has_vnc.get($machine.name)
          <td><input type="text" name="disk" value="$maxdisk" size=3/> gigabytes ($maxdisk max)</td>
        </tr>
        <tr>
          <td><input type="text" name="disk" value="$maxdisk" size=3/> gigabytes ($maxdisk max)</td>
        </tr>
        <tr>
-         <td>HVM/ParaVM</td>
+         <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
          <td>
            <input checked type="radio" name="vmtype" value="hvm">HVM</input>
            <input type="radio" name="vmtype" value="paravm">ParaVM</input>
          <td>
            <input checked type="radio" name="vmtype" value="hvm">HVM</input>
            <input type="radio" name="vmtype" value="paravm">ParaVM</input>
index 4a50e43..b528b3e 100755 (executable)
@@ -24,6 +24,14 @@ import random
 class MyException(Exception):
     pass
 
 class MyException(Exception):
     pass
 
+def helppopup(subj):
+    return '<span class="helplink"><a href="help?subject='+subj+'&amp;simple=true" target="_blank" onclick="return helppopup(\''+subj+'\')">(?)</a></span>'
+
+
+global_dict = {}
+global_dict['helppopup'] = helppopup
+
+
 # ... and stolen from xend/uuid.py
 def randomUUID():
     """Generate a random UUID."""
 # ... and stolen from xend/uuid.py
 def randomUUID():
     """Generate a random UUID."""
@@ -47,7 +55,7 @@ def haveAccess(user, machine):
 
 def error(op, user, fields, err):
     d = dict(op=op, user=user, errorMessage=str(err))
 
 def error(op, user, fields, err):
     d = dict(op=op, user=user, errorMessage=str(err))
-    print Template(file='error.tmpl', searchList=d);
+    print Template(file='error.tmpl', searchList=[d, global_dict]);
 
 def validMachineName(name):
     """Check that name is valid for a machine name"""
 
 def validMachineName(name):
     """Check that name is valid for a machine name"""
@@ -267,7 +275,7 @@ def create(user, fields):
     d = dict(user=user,
              machine=machine)
     print Template(file='create.tmpl',
     d = dict(user=user,
              machine=machine)
     print Template(file='create.tmpl',
-                   searchList=d);
+                   searchList=[d, global_dict]);
 
 def listVms(user, fields):
     machines = [m for m in Machine.select() if haveAccess(user, m)]    
 
 def listVms(user, fields):
     machines = [m for m in Machine.select() if haveAccess(user, m)]    
@@ -281,8 +289,7 @@ def listVms(user, fields):
         elif m.type.hvm:
             has_vnc[m.name] = True
         else:
         elif m.type.hvm:
             has_vnc[m.name] = True
         else:
-            help_name = 'paravm_console'
-            has_vnc[m.name] = 'ParaVM <span class="helplink"><a href="help?subject=%s&amp;simple=true" target="_blank" onclick="return helppopup(\'%s\')">(?)</a></span>' % (help_name, help_name)
+            has_vnc[m.name] = "ParaVM"+helppopup("paravm_console")
     #     for m in machines:
     #         status = statusInfo(m)
     #         on[m.name] = status is not None
     #     for m in machines:
     #         status = statusInfo(m)
     #         on[m.name] = status is not None
@@ -294,7 +301,7 @@ def listVms(user, fields):
              has_vnc=has_vnc,
              uptimes=uptimes,
              cdroms=CDROM.select())
              has_vnc=has_vnc,
              uptimes=uptimes,
              cdroms=CDROM.select())
-    print Template(file='list.tmpl', searchList=d)
+    print Template(file='list.tmpl', searchList=[d, global_dict])
 
 def testMachineId(user, machineId, exists=True):
     if machineId is None:
 
 def testMachineId(user, machineId, exists=True):
     if machineId is None:
@@ -345,7 +352,7 @@ def vnc(user, fields):
              hostname=os.environ.get('SERVER_NAME', 'localhost'),
              authtoken=token)
     print Template(file='vnc.tmpl',
              hostname=os.environ.get('SERVER_NAME', 'localhost'),
              authtoken=token)
     print Template(file='vnc.tmpl',
-                   searchList=d)
+                   searchList=[d, global_dict])
 
 def getNicInfo(data_dict, machine):
     data_dict['num_nics'] = len(machine.nics)
 
 def getNicInfo(data_dict, machine):
     data_dict['num_nics'] = len(machine.nics)
@@ -420,11 +427,32 @@ def command(user, fields):
     d = dict(user=user,
              command=action,
              machine=machine)
     d = dict(user=user,
              command=action,
              machine=machine)
-    print Template(file="command.tmpl", searchList=d)
+    print Template(file="command.tmpl", searchList=[d, global_dict])
         
 def modify(user, fields):
     machine = testMachineId(user, fields.getfirst('machine_id'))
     
         
 def modify(user, fields):
     machine = testMachineId(user, fields.getfirst('machine_id'))
     
+def help(user, fields):
+    simple = fields.getfirst('simple')
+    subjects = fields.getlist('subject')
+    
+    mapping = dict(paravm_console="""
+ParaVM machines do not support console access over VNC.  To access
+these machines, you either need to boot with a liveCD and ssh in or
+hope that the sipb-xen maintainers add support for serial consoles.""",
+                   hvm_paravm="""
+HVM machines use the virtualization features of the processor, while
+ParaVM machines use Xen's emulation of virtualization features.  You
+want an HVM virtualized machine.""",
+                   cpu_weight="""Don't ask us!  We're as mystified as you are.""")
+    
+    d = dict(user=user,
+             simple=simple,
+             subjects=subjects,
+             mapping=mapping)
+    
+    print Template(file="help.tmpl", searchList=[d, global_dict])
+    
 
 def info(user, fields):
     machine = testMachineId(user, fields.getfirst('machine_id'))
 
 def info(user, fields):
     machine = testMachineId(user, fields.getfirst('machine_id'))
@@ -451,7 +479,7 @@ def info(user, fields):
                       ('memory', 'RAM'),
                       'DISK_INFO',
                       ('state', 'state (xen format)'),
                       ('memory', 'RAM'),
                       'DISK_INFO',
                       ('state', 'state (xen format)'),
-                      ('cpu_weight', 'CPU weight'),
+                      ('cpu_weight', 'CPU weight'+helppopup('cpu_weight')),
                       ('on_reboot', 'Action on VM reboot'),
                       ('on_poweroff', 'Action on VM poweroff'),
                       ('on_crash', 'Action on VM crash'),
                       ('on_reboot', 'Action on VM reboot'),
                       ('on_poweroff', 'Action on VM poweroff'),
                       ('on_crash', 'Action on VM crash'),
@@ -496,14 +524,15 @@ def info(user, fields):
              maxdisk=maxDisk(user, machine),
              fields = fields)
     print Template(file='info.tmpl',
              maxdisk=maxDisk(user, machine),
              fields = fields)
     print Template(file='info.tmpl',
-                   searchList=d)
+                   searchList=[d, global_dict])
 
 mapping = dict(list=listVms,
                vnc=vnc,
                command=command,
                modify=modify,
                info=info,
 
 mapping = dict(list=listVms,
                vnc=vnc,
                command=command,
                modify=modify,
                info=info,
-               create=create)
+               create=create,
+               help=help)
 
 if __name__ == '__main__':
     start_time = time.time()
 
 if __name__ == '__main__':
     start_time = time.time()
@@ -512,7 +541,6 @@ if __name__ == '__main__':
         username = "moo"
         email = 'moo@cow.com'
     u = User()
         username = "moo"
         email = 'moo@cow.com'
     u = User()
-    connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
     operation = os.environ.get('PATH_INFO', '')
     if not operation:
         pass
     operation = os.environ.get('PATH_INFO', '')
     if not operation:
         pass
@@ -527,6 +555,8 @@ if __name__ == '__main__':
                       lambda u, e:
                           error(operation, u, e,
                                 "Invalid operation '%s'" % operation))
                       lambda u, e:
                           error(operation, u, e,
                                 "Invalid operation '%s'" % operation))
+    if fun not in (help, ):
+        connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
     try:
         fun(u, fields)
     except MyException, err:
     try:
         fun(u, fields)
     except MyException, err:
index 01debf9..09409a5 100644 (file)
@@ -33,10 +33,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '2.0rc8'
 __CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 8)
 currentTime=time.time
 __CHEETAH_version__ = '2.0rc8'
 __CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 8)
-__CHEETAH_genTime__ = 1191718104.9039481
-__CHEETAH_genTimestamp__ = 'Sat Oct  6 20:48:24 2007'
+__CHEETAH_genTime__ = 1191828896.641397
+__CHEETAH_genTimestamp__ = 'Mon Oct  8 03:34:56 2007'
 __CHEETAH_src__ = 'skeleton.tmpl'
 __CHEETAH_src__ = 'skeleton.tmpl'
-__CHEETAH_srcLastModified__ = 'Sat Oct  6 20:18:06 2007'
+__CHEETAH_srcLastModified__ = 'Mon Oct  8 03:34:52 2007'
 __CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
 __CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
@@ -87,19 +87,46 @@ class skeleton(Template):
 <head><title>''')
         _v = VFFSL(SL,"title",True) # '$title' on line 2, col 14
         if _v is not None: write(_filter(_v, rawExpr='$title')) # from line 2, col 14.
 <head><title>''')
         _v = VFFSL(SL,"title",True) # '$title' on line 2, col 14
         if _v is not None: write(_filter(_v, rawExpr='$title')) # from line 2, col 14.
-        write('''</title></head>
+        write('''</title>
+  <link href="/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
+  <style media="screen" type="text/css">
+    @import "static/css/all.css";
+  </style>
+  <script type="text/javascript">
+var helpWin = null;
+function closeWin(){
+\tif (helpWin != null){
+\t\tif(!helpWin.closed)
+\t\t\thelpWin.close();
+\t}
+}
+
+function helppopup(name){
+   closeWin()
+   helpWin = window.open("help?simple=true&subject="+encodeURIComponent(name), "HMMTHelp",
+"status, height = 300, width = 400");
+   if (window.focus){helpWin.focus();}
+   return false;
+}
+</script>
+</head>
 <body>
 <body>
-<p>[You are logged in as ''')
-        _v = VFFSL(SL,"user.username",True) # '$user.username' on line 4, col 26
-        if _v is not None: write(_filter(_v, rawExpr='$user.username')) # from line 4, col 26.
-        write('''.]</p>
 ''')
 ''')
-        _v = VFFSL(SL,"body",True) # '$body' on line 5, col 1
-        if _v is not None: write(_filter(_v, rawExpr='$body')) # from line 5, col 1.
+        if not VFFSL(SL,"varExists",False)('simple') or not VFFSL(SL,"simple",True): # generated from line 26, col 1
+            write('''<p>[You are logged in as ''')
+            _v = VFFSL(SL,"user.username",True) # '$user.username' on line 27, col 26
+            if _v is not None: write(_filter(_v, rawExpr='$user.username')) # from line 27, col 26.
+            write('''.]</p>
+''')
+        _v = VFFSL(SL,"body",True) # '$body' on line 29, col 1
+        if _v is not None: write(_filter(_v, rawExpr='$body')) # from line 29, col 1.
         write('''
         write('''
-<hr />
+''')
+        if not VFFSL(SL,"varExists",False)('simple') or not VFFSL(SL,"simple",True): # generated from line 30, col 1
+            write('''<hr />
 Questions? Contact <a href="mailto:sipb-xen-dev@mit.edu">sipb-xen-dev@mit.edu</a>.
 Questions? Contact <a href="mailto:sipb-xen-dev@mit.edu">sipb-xen-dev@mit.edu</a>.
-</body>
+''')
+        write('''</body>
 </html>
 ''')
         
 </html>
 ''')
         
index 9c1c891..3a5b8e2 100644 (file)
@@ -1,9 +1,35 @@
 <html>
 <html>
-<head><title>$title</title></head>
+<head><title>$title</title>
+  <link href="/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
+  <style media="screen" type="text/css">
+    @import "static/css/all.css";
+  </style>
+  <script type="text/javascript">
+var helpWin = null;
+function closeWin(){
+       if (helpWin != null){
+               if(!helpWin.closed)
+                       helpWin.close();
+       }
+}
+
+function helppopup(name){
+   closeWin()
+   helpWin = window.open("help?simple=true&subject="+encodeURIComponent(name), "HMMTHelp",
+"status, height = 300, width = 400");
+   if (window.focus){helpWin.focus();}
+   return false;
+}
+</script>
+</head>
 <body>
 <body>
+#if not $varExists('simple') or not $simple
 <p>[You are logged in as $user.username.]</p>
 <p>[You are logged in as $user.username.]</p>
+#end if
 $body
 $body
+#if not $varExists('simple') or not $simple
 <hr />
 Questions? Contact <a href="mailto:sipb-xen-dev@mit.edu">sipb-xen-dev@mit.edu</a>.
 <hr />
 Questions? Contact <a href="mailto:sipb-xen-dev@mit.edu">sipb-xen-dev@mit.edu</a>.
+#end if
 </body>
 </html>
 </body>
 </html>