- Timestamp:
- Oct 10, 2007, 1:56:37 AM (17 years ago)
- Location:
- trunk/web/templates
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/templates/getafsgroups.py
r161 r177 29 29 checkAfsGroup(user, group) returns True if and only if user is in AFS group group in cell cell 30 30 """ 31 print user, group 32 p = subprocess.Popen(["pts", "membership", group, '-c', cell], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 33 p2 = subprocess.Popen(["grep", "-v", "^Members"], stdin=p.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 34 if p2.wait(): 31 p = subprocess.Popen(["pts", "membership", group, '-c', cell], 32 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 33 if p.wait(): 35 34 return False 36 for member in p2.stdout.read().split():37 if member== user:35 for line in p.stdout.readlines()[1:]: 36 if line.strip() == user: 38 37 return True 39 38 return False 40 39 41 def checkLockerOwner(user, locker ):40 def checkLockerOwner(user, locker, verbose=False): 42 41 """ 43 42 checkLockerOwner(user, locker) returns True if and only if user administers locker 44 43 """ 45 p = subprocess.Popen(["fs", "whichcell", "/mit/" + locker], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 46 if (p.wait()): 44 p = subprocess.Popen(["fs", "whichcell", "/mit/" + locker], 45 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 46 if p.wait(): 47 if verbose: 48 return p.stderr.read() 47 49 return False 48 50 cell = p.stdout.read().split()[-1][1:-1] 49 p = subprocess.Popen(["fs", "listacl", "/mit/" + locker], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 50 p2 = subprocess.Popen(["grep", "^ .* rlidwka$"], stdin=p.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 51 if (p2.wait()): 51 p = subprocess.Popen(["fs", "listacl", "/mit/" + locker], 52 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 53 if p.wait(): 54 if verbose: 55 return p.stderr.read() 52 56 return False 53 for line in p 2.stdout.read().split('\n'):57 for line in p.stdout.readlines()[1:]: 54 58 entry = line.split() 55 if entry == []or entry[0] == "Negative":59 if not entry or entry[0] == "Negative": 56 60 break 57 61 if entry[1] == "rlidwka": 58 if entry[0] == user or (entry[0][0:6] == "system" and checkAfsGroup(user, entry[0], cell)): 62 if entry[0] == user or (entry[0][0:6] == "system" and 63 checkAfsGroup(user, entry[0], cell)): 59 64 return True 65 if verbose: 66 return "You don't have admin bits on /mit/" + locker 60 67 return False 61 68 -
trunk/web/templates/info.tmpl
r166 r177 63 63 <input type="hidden" name="machine_id" value="$machine.machine_id"/> 64 64 <table> 65 <tr><td>Owner$ owner_help:</td><td><input type="text" name="owner", value="$machine.owner"/></td></tr>65 <tr><td>Owner${helppopup("owner")}:</td><td><input type="text" name="owner", value="$machine.owner"/></td></tr> 66 66 <tr><td>Contact email:</td><td><input type="text" name="contact" value="$machine.contact"/></td></tr> 67 67 #if $machine.nics -
trunk/web/templates/main.py
r176 r177 88 88 return Machine.select_by(owner=owner) 89 89 90 def maxMemory(user, machine=None ):90 def maxMemory(user, machine=None, on=True): 91 91 """Return the maximum memory for a machine or a user. 92 92 … … 94 94 machine. Else, return the maximum that machine can have. 95 95 96 on is a dictionary from machines to booleans, whether a machine is 97 on. If None, it is recomputed. XXX make this global? 98 """ 99 96 on is whether the machine should be turned on. If false, the max 97 memory for the machine to change to, if it is left off, is 98 returned. 99 """ 100 if not on: 101 return MAX_MEMORY_SINGLE 100 102 machines = getMachinesByOwner(user.username) 101 103 active_machines = [x for x in machines if g.uptimes[x]] … … 119 121 if user.username == 'moo': 120 122 return True 121 return getafsgroups.checkLockerOwner(user.username, machine.owner)123 return getafsgroups.checkLockerOwner(user.username, machine.owner) 122 124 123 125 def error(op, user, fields, err, emsg): … … 175 177 return p.stdout.read(), p.stderr.read() 176 178 if p.wait(): 177 raise CodeError('ERROR on remctl %s: %s' % 178 (args, p.stderr.read())) 179 print >> sys.stderr, 'Error on remctl %s:' % args 180 print >> sys.stderr, p.stderr.read() 181 raise CodeError('ERROR on remctl') 179 182 return p.stdout.read() 180 183 … … 320 323 return machine 321 324 322 def validMemory(user, memory, machine=None): 323 """Parse and validate limits for memory for a given user and machine.""" 325 def validMemory(user, memory, machine=None, on=True): 326 """Parse and validate limits for memory for a given user and machine. 327 328 on is whether the memory must be valid after the machine is 329 switched on. 330 """ 324 331 try: 325 332 memory = int(memory) … … 329 336 raise InvalidInput('memory', memory, 330 337 "Minimum %s MB" % MIN_MEMORY_SINGLE) 331 if memory > maxMemory(user, machine ):338 if memory > maxMemory(user, machine, on): 332 339 raise InvalidInput('memory', memory, 333 340 'Maximum %s MB' % maxMemory(user, machine)) … … 361 368 362 369 memory = fields.getfirst('memory') 363 memory = validMemory(user, memory )370 memory = validMemory(user, memory, on=True) 364 371 365 372 disk = fields.getfirst('disk') … … 566 573 567 574 def testOwner(user, owner, machine=None): 568 if not getafsgroups.checkLockerOwner(user.username, owner): 569 raise InvalidInput('owner', owner, 570 "Invalid") 571 return owner 575 if owner == machine.owner: #XXX What do we do when you lose access to the locker? 576 return owner 577 value = getafsgroups.checkLockerOwner(user.username, owner, verbose=True) 578 if value == True: 579 return owner 580 raise InvalidInput('owner', owner, value) 572 581 573 582 def testContact(user, contact, machine=None): 574 if contact != user.email: 575 raise InvalidInput('contact', contact, 576 "Invalid") 583 if not re.match("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", contact, re.I): 584 raise InvalidInput('contact', contact, "Not a valid email") 577 585 return contact 578 586 … … 581 589 582 590 def testName(user, name, machine=None): 583 if Machine.select_by(name=name) == []: 591 if name is None: 592 return None 593 if not Machine.select_by(name=name): 584 594 return name 585 595 if name == machine.name: 586 596 return name 587 raise InvalidInput('name', name, 588 "Already taken") 597 raise InvalidInput('name', name, "Already taken") 589 598 590 599 def testHostname(user, hostname, machine): … … 593 602 return hostname 594 603 # check if doesn't already exist 595 if NIC.select_by(hostname=hostname) == []: 596 return hostname 597 raise InvalidInput('hostname', hostname, 598 "Different from before") 599 604 if NIC.select_by(hostname=hostname): 605 raise InvalidInput('hostname', hostname, 606 "Already exists") 607 if not re.match("^[A-Z0-9-]{1,22}$", hostname, re.I): 608 raise InvalidInput('hostname', hostname, "Not a valid hostname; must only use number, letters, and dashes.") 609 return hostname 600 610 601 611 def modify(user, fields): 602 612 """Handler for modifying attributes of a machine.""" 603 #XXX not written yet 604 613 614 olddisk = {} 605 615 transaction = ctx.current.create_transaction() 606 616 try: … … 609 619 contact = testContact(user, fields.getfirst('contact')) 610 620 hostname = testHostname(owner, fields.getfirst('hostname'), 611 machine)621 machine) 612 622 name = testName(user, fields.getfirst('name'), machine) 613 623 oldname = machine.name 614 624 command="modify" 615 olddisk = {}616 625 617 626 memory = fields.getfirst('memory') 618 627 if memory is not None: 619 memory = validMemory(user, memory, machine) 620 else: 621 memory = machine.memory 622 if memory != machine.memory: 628 memory = validMemory(user, memory, machine, on=False) 623 629 machine.memory = memory 624 630 625 631 disksize = testDisk(user, fields.getfirst('disk')) 626 632 if disksize is not None: 627 633 disksize = validDisk(user, disksize, machine) 628 else: 629 disksize = machine.disks[0].size 630 for disk in machine.disks: 631 olddisk[disk.guest_device_name] = disk.size 632 disk.size = disksize 633 ctx.current.save(disk) 634 disk = machine.disks[0] 635 if disk.size != disksize: 636 olddisk[disk.guest_device_name] = disksize 637 disk.size = disksize 638 ctx.current.save(disk) 634 639 635 # XXX all NICs get samehostname on change? Interface doesn't support more.636 for nic in machine.nics :640 # XXX first NIC gets hostname on change? Interface doesn't support more. 641 for nic in machine.nics[:1]: 637 642 nic.hostname = hostname 638 643 ctx.current.save(nic) 639 644 640 if owner != machine.owner:645 if owner is not None and owner != machine.owner: 641 646 machine.owner = owner 642 if name != machine.name:647 if name is not None and name != machine.name: 643 648 machine.name = name 644 649 … … 648 653 transaction.rollback() 649 654 raise 650 remctl("web", "moveregister", oldname, name)651 for disk in machine.disks:652 # XXX all disks get the same size on change? Interface doesn't support more.653 if disk.size != olddisk[disk.guest_device_name]:654 remctl("web", "lvresize", oldname, disk.guest_device_name, str(disk.size))655 if oldname != name:656 remctl("web", "lvrename", oldname, disk.guest_device_name, name)655 for diskname in olddisk: 656 remctl("web", "lvresize", oldname, diskname, str(olddisk[diskname])) 657 if name is not None and name != oldname: 658 for disk in machine.disks: 659 if oldname != name: 660 remctl("web", "lvrename", oldname, disk.guest_device_name, name) 661 remctl("web", "moveregister", oldname, name) 657 662 d = dict(user=user, 658 663 command=command, … … 815 820 sys.stderr.seek(0) 816 821 e = sys.stderr.read() 822 sys.stderr=sys.stdout 817 823 if e: 818 824 output = str(output)
Note: See TracChangeset
for help on using the changeset viewer.