Changeset 438 for trunk/packages/sipb-xen-www
- Timestamp:
- Apr 21, 2008, 7:22:21 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-www/code/main.py
r437 r438 60 60 def helppopup(subj): 61 61 """Return HTML code for a (?) link to a specified help topic""" 62 return ('<span class="helplink"><a href="help?subject=' + subj + 63 '&simple=true" target="_blank" ' + 62 return ('<span class="helplink"><a href="help?subject=' + subj + 63 '&simple=true" target="_blank" ' + 64 64 'onclick="return helppopup(\'' + subj + '\')">(?)</a></span>') 65 65 … … 143 143 raise InvalidInput('name', name, 144 144 "Name already exists.") 145 145 146 146 owner = validation.testOwner(user, fields.getfirst('owner')) 147 147 148 148 memory = fields.getfirst('memory') 149 149 memory = validation.validMemory(owner, memory, on=True) 150 150 151 151 disk_size = fields.getfirst('disk') 152 152 disk_size = validation.validDisk(owner, disk_size) … … 162 162 if clone_from and clone_from != 'ice3': 163 163 raise CodeError("Invalid clone image '%s'" % clone_from) 164 164 165 165 return dict(contact=user, name=name, memory=memory, disk_size=disk_size, 166 166 owner=owner, machine_type=vm_type, cdrom=cdrom, clone_from=clone_from) … … 187 187 188 188 def getListDict(user): 189 """Gets the list of local variables used by list.tmpl.""" 189 190 machines = g.machines 190 191 checkpoint.checkpoint('Got my machines') … … 229 230 checkpoint.checkpoint('Got list dict') 230 231 return templates.list(searchList=[d]) 231 232 232 233 def vnc(user, fields): 233 234 """VNC applet page. … … 241 242 242 243 -t nat -A PREROUTING -s ! 18.181.0.60 -i eth1 -p tcp -m tcp \ 243 --dport 10003 -j DNAT --to-destination 18.181.0.60:10003 244 --dport 10003 -j DNAT --to-destination 18.181.0.60:10003 244 245 -t nat -A POSTROUTING -d 18.181.0.60 -o eth1 -p tcp -m tcp \ 245 --dport 10003 -j SNAT --to-source 18.187.7.142 246 --dport 10003 -j SNAT --to-source 18.187.7.142 246 247 -A FORWARD -d 18.181.0.60 -i eth1 -o eth1 -p tcp -m tcp \ 247 248 --dport 10003 -j ACCEPT … … 251 252 """ 252 253 machine = validation.testMachineId(user, fields.getfirst('machine_id')) 253 254 254 255 TOKEN_KEY = "0M6W0U1IXexThi5idy8mnkqPKEq1LtEnlK/pZSn0cDrN" 255 256 … … 264 265 token = cPickle.dumps(token) 265 266 token = base64.urlsafe_b64encode(token) 266 267 267 268 status = controls.statusInfo(machine) 268 269 has_vnc = hasVnc(status) 269 270 270 271 d = dict(user=user, 271 272 on=status, … … 277 278 278 279 def getHostname(nic): 280 """Find the hostname associated with a NIC. 281 282 XXX this should be merged with the similar logic in DNS and DHCP. 283 """ 279 284 if nic.hostname and '.' in nic.hostname: 280 285 return nic.hostname … … 318 323 for disk in machine.disks: 319 324 name = disk.guest_device_name 320 disk_fields.extend([(x % name, y % name) for x, y in 325 disk_fields.extend([(x % name, y % name) for x, y in 321 326 disk_fields_template]) 322 327 data_dict['%s_size' % name] = "%0.1f GiB" % (disk.size / 1024.) … … 353 358 354 359 def modifyDict(user, fields): 360 """Modify a machine as specified by CGI arguments. 361 362 Return a list of local variables for modify.tmpl. 363 """ 355 364 olddisk = {} 356 365 transaction = ctx.current.create_transaction() … … 370 379 memory = validation.validMemory(user, memory, machine, on=False) 371 380 machine.memory = memory 372 381 373 382 disksize = validation.testDisk(user, fields.getfirst('disk')) 374 383 if disksize is not None: … … 379 388 disk.size = disksize 380 389 ctx.current.save(disk) 381 390 382 391 if owner is not None: 383 392 machine.owner = owner … … 388 397 if contact is not None: 389 398 machine.contact = contact 390 399 391 400 ctx.current.save(machine) 392 401 transaction.commit() … … 401 410 command=command, 402 411 machine=machine) 403 412 404 413 def modify(user, fields): 405 414 """Handler for modifying attributes of a machine.""" … … 420 429 info_dict['result'] = result 421 430 return templates.info(searchList=[info_dict]) 422 431 423 432 424 433 def helpHandler(user, fields): … … 426 435 simple = fields.getfirst('simple') 427 436 subjects = fields.getlist('subject') 428 437 429 438 help_mapping = dict(paravm_console=""" 430 439 ParaVM machines do not support local console access over VNC. To … … 461 470 """ 462 471 ) 463 472 464 473 if not subjects: 465 474 subjects = sorted(help_mapping.keys()) 466 475 467 476 d = dict(user=user, 468 477 simple=simple, 469 478 subjects=subjects, 470 479 mapping=help_mapping) 471 480 472 481 return templates.help(searchList=[d]) 473 482 474 483 475 484 def badOperation(u, e): 485 """Function called when accessing an unknown URI.""" 476 486 raise CodeError("Unknown operation") 477 487 478 488 def infoDict(user, machine): 489 """Get the variables used by info.tmpl.""" 479 490 status = controls.statusInfo(machine) 480 491 checkpoint.checkpoint('Getting status info') … … 523 534 nic_fields = getNicInfo(machine_info, machine) 524 535 nic_point = display_fields.index('NIC_INFO') 525 display_fields = (display_fields[:nic_point] + nic_fields + 536 display_fields = (display_fields[:nic_point] + nic_fields + 526 537 display_fields[nic_point+1:]) 527 538 528 539 disk_fields = getDiskInfo(machine_info, machine) 529 540 disk_point = display_fields.index('DISK_INFO') 530 display_fields = (display_fields[:disk_point] + disk_fields + 541 display_fields = (display_fields[:disk_point] + disk_fields + 531 542 display_fields[disk_point+1:]) 532 543 533 544 main_status['memory'] += ' MiB' 534 545 for field, disp in display_fields: … … 584 595 585 596 def printHeaders(headers): 597 """Print a dictionary as HTTP headers.""" 586 598 for key, value in headers.iteritems(): 587 599 print '%s: %s' % (key, value) … … 594 606 return username 595 607 596 def main(operation, user, fields): 608 def main(operation, user, fields): 597 609 start_time = time.time() 598 610 fun = mapping.get(operation, badOperation)
Note: See TracChangeset
for help on using the changeset viewer.