Changeset 144 for trunk/web/templates


Ignore:
Timestamp:
Oct 8, 2007, 4:44:14 AM (17 years ago)
Author:
ecprice
Message:

More updates.

Location:
trunk/web/templates
Files:
1 deleted
4 edited

Legend:

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

    r134 r144  
    88
    99#def body
    10 <h1>Command succesful</h1>
     10<h1>Command successful</h1>
    1111<p>$command ${machine.name} was successful.</p>
    12 #if $command == "Delete VM"
     12#if $command == "Delete VM" or True
    1313<p><a href="list">Return</a></p>
    1414#else
  • trunk/web/templates/info.tmpl

    r135 r144  
    6969#end if
    7070#if not $on
    71     <tr><td>Ram:</td><td><input type="text" size=3 value="$machine.memory"/>MB (max $maxmem)</td></tr>
    72     <tr><td>Disk:</td><td><input type="text" size=3 value="${machine.disks[0].size/1024.}"/>GB (max $maxdisk)</td></tr>
     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></tr>
    7373#end if
    7474    <tr><td><input type="submit" class="button" name="action" value="Change"/></td></tr>
  • trunk/web/templates/list.tmpl

    r139 r144  
    2121        <td>Uptime</td>
    2222        <td>VNC</td>
    23         <td>Restart?</td>
     23        <td></td>
    2424      #for $machine in $machines:
    2525      <tr>
     
    3838#end if
    3939<td>#slurp
    40 #if $uptimes.get($machine.name)
    41 $uptimes[$machine.name]#slurp
     40#if $uptimes[$machine]
     41$uptimes[$machine]#slurp
    4242#else
    4343Off#slurp
     
    4545</td>
    4646        <td>#slurp
    47 #if $has_vnc.get($machine.name) == True
     47#if $has_vnc[$machine] == True
    4848<a href="vnc?machine_id=$machine.machine_id">Console</a>#slurp
    4949#else
    50 $has_vnc.get($machine.name)
     50$has_vnc[$machine]
    5151#end if
    5252</td>
     
    5555            <input type="hidden" name="machine_id"
    5656                   value="$machine.machine_id"/>
    57             <input type="submit" class="button"
    58                    value="Reboot"/>
     57#if $uptimes[$machine]
     58            <input type="submit" class="button" name="action" value="Shutdown"/>
     59#else
     60            <input type="submit" class="button" name="action" value="Power on"/>
     61#end if
    5962          </form>
    6063        </td>
     
    6366    </table>
    6467#end if
    65 
     68#if $can_add_vm
    6669    <p>Create a new VM:</p>
    6770    <form action="create" method="POST">
     
    7376        <tr>
    7477          <td>Memory</td>
    75           <td><input type="text" name="memory" value="$maxmem" size=3/> megabytes ($maxmem max)</td>
     78          <td><input type="text" name="memory" value="$default_mem" size=3/> megabytes ($max_mem max)</td>
    7679        </tr>
    7780        <tr>
    7881          <td>Disk</td>
    79           <td><input type="text" name="disk" value="$maxdisk" size=3/> gigabytes ($maxdisk max)</td>
     82          <td><input type="text" name="disk" value="$default_disk" size=3/> gigabytes (${"%0.1f" % ($max_disk-0.05)} max)</td>
    8083        </tr>
    8184        <tr>
     
    102105      <input type="submit" class="button" value="Create it!"/>
    103106    </form>
    104 
     107#else
     108<p>You are at the maximum number of VMs.</p>
     109#end if
    105110#end def
  • trunk/web/templates/main.py

    r140 r144  
    4242                     "%02x" * 6]) % tuple(u)
    4343
    44 def maxMemory(user, machine=None):
    45     return 256
     44MAX_MEMORY_TOTAL = 512
     45MAX_MEMORY_SINGLE = 256
     46MIN_MEMORY_SINGLE = 16
     47MAX_DISK_TOTAL = 50
     48MAX_DISK_SINGLE = 50
     49MIN_DISK_SINGLE = 0.1
     50MAX_VMS_TOTAL = 10
     51MAX_VMS_ACTIVE = 4
     52
     53def getMachinesOwner(owner):
     54    return Machine.select_by(owner=owner)
     55
     56def maxMemory(user, machine=None, on=None):
     57    machines = getMachinesOwner(user.username)
     58    if on is None:
     59        on = getUptimes(machines)
     60    active_machines = [x for x in machines if on[x]]
     61    mem_usage = sum([x.memory for x in active_machines if x != machine])
     62    return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage)
    4663
    4764def maxDisk(user, machine=None):
    48     return 10.0
     65    machines = getMachinesOwner(user.username)
     66    disk_usage = sum([sum([y.size for y in x.disks])
     67                      for x in machines if x != machine])
     68    return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.)
     69
     70def canAddVm(user, on=None):
     71    machines = getMachinesOwner(user.username)
     72    if on is None:
     73        on = getUptimes(machines)
     74    active_machines = [x for x in machines if on[x]]
     75    return (len(machines) < MAX_VMS_TOTAL and
     76            len(active_machines) < MAX_VMS_ACTIVE)
    4977
    5078def haveAccess(user, machine):
     
    95123                         stderr=subprocess.PIPE)
    96124    if kws.get('err'):
     125        p.wait()
    97126        return p.stdout.read(), p.stderr.read()
    98127    if p.wait():
    99         print >> sys.stderr, 'ERROR on remctl ', args
    100         print >> sys.stderr, p.stderr.read()
     128        raise MyException('ERROR on remctl %s: %s' %
     129                          (args, p.stderr.read()))
    101130    return p.stdout.read()
    102131
     
    159188        uptime = ' '.join(lst[2:])
    160189        d[name] = uptime
    161     return d
     190    ans = {}
     191    for m in machines:
     192        ans[m] = d.get(m.name)
     193    return ans
    162194
    163195def statusInfo(machine):
     
    191223    transaction = ctx.current.create_transaction()
    192224    try:
     225        if memory > maxMemory(user):
     226            raise MyException("Too much memory requested")
     227        if disk > maxDisk(user) * 1024:
     228            raise MyException("Too much disk requested")
     229        if not canAddVm(user):
     230            raise MyException("Too many VMs requested")
    193231        res = meta.engine.execute('select nextval(\'"machines_machine_id_seq"\')')
    194232        id = res.fetchone()[0]
     
    218256        transaction.rollback()
    219257        raise
     258    registerMachine(machine)
    220259    makeDisks()
    221     registerMachine(machine)
    222260    # tell it to boot with cdrom
    223261    bootMachine(machine, cdrom)
     
    228266    try:
    229267        memory = int(memory)
    230         if memory <= 0:
     268        if memory < MIN_MEMORY_SINGLE:
    231269            raise ValueError
    232270    except ValueError:
    233         raise MyException("Invalid memory amount")
     271        raise MyException("Invalid memory amount; must be at least %s MB" %
     272                          MIN_MEMORY_SINGLE)
    234273    if memory > maxMemory(user, machine):
    235274        raise MyException("Too much memory requested")
     
    242281            raise MyException("Too much disk requested")
    243282        disk = int(disk * 1024)
    244         if disk <= 0:
     283        if disk < MIN_DISK_SINGLE * 1024:
    245284            raise ValueError
    246285    except ValueError:
    247         raise MyException("Invalid disk amount")
     286        raise MyException("Invalid disk amount; minimum is %s GB" %
     287                          MIN_DISK_SINGLE)
    248288    return disk
    249289
     
    287327    on = uptimes
    288328    for m in machines:
    289         if not on.get(m.name):
    290             has_vnc[m.name] = 'Off'
     329        if not on[m]:
     330            has_vnc[m] = 'Off'
    291331        elif m.type.hvm:
    292             has_vnc[m.name] = True
     332            has_vnc[m] = True
    293333        else:
    294             has_vnc[m.name] = "ParaVM"+helppopup("paravm_console")
     334            has_vnc[m] = "ParaVM"+helppopup("paravm_console")
    295335    #     for m in machines:
    296336    #         status = statusInfo(m)
    297337    #         on[m.name] = status is not None
    298338    #         has_vnc[m.name] = hasVnc(status)
     339    max_mem=maxMemory(user, on=on)
     340    max_disk=maxDisk(user)
    299341    d = dict(user=user,
    300              maxmem=maxMemory(user),
    301              maxdisk=maxDisk(user),
     342             can_add_vm=canAddVm(user, on=on),
     343             max_mem=max_mem,
     344             max_disk=max_disk,
     345             default_mem=max_mem,
     346             default_disk=min(4.0, max_disk),
    302347             machines=machines,
    303348             has_vnc=has_vnc,
     
    418463            remctl('reboot', machine.name)
    419464    elif action == 'Power on':
     465        if maxMemory(user) < machine.memory:
     466            raise MyException("You don't have enough free RAM quota")
    420467        bootMachine(machine, cdrom)
    421468    elif action == 'Power off':
     
    515562            pass
    516563            #fields.append((disp, None))
    517 
     564    max_mem = maxMemory(user, machine)
     565    max_disk = maxDisk(user, machine)
    518566    d = dict(user=user,
    519567             cdroms=CDROM.select(),
     
    523571             uptime=str(uptime),
    524572             ram=machine.memory,
    525              maxmem=maxMemory(user, machine),
    526              maxdisk=maxDisk(user, machine),
     573             max_mem=max_mem,
     574             max_disk=max_disk,
    527575             fields = fields)
    528576    print Template(file='info.tmpl',
     
    549597        u.email = os.environ[ 'SSL_CLIENT_S_DN_Email']
    550598    else:
    551         u.username = 'nobody'
    552         u.email = None
     599        u.username = 'moo'
     600        u.email = 'nobody'
    553601    connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
    554602    operation = os.environ.get('PATH_INFO', '')
Note: See TracChangeset for help on using the changeset viewer.