Changeset 134 for trunk/web


Ignore:
Timestamp:
Oct 8, 2007, 2:17:26 AM (17 years ago)
Author:
ecprice
Message:

Moo!

Location:
trunk/web/templates
Files:
1 added
2 edited

Legend:

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

    r113 r134  
    1313<p>Odd... no error, but no machine.</p>
    1414#end if
     15<p><a href="list">Return</a></p>
    1516#end def
  • trunk/web/templates/main.py

    r133 r134  
    213213    return machine
    214214
    215 def create(user, fields):
    216     name = fields.getfirst('name')
    217     if not validMachineName(name):
    218         raise MyException("Invalid name '%s'" % name)
    219     name = user.username + '_' + name.lower()
    220 
    221     if Machine.get_by(name=name):
    222         raise MyException("A machine named '%s' already exists" % name)
    223    
    224     memory = fields.getfirst('memory')
     215def validMemory(user, memory, machine=None):
    225216    try:
    226217        memory = int(memory)
     
    229220    except ValueError:
    230221        raise MyException("Invalid memory amount")
    231     if memory > maxMemory(user):
     222    if memory > maxMemory(user, machine):
    232223        raise MyException("Too much memory requested")
    233    
    234     disk = fields.getfirst('disk')
     224    return memory
     225
     226def validDisk(user, disk, machine=None):
    235227    try:
    236228        disk = float(disk)
    237         if disk > maxDisk(user):
     229        if disk > maxDisk(user, machine):
    238230            raise MyException("Too much disk requested")
    239231        disk = int(disk * 1024)
     
    242234    except ValueError:
    243235        raise MyException("Invalid disk amount")
    244    
     236    return disk
     237
     238def create(user, fields):
     239    name = fields.getfirst('name')
     240    if not validMachineName(name):
     241        raise MyException("Invalid name '%s'" % name)
     242    name = user.username + '_' + name.lower()
     243
     244    if Machine.get_by(name=name):
     245        raise MyException("A machine named '%s' already exists" % name)
     246   
     247    memory = fields.getfirst('memory')
     248    memory = validMemory(user, memory)
     249   
     250    disk = fields.getfirst('disk')
     251    disk = validDisk(user, disk)
     252
    245253    vm_type = fields.getfirst('vmtype')
    246254    if vm_type not in ('hvm', 'paravm'):
Note: See TracChangeset for help on using the changeset viewer.