Changeset 572 for trunk/packages
- Timestamp:
- Jun 2, 2008, 11:25:47 PM (16 years ago)
- Location:
- trunk/packages/sipb-xen-www/code
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-www/code/controls.py
r563 r572 93 93 % (err, machine.name, cdtype)) 94 94 95 def createVm( owner, contact, name, memory, disk_size, machine_type, cdrom, clone_from):95 def createVm(username, state, owner, contact, name, memory, disksize, machine_type, cdrom, clone_from): 96 96 """Create a VM and put it in the database""" 97 97 # put stuff in the table 98 98 transaction = ctx.current.create_transaction() 99 99 try: 100 validation.validMemory(owner, memory) 101 validation.validDisk(owner, disk_size * 1. / 1024) 102 validation.validAddVm(owner) 100 validation.Validate(username, state, owner=owner, memory=memory, disksize=disksize/1024.) 103 101 res = meta.engine.execute('select nextval(' 104 102 '\'"machines_machine_id_seq"\')') … … 116 114 ctx.current.save(machine) 117 115 disk = Disk(machine_id=machine.machine_id, 118 guest_device_name='hda', size=disk _size)116 guest_device_name='hda', size=disksize) 119 117 open_nics = NIC.select_by(machine_id=None) 120 118 if not open_nics: #No IPs left! … … 141 139 """Return a dictionary mapping machine names to dicts.""" 142 140 value_string = remctl('web', 'listvms') 143 value_dict = yaml.load(value_string, yaml. CSafeLoader)141 value_dict = yaml.load(value_string, yaml.SafeLoader) 144 142 return value_dict 145 143 … … 209 207 remctl('web', 'lvremove', mname, dname) 210 208 211 def commandResult(user , fields):209 def commandResult(username, state, fields): 212 210 start_time = 0 213 machine = validation. testMachineId(user, fields.getfirst('machine_id'))211 machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine 214 212 action = fields.getfirst('action') 215 213 cdrom = fields.getfirst('cdrom') … … 236 234 237 235 elif action == 'Power on': 238 if validation.maxMemory(user , machine) < machine.memory:236 if validation.maxMemory(username, state, machine) < machine.memory: 239 237 raise InvalidInput('action', 'Power on', 240 238 "You don't have enough free RAM quota " … … 264 262 deleteVM(machine) 265 263 266 d = dict(user=user ,264 d = dict(user=username, 267 265 command=action, 268 266 machine=machine) -
trunk/packages/sipb-xen-www/code/main.py
r566 r572 42 42 import validation 43 43 import cache_acls 44 from webcommon import InvalidInput, CodeError, g44 from webcommon import InvalidInput, CodeError, state 45 45 import controls 46 46 … … 120 120 DEFAULT_HEADERS = {'Content-Type': 'text/html'} 121 121 122 def error(op, user , fields, err, emsg):122 def error(op, username, fields, err, emsg): 123 123 """Print an error page when a CodeError occurs""" 124 d = dict(op=op, user=user , errorMessage=str(err),124 d = dict(op=op, user=username, errorMessage=str(err), 125 125 stderr=emsg) 126 126 return templates.error(searchList=[d]) 127 127 128 def invalidInput(op, user , fields, err, emsg):128 def invalidInput(op, username, fields, err, emsg): 129 129 """Print an error page when an InvalidInput exception occurs""" 130 d = dict(op=op, user=user , err_field=err.err_field,130 d = dict(op=op, user=username, err_field=err.err_field, 131 131 err_value=str(err.err_value), stderr=emsg, 132 132 errorMessage=str(err)) … … 143 143 return False 144 144 145 def parseCreate(user, fields): 146 name = fields.getfirst('name') 147 if not validation.validMachineName(name): 148 raise InvalidInput('name', name, 'You must provide a machine name. Max 22 chars, alnum plus \'-\' and \'_\'.') 149 name = name.lower() 150 151 if Machine.get_by(name=name): 152 raise InvalidInput('name', name, 153 "Name already exists.") 154 155 owner = validation.testOwner(user, fields.getfirst('owner')) 156 157 memory = fields.getfirst('memory') 158 memory = validation.validMemory(owner, memory, on=True) 159 160 disk_size = fields.getfirst('disk') 161 disk_size = validation.validDisk(owner, disk_size) 162 163 vm_type = fields.getfirst('vmtype') 164 vm_type = validation.validVmType(vm_type) 165 166 cdrom = fields.getfirst('cdrom') 167 if cdrom is not None and not CDROM.get(cdrom): 168 raise CodeError("Invalid cdrom type '%s'" % cdrom) 169 170 clone_from = fields.getfirst('clone_from') 171 if clone_from and clone_from != 'ice3': 172 raise CodeError("Invalid clone image '%s'" % clone_from) 173 174 return dict(contact=user, name=name, memory=memory, disk_size=disk_size, 175 owner=owner, machine_type=vm_type, cdrom=cdrom, clone_from=clone_from) 176 177 def create(user, fields): 145 def parseCreate(username, state, fields): 146 kws = dict([(kw, fields.getfirst(kw)) for kw in 'name owner memory disksize vmtype cdrom clone_from'.split()]) 147 validate = validation.Validate(username, state, **kws) 148 return dict(contact=username, name=validate.name, memory=validate.memory, 149 disksize=validate.disksize, owner=validate.owner, machine_type=validate.vmtype, 150 cdrom=getattr(validate, 'cdrom', None), 151 clone_from=getattr(validate, 'clone_from', None)) 152 153 def create(username, state, fields): 178 154 """Handler for create requests.""" 179 155 try: 180 parsed_fields = parseCreate(user , fields)181 machine = controls.createVm( **parsed_fields)156 parsed_fields = parseCreate(username, state, fields) 157 machine = controls.createVm(username, **parsed_fields) 182 158 except InvalidInput, err: 183 159 pass 184 160 else: 185 161 err = None 186 g.clear() #Changed global state187 d = getListDict(user )162 state.clear() #Changed global state 163 d = getListDict(username) 188 164 d['err'] = err 189 165 if err: … … 195 171 196 172 197 def getListDict(user ):173 def getListDict(username, state): 198 174 """Gets the list of local variables used by list.tmpl.""" 199 175 checkpoint.checkpoint('Starting') 200 machines = g.machines176 machines = state.machines 201 177 checkpoint.checkpoint('Got my machines') 202 178 on = {} 203 179 has_vnc = {} 204 xmlist = g.xmlist180 xmlist = state.xmlist 205 181 checkpoint.checkpoint('Got uptimes') 206 can_clone = 'ice3' not in g.xmlist_raw182 can_clone = 'ice3' not in state.xmlist_raw 207 183 for m in machines: 208 184 if m not in xmlist: … … 217 193 else: 218 194 has_vnc[m] = "ParaVM"+helppopup("ParaVM Console") 219 max_memory = validation.maxMemory(user )220 max_disk = validation.maxDisk(user )195 max_memory = validation.maxMemory(username, state) 196 max_disk = validation.maxDisk(username) 221 197 checkpoint.checkpoint('Got max mem/disk') 222 198 defaults = Defaults(max_memory=max_memory, 223 199 max_disk=max_disk, 224 owner=user ,200 owner=username, 225 201 cdrom='gutsy-i386') 226 202 checkpoint.checkpoint('Got defaults') 227 203 def sortkey(machine): 228 return (machine.owner != user , machine.owner, machine.name)204 return (machine.owner != username, machine.owner, machine.name) 229 205 machines = sorted(machines, key=sortkey) 230 d = dict(user=user ,231 cant_add_vm=validation.cantAddVm(user ),206 d = dict(user=username, 207 cant_add_vm=validation.cantAddVm(username, state), 232 208 max_memory=max_memory, 233 209 max_disk=max_disk, … … 238 214 return d 239 215 240 def listVms(user , fields):216 def listVms(username, state, fields): 241 217 """Handler for list requests.""" 242 218 checkpoint.checkpoint('Getting list dict') 243 d = getListDict(user )219 d = getListDict(username, state) 244 220 checkpoint.checkpoint('Got list dict') 245 221 return templates.list(searchList=[d]) 246 222 247 def vnc(user , fields):223 def vnc(username, state, fields): 248 224 """VNC applet page. 249 225 … … 265 241 echo 1 > /proc/sys/net/ipv4/ip_forward 266 242 """ 267 machine = validation. testMachineId(user, fields.getfirst('machine_id'))243 machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine 268 244 269 245 TOKEN_KEY = "0M6W0U1IXexThi5idy8mnkqPKEq1LtEnlK/pZSn0cDrN" 270 246 271 247 data = {} 272 data["user"] = user 248 data["user"] = username 273 249 data["machine"] = machine.name 274 250 data["expires"] = time.time()+(5*60) … … 283 259 has_vnc = hasVnc(status) 284 260 285 d = dict(user=user ,261 d = dict(user=username, 286 262 on=status, 287 263 has_vnc=has_vnc, … … 342 318 return disk_fields 343 319 344 def command(user , fields):320 def command(username, state, fields): 345 321 """Handler for running commands like boot and delete on a VM.""" 346 322 back = fields.getfirst('back') 347 323 try: 348 d = controls.commandResult(user , fields)324 d = controls.commandResult(username, state, fields) 349 325 if d['command'] == 'Delete VM': 350 326 back = 'list' … … 352 328 if not back: 353 329 raise 354 #print >> sys.stderr, err330 print >> sys.stderr, err 355 331 result = err 356 332 else: … … 359 335 return templates.command(searchList=[d]) 360 336 if back == 'list': 361 g.clear() #Changed global state362 d = getListDict(user )337 state.clear() #Changed global state 338 d = getListDict(username) 363 339 d['result'] = result 364 340 return templates.list(searchList=[d]) 365 341 elif back == 'info': 366 machine = validation. testMachineId(user, fields.getfirst('machine_id'))342 machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine 367 343 return ({'Status': '302', 368 344 'Location': '/info?machine_id=%d' % machine.machine_id}, … … 371 347 raise InvalidInput('back', back, 'Not a known back page.') 372 348 373 def modifyDict(user , fields):349 def modifyDict(username, state, fields): 374 350 """Modify a machine as specified by CGI arguments. 375 351 … … 379 355 transaction = ctx.current.create_transaction() 380 356 try: 381 machine = validation.testMachineId(user, fields.getfirst('machine_id')) 382 owner = validation.testOwner(user, fields.getfirst('owner'), machine) 383 admin = validation.testAdmin(user, fields.getfirst('administrator'), 384 machine) 385 contact = validation.testContact(user, fields.getfirst('contact'), 386 machine) 387 name = validation.testName(user, fields.getfirst('name'), machine) 357 kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name memory vmtype disksize'.split()]) 358 validate = validation.Validate(username, state, **kws) 359 machine = validate.machine 360 print >> sys.stderr, machine, machine.administrator, kws['admin'] 388 361 oldname = machine.name 389 command = "modify" 390 391 memory = fields.getfirst('memory') 392 if memory is not None: 393 memory = validation.validMemory(owner, memory, machine, on=False) 394 machine.memory = memory 395 396 vm_type = validation.validVmType(fields.getfirst('vmtype')) 397 if vm_type is not None: 398 machine.type = vm_type 399 400 disksize = validation.testDisk(owner, fields.getfirst('disk')) 401 if disksize is not None: 402 disksize = validation.validDisk(owner, disksize, machine) 362 363 if hasattr(validate, 'memory'): 364 machine.memory = validate.memory 365 366 if hasattr(validate, 'vmtype'): 367 machine.type = validate.vmtype 368 369 if hasattr(validate, 'disksize'): 370 disksize = validate.disksize 403 371 disk = machine.disks[0] 404 372 if disk.size != disksize: … … 408 376 409 377 update_acl = False 410 if owner is not None andowner != machine.owner:411 machine.owner = owner378 if hasattr(validate, 'owner') and validate.owner != machine.owner: 379 machine.owner = validate.owner 412 380 update_acl = True 413 if name is not None:381 if hasattr(validate, 'name'): 414 382 machine.name = name 415 if admin is not None andadmin != machine.administrator:416 machine.administrator = admin383 if hasattr(validate, 'admin') and validate.admin != machine.administrator: 384 machine.administrator = validate.admin 417 385 update_acl = True 418 if contact is not None:419 machine.contact = contact386 if hasattr(validate, 'contact'): 387 machine.contact = validate.contact 420 388 421 389 ctx.current.save(machine) 422 390 if update_acl: 391 print >> sys.stderr, machine, machine.administrator 423 392 cache_acls.refreshMachine(machine) 424 393 transaction.commit() … … 428 397 for diskname in olddisk: 429 398 controls.resizeDisk(oldname, diskname, str(olddisk[diskname])) 430 if name is not None:431 controls.renameMachine(machine, oldname, name)432 return dict(user=user ,433 command= command,399 if hasattr(validate, 'name'): 400 controls.renameMachine(machine, oldname, validate.name) 401 return dict(user=username, 402 command="modify", 434 403 machine=machine) 435 404 436 def modify(user , fields):405 def modify(username, state, fields): 437 406 """Handler for modifying attributes of a machine.""" 438 407 try: 439 modify_dict = modifyDict(user , fields)408 modify_dict = modifyDict(username, state, fields) 440 409 except InvalidInput, err: 441 410 result = None 442 machine = validation. testMachineId(user, fields.getfirst('machine_id'))411 machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine 443 412 else: 444 413 machine = modify_dict['machine'] 445 414 result = 'Success!' 446 415 err = None 447 info_dict = infoDict(user , machine)416 info_dict = infoDict(username, machine) 448 417 info_dict['err'] = err 449 418 if err: … … 454 423 455 424 456 def helpHandler(user , fields):425 def helpHandler(username, state, fields): 457 426 """Handler for help messages.""" 458 427 simple = fields.getfirst('simple') … … 497 466 subjects = sorted(help_mapping.keys()) 498 467 499 d = dict(user=user ,468 d = dict(user=username, 500 469 simple=simple, 501 470 subjects=subjects, … … 509 478 raise CodeError("Unknown operation") 510 479 511 def infoDict(user , machine):480 def infoDict(username, machine): 512 481 """Get the variables used by info.tmpl.""" 513 482 status = controls.statusInfo(machine) … … 580 549 581 550 582 max_mem = validation.maxMemory(machine.owner, machine, False)551 max_mem = validation.maxMemory(machine.owner, state, machine, False) 583 552 checkpoint.checkpoint('Got mem') 584 553 max_disk = validation.maxDisk(machine.owner, machine) … … 589 558 defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) 590 559 checkpoint.checkpoint('Got defaults') 591 d = dict(user=user ,560 d = dict(user=username, 592 561 on=status is not None, 593 562 machine=machine, … … 602 571 return d 603 572 604 def info(user , fields):573 def info(username, state, fields): 605 574 """Handler for info on a single VM.""" 606 machine = validation. testMachineId(user, fields.getfirst('machine_id'))607 d = infoDict(user , machine)575 machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine 576 d = infoDict(username, machine) 608 577 checkpoint.checkpoint('Got infodict') 609 578 return templates.info(searchList=[d]) 610 579 611 def unauthFront(_, fields):580 def unauthFront(_, _2, fields): 612 581 """Information for unauth'd users.""" 613 582 return templates.unauth(searchList=[{'simple' : True}]) … … 629 598 630 599 631 def getUser( ):600 def getUser(environ): 632 601 """Return the current user based on the SSL environment variables""" 633 email = os.environ.get('SSL_CLIENT_S_DN_Email', None)602 email = environ.get('SSL_CLIENT_S_DN_Email', None) 634 603 if email is None: 635 604 return None 636 return email.split("@")[0] 637 638 def main(operation, user, fields): 605 if not email.endswith('@MIT.EDU'): 606 return None 607 return email[:-8] 608 609 def main(operation, username, state, fields): 639 610 start_time = time.time() 640 611 fun = mapping.get(operation, badOperation) … … 644 615 try: 645 616 checkpoint.checkpoint('Before') 646 output = fun(u , fields)617 output = fun(username, state, fields) 647 618 checkpoint.checkpoint('After') 648 619 … … 653 624 e = revertStandardError() 654 625 if e: 626 if isinstance(output, basestring): 627 sys.stderr = StringIO() 628 x = str(output) 629 print >> sys.stderr, x 630 print >> sys.stderr, 'XXX' 631 print >> sys.stderr, e 632 raise Exception() 655 633 output.addError(e) 656 634 printHeaders(headers) … … 659 637 print output_string 660 638 if fields.has_key('timedebug'): 661 print '<pre>%s</pre>' % c heckpoint639 print '<pre>%s</pre>' % cgi.escape(checkpoint) 662 640 except Exception, err: 663 641 if not fields.has_key('js'): … … 665 643 print 'Content-Type: text/html\n' 666 644 e = revertStandardError() 667 print error(operation, u, fields, err, e)645 print error(operation, state.username, fields, err, e) 668 646 sys.exit(1) 669 647 if isinstance(err, InvalidInput): 670 648 print 'Content-Type: text/html\n' 671 649 e = revertStandardError() 672 print invalidInput(operation, u, fields, err, e)650 print invalidInput(operation, state.username, fields, err, e) 673 651 sys.exit(1) 674 652 print 'Content-Type: text/plain\n' … … 690 668 logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.INFO) 691 669 692 u = getUser()693 g.user = u670 username = getUser(os.environ) 671 state.username = username 694 672 operation = os.environ.get('PATH_INFO', '') 695 673 if not operation: … … 697 675 print 'Location: ' + os.environ['SCRIPT_NAME']+'/\n' 698 676 sys.exit(0) 699 700 if u is None: 677 if username is None: 701 678 operation = 'unauth' 702 703 679 if operation.startswith('/'): 704 680 operation = operation[1:] … … 708 684 if os.getenv("SIPB_XEN_PROFILE"): 709 685 import profile 710 profile.run('main(operation, u , fields)', 'log-'+operation)711 else: 712 main(operation, u , fields)686 profile.run('main(operation, username, state, fields)', 'log-'+operation) 687 else: 688 main(operation, username, state, fields) -
trunk/packages/sipb-xen-www/code/templates/info.tmpl
r539 r572 78 78 $helppopup("Administrator")#slurp 79 79 #end filter 80 :</td><td><input type="text" name="admin istrator", value="$defaults.administrator"/></td></tr>80 :</td><td><input type="text" name="admin", value="$defaults.administrator"/></td></tr> 81 81 #filter None 82 82 $errorRow('administrator', $err) … … 107 107 $errorRow('memory', $err) 108 108 #end filter 109 <tr><td>Disk:</td><td><input type="text" size=3 name="disk " value="$defaults.disk"/>GiB (max $max_disk)</td><td>WARNING: Modifying disk size may corrupt your data.</td></tr>109 <tr><td>Disk:</td><td><input type="text" size=3 name="disksize" value="$defaults.disk"/>GiB (max $max_disk)</td><td>WARNING: Modifying disk size may corrupt your data.</td></tr> 110 110 #filter None 111 111 $errorRow('disk', $err) -
trunk/packages/sipb-xen-www/code/templates/list.tmpl
r559 r572 40 40 <tr> 41 41 <td>Disk</td> 42 <td><input type="text" name="disk " value="$defaults.disk" size=3/> GiB (${"%0.1f" % ($max_disk-0.05)} max)</td>42 <td><input type="text" name="disksize" value="$defaults.disk" size=3/> GiB (${"%0.1f" % ($max_disk-0.05)} max)</td> 43 43 </tr> 44 44 #filter None -
trunk/packages/sipb-xen-www/code/validation.py
r537 r572 6 6 import string 7 7 from sipb_xen_database import Machine, NIC, Type, Disk 8 from webcommon import InvalidInput , g8 from webcommon import InvalidInput 9 9 10 10 MAX_MEMORY_TOTAL = 512 … … 17 17 MAX_VMS_ACTIVE = 4 18 18 19 def getMachinesByOwner(user, machine=None): 19 class Validate: 20 def __init__(self, username, state, machine_id=None, name=None, owner=None, 21 admin=None, contact=None, memory=None, disksize=None, 22 vmtype=None, cdrom=None, clone_from=None): 23 # XXX Successive quota checks aren't a good idea, since you 24 # can't necessarily change the locker and disk size at the 25 # same time. 26 created_new = (machine_id is None) 27 28 if machine_id is not None: 29 self.machine = testMachineId(username, machine_id) 30 machine = getattr(self, 'machine', None) 31 32 owner = testOwner(username, owner, machine) 33 if owner is not None: 34 self.owner = owner 35 admin = testAdmin(username, admin, machine) 36 if admin is not None: 37 self.admin = admin 38 contact = testContact(username, contact, machine) 39 if contact is not None: 40 self.contact = contact 41 name = testName(username, name, machine) 42 if name is not None: 43 self.name = name 44 if memory is not None: 45 self.memory = validMemory(self.owner, state, memory, machine, 46 on=not created_new) 47 if disksize is not None: 48 self.disksize = validDisk(self.owner, disksize, machine) 49 if vmtype is not None: 50 self.vmtype = validVmType(vmtype) 51 if cdrom is not None: 52 if not CDROM.get(cdrom): 53 raise CodeError("Invalid cdrom type '%s'" % cdrom) 54 self.cdrom = cdrom 55 if clone_from is not None: 56 if clone_from not in ('ice3', ): 57 raise CodeError("Invalid clone image '%s'" % clone_from) 58 self.clone_from = clone_from 59 60 61 def getMachinesByOwner(owner, machine=None): 20 62 """Return the machines owned by the same as a machine. 21 63 … … 25 67 if machine: 26 68 owner = machine.owner 27 else:28 owner = user29 69 return Machine.select_by(owner=owner) 30 70 31 def maxMemory( user, machine=None, on=True):71 def maxMemory(owner, g, machine=None, on=True): 32 72 """Return the maximum memory for a machine or a user. 33 73 … … 44 84 if not on: 45 85 return MAX_MEMORY_SINGLE 46 machines = getMachinesByOwner( user, machine)86 machines = getMachinesByOwner(owner, machine) 47 87 active_machines = [x for x in machines if g.xmlist.get(x)] 48 88 mem_usage = sum([x.memory for x in active_machines if x != machine]) 49 89 return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage) 50 90 51 def maxDisk( user, machine=None):91 def maxDisk(owner, machine=None): 52 92 """Return the maximum disk that a machine can reach. 53 93 … … 60 100 machine_id = None 61 101 disk_usage = Disk.query().filter_by(Disk.c.machine_id != machine_id, 62 owner= user).sum(Disk.c.size) or 0102 owner=owner).sum(Disk.c.size) or 0 63 103 return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.) 64 104 65 def cantAddVm( user):66 machines = getMachinesByOwner( user)105 def cantAddVm(owner, g): 106 machines = getMachinesByOwner(owner) 67 107 active_machines = [x for x in machines if g.xmlist.get(x)] 68 108 if len(machines) >= MAX_VMS_TOTAL: … … 72 112 'To create more, turn one off.') 73 113 return False 74 75 def validAddVm(user):76 reason = cantAddVm(user)77 if reason:78 raise InvalidInput('create', True, reason)79 return True80 114 81 115 def haveAccess(user, machine): … … 99 133 return True 100 134 101 def validMemory( user, memory, machine=None, on=True):102 """Parse and validate limits for memory for a given user and machine.135 def validMemory(owner, g, memory, machine=None, on=True): 136 """Parse and validate limits for memory for a given owner and machine. 103 137 104 138 on is whether the memory must be valid after the machine is … … 112 146 raise InvalidInput('memory', memory, 113 147 "Minimum %s MiB" % MIN_MEMORY_SINGLE) 114 if memory > maxMemory(user, machine, on): 148 max_val = maxMemory(owner, g, machine, on) 149 if memory > max_val: 115 150 raise InvalidInput('memory', memory, 116 'Maximum %s MiB for %s' % (maxMemory(user, machine), 117 user)) 151 'Maximum %s MiB for %s' % (max_val, owner)) 118 152 return memory 119 153 120 def validDisk( user, disk, machine=None):121 """Parse and validate limits for disk for a given user and machine."""154 def validDisk(owner, disk, machine=None): 155 """Parse and validate limits for disk for a given owner and machine.""" 122 156 try: 123 157 disk = float(disk) 124 if disk > maxDisk( user, machine):158 if disk > maxDisk(owner, machine): 125 159 raise InvalidInput('disk', disk, 126 "Maximum %s G" % maxDisk( user, machine))160 "Maximum %s G" % maxDisk(owner, machine)) 127 161 disk = int(disk * 1024) 128 162 if disk < MIN_DISK_SINGLE * 1024: … … 191 225 If machine is None, this is the owner of a new machine. 192 226 """ 193 if owner == user or machine is not None and owner == machine.owner:227 if owner == user: 194 228 return owner 229 if machine is not None and owner in (machine.owner, None): 230 return None 195 231 if owner is None: 196 232 raise InvalidInput('owner', owner, "Owner must be specified") … … 214 250 215 251 def testName(user, name, machine=None): 216 if name in (None, machine.name): 252 if name is None: 253 return None 254 if machine is not None and name == machine.name: 217 255 return None 218 256 if not Machine.select_by(name=name): 257 if not validMachineName(name): 258 raise InvalidInput('name', name, 'You must provide a machine name. Max 22 chars, alnum plus \'-\' and \'_\'.') 219 259 return name 220 260 raise InvalidInput('name', name, "Name is already taken.") -
trunk/packages/sipb-xen-www/code/webcommon.py
r554 r572 37 37 return property(getter) 38 38 39 class Global(object):40 """ Global state of the system, to avoid duplicate remctls to get state"""39 class State(object): 40 """State for a request""" 41 41 def __init__(self, user): 42 self.user = user42 self.username = user 43 43 44 44 machines = cachedproperty(lambda self: 45 Machine.query().join('acl').select_by(user=self.user ))45 Machine.query().join('acl').select_by(user=self.username)) 46 46 xmlist_raw = cachedproperty(lambda self: controls.getList()) 47 47 xmlist = cachedproperty(lambda self: … … 56 56 delattr(self, attr) 57 57 58 g = Global(None)58 state = State(None)
Note: See TracChangeset
for help on using the changeset viewer.