Ignore:
Timestamp:
Jun 2, 2008, 11:25:47 PM (16 years ago)
Author:
ecprice
Message:

Put validation behind more abstraction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-www/code/controls.py

    r563 r572  
    9393                        % (err, machine.name, cdtype))
    9494
    95 def createVm(owner, contact, name, memory, disk_size, machine_type, cdrom, clone_from):
     95def createVm(username, state, owner, contact, name, memory, disksize, machine_type, cdrom, clone_from):
    9696    """Create a VM and put it in the database"""
    9797    # put stuff in the table
    9898    transaction = ctx.current.create_transaction()
    9999    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.)
    103101        res = meta.engine.execute('select nextval('
    104102                                  '\'"machines_machine_id_seq"\')')
     
    116114        ctx.current.save(machine)
    117115        disk = Disk(machine_id=machine.machine_id,
    118                     guest_device_name='hda', size=disk_size)
     116                    guest_device_name='hda', size=disksize)
    119117        open_nics = NIC.select_by(machine_id=None)
    120118        if not open_nics: #No IPs left!
     
    141139    """Return a dictionary mapping machine names to dicts."""
    142140    value_string = remctl('web', 'listvms')
    143     value_dict = yaml.load(value_string, yaml.CSafeLoader)
     141    value_dict = yaml.load(value_string, yaml.SafeLoader)
    144142    return value_dict
    145143
     
    209207        remctl('web', 'lvremove', mname, dname)
    210208
    211 def commandResult(user, fields):
     209def commandResult(username, state, fields):
    212210    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
    214212    action = fields.getfirst('action')
    215213    cdrom = fields.getfirst('cdrom')
     
    236234               
    237235    elif action == 'Power on':
    238         if validation.maxMemory(user, machine) < machine.memory:
     236        if validation.maxMemory(username, state, machine) < machine.memory:
    239237            raise InvalidInput('action', 'Power on',
    240238                               "You don't have enough free RAM quota "
     
    264262        deleteVM(machine)
    265263
    266     d = dict(user=user,
     264    d = dict(user=username,
    267265             command=action,
    268266             machine=machine)
Note: See TracChangeset for help on using the changeset viewer.