Changeset 187


Ignore:
Timestamp:
Oct 11, 2007, 1:55:29 AM (17 years ago)
Author:
ecprice
Message:

Help, admin, links at the top.

Location:
trunk/web/templates
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/templates/help.tmpl

    r139 r187  
    33
    44#def title
     5#if len($subjects) == 1
     6Help on $subjects[0]
     7#else
    58Help
     9#end if
    610#end def
    711
     
    1014#if not $simple
    1115<h1>Help</h1>
     16<p>Topics:
     17#for $key in sorted($mapping)
     18<a href="help?subject=$key">$key</a>
     19#end for
     20</p>
    1221#end if
    1322#for $subject in $subjects
     23#if $subject in $mapping
     24#if not $simple
     25<h2>$subject</h2>
     26#end if
    1427<p>$mapping[$subject]</p>
     28#else
     29<p>Unknown subject '$subject'.</p>
     30#end if
    1531#end for
     32#if $simple
     33<a href="javascript:window.close();">Close</a>
     34#end if
    1635#end def
  • trunk/web/templates/info.tmpl

    r177 r187  
    6464  <table>
    6565    <tr><td>Owner${helppopup("owner")}:</td><td><input type="text" name="owner", value="$machine.owner"/></td></tr>
     66    <tr><td>Administrator${helppopup("administrator")}:</td><td><input type="text" name="administrator", value="$machine.administrator"/></td></tr>
    6667    <tr><td>Contact email:</td><td><input type="text" name="contact" value="$machine.contact"/></td></tr>
    6768#if $machine.nics
  • trunk/web/templates/main.py

    r182 r187  
    1616import getafsgroups
    1717
    18 sys.stderr = StringIO.StringIO()
     18errio = StringIO.StringIO()
     19sys.stderr = errio
    1920sys.path.append('/home/ecprice/.local/lib/python2.5/site-packages')
    2021
     
    8485MAX_VMS_ACTIVE = 4
    8586
    86 def getMachinesByOwner(owner):
    87     """Return the machines owned by a given owner."""
     87def getMachinesByOwner(user, machine=None):
     88    """Return the machines owned by the same as a machine.
     89   
     90    If the machine is None, return the machines owned by the same
     91    user.
     92    """
     93    if machine:
     94        owner = machine.owner
     95    else:
     96        owner = user.username
    8897    return Machine.select_by(owner=owner)
    8998
     
    100109    if not on:
    101110        return MAX_MEMORY_SINGLE
    102     machines = getMachinesByOwner(user.username)
     111    machines = getMachinesByOwner(user, machine)
    103112    active_machines = [x for x in machines if g.uptimes[x]]
    104113    mem_usage = sum([x.memory for x in active_machines if x != machine])
     
    106115
    107116def maxDisk(user, machine=None):
    108     machines = getMachinesByOwner(user.username)
     117    machines = getMachinesByOwner(user, machine)
    109118    disk_usage = sum([sum([y.size for y in x.disks])
    110119                      for x in machines if x != machine])
     
    112121
    113122def canAddVm(user):
    114     machines = getMachinesByOwner(user.username)
     123    machines = getMachinesByOwner(user)
    115124    active_machines = [x for x in machines if g.uptimes[x]]
    116125    return (len(machines) < MAX_VMS_TOTAL and
     
    118127
    119128def haveAccess(user, machine):
    120     """Return whether a user has access to a machine"""
     129    """Return whether a user has adminstrative access to a machine"""
     130    if user.username == 'moo':
     131        return True
     132    if user.username in (machine.administrator, machine.owner):
     133        return True
     134    if checkAfsGroup(user, machine.administrator, 'athena.mit.edu'): #XXX Cell?
     135        return True
     136    return owns(user, machine)
     137
     138def owns(user, machine):
     139    """Return whether a user owns a machine"""
    121140    if user.username == 'moo':
    122141        return True
     
    573592    return Template(file="command.tmpl", searchList=[d, global_dict])
    574593
    575 def testOwner(user, owner, machine=None):
    576     if owner == machine.owner:   #XXX What do we do when you lose access to the locker?
    577         return owner
     594def testAdmin(user, admin, machine):
     595    if admin in (None, machine.administrator):
     596        return None
     597    if admin == user.username:
     598        return admin
     599    if getafsgroups.checkAfsGroup(user, admin, 'athena.mit.edu'):
     600        return admin
     601    if getafsgroups.checkAfsGroup(user, 'system:'+admin, 'athena.mit.edu'):
     602        return 'system:'+admin
     603    raise InvalidInput('admin', admin,
     604                       'You must control the group you move it to')
     605   
     606def testOwner(user, owner, machine):
     607    if owner in (None, machine.owner):
     608        return None
     609    #XXX should you be able to transfer ownership if you don't already own it?
     610    #if not owns(user, machine):
     611    #    raise InvalidInput('owner', owner, "You don't own this machine, so you can't  transfer ownership")
    578612    value = getafsgroups.checkLockerOwner(user.username, owner, verbose=True)
    579613    if value == True:
     
    582616
    583617def testContact(user, contact, machine=None):
     618    if contact in (None, machine.contact):
     619        return None
    584620    if not re.match("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", contact, re.I):
    585621        raise InvalidInput('contact', contact, "Not a valid email")
     
    590626
    591627def testName(user, name, machine=None):
    592     if name is None:
     628    if name in (None, machine.name):
    593629        return None
    594630    if not Machine.select_by(name=name):
    595         return name
    596     if name == machine.name:
    597631        return name
    598632    raise InvalidInput('name', name, "Already taken")
     
    618652        machine = testMachineId(user, fields.getfirst('machine_id'))
    619653        owner = testOwner(user, fields.getfirst('owner'), machine)
    620         contact = testContact(user, fields.getfirst('contact'))
    621         hostname = testHostname(owner, fields.getfirst('hostname'),
    622                                 machine)
     654        admin = testAdmin(user, fields.getfirst('administrator'), machine)
     655        contact = testContact(user, fields.getfirst('contact'), machine)
     656        hostname = testHostname(owner, fields.getfirst('hostname'), machine)
    623657        name = testName(user, fields.getfirst('name'), machine)
    624658        oldname = machine.name
     
    644678            ctx.current.save(nic)
    645679
    646         if owner is not None and owner != machine.owner:
     680        if owner is not None:
    647681            machine.owner = owner
    648         if name is not None and name != machine.name:
     682        if name is not None:
    649683            machine.name = name
     684        if admin is not None:
     685            machine.administrator = admin
     686        if contact is not None:
     687            machine.contact = contact
    650688           
    651689        ctx.current.save(machine)
     
    656694    for diskname in olddisk:
    657695        remctl("web", "lvresize", oldname, diskname, str(olddisk[diskname]))
    658     if name is not None and name != oldname:
     696    if name is not None:
    659697        for disk in machine.disks:
    660             if oldname != name:
    661                 remctl("web", "lvrename", oldname, disk.guest_device_name, name)
     698            remctl("web", "lvrename", oldname, disk.guest_device_name, name)
    662699        remctl("web", "moveregister", oldname, name)
    663700    d = dict(user=user,
     
    681718want an HVM virtualized machine.""",
    682719                   cpu_weight="""Don't ask us!  We're as mystified as you are.""",
    683                    owner="""The Owner must be the name of a locker that you are an AFS
    684 administrator of.  In particular, you or an AFS group you are a member
    685 of must have AFS rlidwka bits on the locker.  You can check see who
    686 administers the LOCKER locker using the command 'fs la /mit/LOCKER' on
    687 Athena.)""")
    688    
     720                   owner="""The owner field is used to determine <a href="help?subject=quotas">quotas</a>.  It must be the name
     721of a locker that you are an AFS administrator of.  In particular, you
     722or an AFS group you are a member of must have AFS rlidwka bits on the
     723locker.  You can check see who administers the LOCKER locker using the
     724command 'fs la /mit/LOCKER' on Athena.)  See also <a href="help?subject=administrator">administrator</a>.""",
     725                   administrator="""The administrator field determines who can access the console and power on and off the machine.  This can be either a user or a moira group.""",
     726                   quotas="""Quotas are determined on a per-locker basis.  Each
     727quota may have a maximum of 512 megabytes of active ram, 50 gigabytes of disk, and 4 active machines."""
     728
     729                   )
     730   
     731    if not subjects:
     732        subjects = sorted(mapping.keys())
     733       
    689734    d = dict(user=user,
    690735             simple=simple,
     
    715760    display_fields = [('name', 'Name'),
    716761                      ('owner', 'Owner'),
     762                      ('administrator', 'Administrator'),
    717763                      ('contact', 'Contact'),
    718764                      ('type', 'Type'),
     
    736782    machine_info['type'] = machine.type.hvm and 'HVM' or 'ParaVM'
    737783    machine_info['owner'] = machine.owner
     784    machine_info['administrator'] = machine.administrator
    738785    machine_info['contact'] = machine.contact
    739786
     
    817864        output = fun(u, fields)
    818865        print 'Content-Type: text/html\n'
    819         sys.stderr.seek(0)
    820         e = sys.stderr.read()
    821866        sys.stderr=sys.stdout
     867        errio.seek(0)
     868        e = errio.read()
    822869        if e:
    823870            output = str(output)
     
    826873    except CodeError, err:
    827874        print 'Content-Type: text/html\n'
    828         sys.stderr.seek(0)
    829         e = sys.stderr.read()
    830875        sys.stderr=sys.stdout
     876        errio.seek(0)
     877        e = errio.read()
    831878        print error(operation, u, fields, err, e)
    832879    except InvalidInput, err:
    833880        print 'Content-Type: text/html\n'
    834         sys.stderr.seek(0)
    835         e = sys.stderr.read()
    836881        sys.stderr=sys.stdout
     882        errio.seek(0)
     883        e = errio.read()
    837884        print invalidInput(operation, u, fields, err, e)
    838885    except:
    839886        print 'Content-Type: text/plain\n'
    840         sys.stderr.seek(0)
    841         e = sys.stderr.read()
     887        sys.stderr=sys.stdout
     888        errio.seek(0)
     889        e = errio.read()
    842890        print e
    843891        print '----'
    844         sys.stderr = sys.stdout
    845892        raise
  • trunk/web/templates/skeleton.py

    r184 r187  
    3434__CHEETAH_version__ = '2.0rc8'
    3535__CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 8)
    36 __CHEETAH_genTime__ = 1192025116.0694621
    37 __CHEETAH_genTimestamp__ = 'Wed Oct 10 10:05:16 2007'
     36__CHEETAH_genTime__ = 1192082083.444865
     37__CHEETAH_genTimestamp__ = 'Thu Oct 11 01:54:43 2007'
    3838__CHEETAH_src__ = 'skeleton.tmpl'
    39 __CHEETAH_srcLastModified__ = 'Wed Oct 10 10:04:55 2007'
     39__CHEETAH_srcLastModified__ = 'Thu Oct 11 01:54:41 2007'
    4040__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'
    4141
     
    117117            if _v is not None: write(_filter(_v, rawExpr='$user.username')) # from line 26, col 26.
    118118            write('''.]</p>
     119<p><a href="list">List</a>
    119120''')
    120         _v = VFFSL(SL,"body",True) # '$body' on line 28, col 1
    121         if _v is not None: write(_filter(_v, rawExpr='$body')) # from line 28, col 1.
     121            if VFFSL(SL,"varExists",False)('machine'): # generated from line 28, col 1
     122                write('''<a href="info?machine_id=''')
     123                _v = VFFSL(SL,"machine.machine_id",True) # '$machine.machine_id' on line 29, col 26
     124                if _v is not None: write(_filter(_v, rawExpr='$machine.machine_id')) # from line 29, col 26.
     125                write('''">Info</a>
     126<a href="vnc?machine_id=''')
     127                _v = VFFSL(SL,"machine.machine_id",True) # '$machine.machine_id' on line 30, col 25
     128                if _v is not None: write(_filter(_v, rawExpr='$machine.machine_id')) # from line 30, col 25.
     129                write('''">Console</a>
     130''')
     131            write('''<a href="help">Help</a></p>
     132''')
     133        _v = VFFSL(SL,"body",True) # '$body' on line 34, col 1
     134        if _v is not None: write(_filter(_v, rawExpr='$body')) # from line 34, col 1.
    122135        write('''
    123136''')
    124         if not VFFSL(SL,"varExists",False)('simple') or not VFFSL(SL,"simple",True): # generated from line 29, col 1
     137        if not VFFSL(SL,"varExists",False)('simple') or not VFFSL(SL,"simple",True): # generated from line 35, col 1
    125138            write('''<hr />
    126139Questions? Contact <a href="mailto:sipb-xen-dev@mit.edu">sipb-xen-dev@mit.edu</a>.
  • trunk/web/templates/skeleton.tmpl

    r184 r187  
    2525#if not $varExists('simple') or not $simple
    2626<p>[You are logged in as $user.username.]</p>
     27<p><a href="list">List</a>
     28#if $varExists('machine')
     29<a href="info?machine_id=$machine.machine_id">Info</a>
     30<a href="vnc?machine_id=$machine.machine_id">Console</a>
     31#end if
     32<a href="help">Help</a></p>
    2733#end if
    2834$body
Note: See TracChangeset for help on using the changeset viewer.