- Timestamp:
- Oct 9, 2007, 8:09:47 AM (17 years ago)
- Location:
- trunk/web/templates
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/templates/error.tmpl
r113 r153 8 8 #def body 9 9 <h1>ERROR</h1> 10 <p>$errorMessage in operation $op</p>11 10 11 <p>$errorMessage in operation $op. This shouldn't happen! Please 12 email sipb-xen@mit.edu to explain how it happened. Stderr:</p> 13 <pre>$stderr</pre> 12 14 #end def -
trunk/web/templates/info.tmpl
r147 r153 63 63 <input type="hidden" name="machine_id" value="$machine.machine_id"/> 64 64 <table> 65 <tr><td>Owner:</td><td><input type="text" value="$machine.owner"/></td></tr>66 <tr><td>Contact email:</td><td><input type="text" value="$machine.contact"/></td></tr>65 <tr><td>Owner:</td><td><input type="text" name="owner", value="$machine.owner"/></td></tr> 66 <tr><td>Contact email:</td><td><input type="text" name="contact" value="$machine.contact"/></td></tr> 67 67 #if $machine.nics 68 <tr><td>Hostname:</td><td><input type="text" value="$machine.nics[0].hostname"/>.servers.csail.mit.edu</td></tr>68 <tr><td>Hostname:</td><td><input type="text" name="hostname" value="$machine.nics[0].hostname"/>.servers.csail.mit.edu</td></tr> 69 69 #end if 70 70 #if not $on 71 <tr><td>Ram:</td><td><input type="text" size=3 value="$machine.memory"/>MB (max $max_mem)</td></tr>72 <tr><td>Disk:</td><td><input type="text" size=3 value="${machine.disks[0].size/1024.}"/>GB (max $max_disk)</td><td>WARNING: Modifying disk size may corrupt your data.</td></tr>71 <tr><td>Ram:</td><td><input type="text" size=3 name="memory" value="$machine.memory"/>MB (max $max_mem)</td></tr> 72 <tr><td>Disk:</td><td><input type="text" size=3 name="disk" value="${machine.disks[0].size/1024.}"/>GB (max $max_disk)</td><td>WARNING: Modifying disk size may corrupt your data.</td></tr> 73 73 #end if 74 74 <tr><td><input type="submit" class="button" name="action" value="Change"/></td></tr> -
trunk/web/templates/main.py
r152 r153 13 13 import hmac 14 14 import datetime 15 16 sys.stderr = sys.stdout 15 import StringIO 16 17 sys.stderr = StringIO.StringIO() 17 18 sys.path.append('/home/ecprice/.local/lib/python2.5/site-packages') 18 19 … … 32 33 the select box). 33 34 """ 34 pass 35 def __init__(self, err_field, err_value, expl=None): 36 super(InvalidInput, self).__init__(expl) 37 self.err_field = err_field 38 self.err_value = err_value 35 39 36 40 class CodeError(MyException): … … 116 120 return machine.owner == user.username 117 121 118 def error(op, user, fields, err ):122 def error(op, user, fields, err, emsg): 119 123 """Print an error page when a CodeError occurs""" 120 d = dict(op=op, user=user, errorMessage=str(err)) 121 print Template(file='error.tmpl', searchList=[d, global_dict]); 124 d = dict(op=op, user=user, errorMessage=str(err), 125 stderr=emsg) 126 return Template(file='error.tmpl', searchList=[d, global_dict]); 127 128 def invalidInput(op, user, fields, err, emsg): 129 """Print an error page when an InvalidInput exception occurs""" 130 d = dict(op=op, user=user, err_field=err.err_field, 131 err_value=str(err.err_value), stderr=emsg, 132 errorMessage=str(err)) 133 return Template(file='invalid.tmpl', searchList=[d, global_dict]); 122 134 123 135 def validMachineName(name): … … 266 278 try: 267 279 if memory > maxMemory(user): 268 raise InvalidInput("Too much memory requested") 280 raise InvalidInput('memory', memory, 281 "Max %s" % maxMemory(user)) 269 282 if disk > maxDisk(user) * 1024: 270 raise InvalidInput("Too much disk requested") 283 raise InvalidInput('disk', disk, 284 "Max %s" % maxDisk(user)) 271 285 if not canAddVm(user): 272 raise InvalidInput( "Too many VMs requested")286 raise InvalidInput('create', True, 'Unable to create more VMs') 273 287 res = meta.engine.execute('select nextval(\'"machines_machine_id_seq"\')') 274 288 id = res.fetchone()[0] … … 312 326 raise ValueError 313 327 except ValueError: 314 raise InvalidInput( "Invalid memory amount; must be at least %s MB" %315 MIN_MEMORY_SINGLE)328 raise InvalidInput('memory', memory, 329 "Minimum %s MB" % MIN_MEMORY_SINGLE) 316 330 if memory > maxMemory(user, machine): 317 raise InvalidInput("Too much memory requested") 331 raise InvalidInput('memory', memory, 332 'Maximum %s MB' % maxMemory(user, machine)) 318 333 return memory 319 334 … … 323 338 disk = float(disk) 324 339 if disk > maxDisk(user, machine): 325 raise InvalidInput("Too much disk requested") 340 raise InvalidInput('disk', disk, 341 "Maximum %s G" % maxDisk(user, machine)) 326 342 disk = int(disk * 1024) 327 343 if disk < MIN_DISK_SINGLE * 1024: 328 344 raise ValueError 329 345 except ValueError: 330 raise InvalidInput( "Invalid disk amount; minimum is %s GB" %331 MIN_DISK_SINGLE)346 raise InvalidInput('disk', disk, 347 "Minimum %s GB" % MIN_DISK_SINGLE) 332 348 return disk 333 349 … … 336 352 name = fields.getfirst('name') 337 353 if not validMachineName(name): 338 raise InvalidInput( "Invalid name '%s'" %name)354 raise InvalidInput('name', name) 339 355 name = user.username + '_' + name.lower() 340 356 341 357 if Machine.get_by(name=name): 342 raise InvalidInput("A machine named '%s' already exists" % name) 358 raise InvalidInput('name', name, 359 "Already exists") 343 360 344 361 memory = fields.getfirst('memory') … … 360 377 d = dict(user=user, 361 378 machine=machine) 362 printTemplate(file='create.tmpl',379 return Template(file='create.tmpl', 363 380 searchList=[d, global_dict]); 364 381 … … 392 409 uptimes=uptimes, 393 410 cdroms=CDROM.select()) 394 printTemplate(file='list.tmpl', searchList=[d, global_dict])411 return Template(file='list.tmpl', searchList=[d, global_dict]) 395 412 396 413 def testMachineId(user, machineId, exists=True): … … 453 470 hostname=os.environ.get('SERVER_NAME', 'localhost'), 454 471 authtoken=token) 455 printTemplate(file='vnc.tmpl',472 return Template(file='vnc.tmpl', 456 473 searchList=[d, global_dict]) 457 474 … … 530 547 elif action == 'Power on': 531 548 if maxMemory(user) < machine.memory: 532 raise InvalidInput("You don't have enough free RAM quota") 549 raise InvalidInput('action', 'Power on', 550 "You don't have enough free RAM quota to turn on this machine") 533 551 bootMachine(machine, cdrom) 534 552 elif action == 'Power off': … … 543 561 command=action, 544 562 machine=machine) 545 print Template(file="command.tmpl", searchList=[d, global_dict]) 546 563 return Template(file="command.tmpl", searchList=[d, global_dict]) 564 565 def testOwner(user, owner, machine=None): 566 if owner != user.username: 567 raise InvalidInput('owner', owner, 568 "Invalid") 569 return owner 570 571 def testContact(user, contact, machine=None): 572 if contact != user.email: 573 raise InvalidInput('contact', contact, 574 "Invalid") 575 return contact 576 577 def testHostname(user, hostname, machine): 578 for nic in machine.nics: 579 if hostname == nic.hostname: 580 return hostname 581 raise InvalidInput('hostname', hostname, 582 "Different from before") 583 584 547 585 def modify(user, fields): 548 586 """Handler for modifying attributes of a machine.""" 549 587 #XXX not written yet 550 588 machine = testMachineId(user, fields.getfirst('machine_id')) 551 589 owner = testOwner(user, fields.getfirst('owner'), machine) 590 contact = testContact(user, fields.getfirst('contact')) 591 hostname = testHostname(user, fields.getfirst('hostname'), 592 machine) 593 ram = fields.getfirst('memory') 594 if ram is not None: 595 ram = validMemory(user, ram, machine) 596 disk = testDisk(user, fields.getfirst('disk')) 597 if disk is not None: 598 disk = validDisk(user, disk, machine) 599 600 601 552 602 def help(user, fields): 553 603 """Handler for help messages.""" … … 570 620 mapping=mapping) 571 621 572 printTemplate(file="help.tmpl", searchList=[d, global_dict])622 return Template(file="help.tmpl", searchList=[d, global_dict]) 573 623 574 624 … … 645 695 max_disk=max_disk, 646 696 fields = fields) 647 printTemplate(file='info.tmpl',697 return Template(file='info.tmpl', 648 698 searchList=[d, global_dict]) 649 699 … … 686 736 operation = 'list' 687 737 688 fun = mapping.get(operation,689 lambda u, e:690 error(operation, u, e, 691 "Invalid operation '%s'" % operation))738 def badOperation(u, e): 739 raise CodeError("Unknown operation") 740 741 fun = mapping.get(operation, badOperation) 692 742 if fun not in (help, ): 693 743 connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen') 694 744 try: 695 fun(u, fields) 745 output = fun(u, fields) 746 print 'Content-Type: text/html\n' 747 sys.stderr.seek(0) 748 e = sys.stderr.read() 749 if e: 750 output = output.replace('<body>', '<body><pre>'+e+'</pre>') 751 print output 696 752 except CodeError, err: 697 error(operation, u, fields, err) 753 print 'Content-Type: text/html\n' 754 sys.stderr.seek(0) 755 e = sys.stderr.read() 756 print error(operation, u, fields, err, e) 698 757 except InvalidInput, err: 699 error(operation, u, fields, err) 758 print 'Content-Type: text/html\n' 759 sys.stderr.seek(0) 760 e = sys.stderr.read() 761 print invalidInput(operation, u, fields, err, e) 762 except: 763 print 'Content-Type: text/plain\n' 764 sys.stderr.seek(0) 765 e = sys.stderr.read() 766 print e 767 print '----' 768 raise -
trunk/web/templates/skeleton.tmpl
r139 r153 16 16 function helppopup(name){ 17 17 closeWin() 18 helpWin = window.open("help?simple=true&subject="+encodeURIComponent(name), "H MMTHelp",18 helpWin = window.open("help?simple=true&subject="+encodeURIComponent(name), "Help", 19 19 "status, height = 300, width = 400"); 20 20 if (window.focus){helpWin.focus();}
Note: See TracChangeset
for help on using the changeset viewer.