Ignore:
Timestamp:
Oct 3, 2008, 7:26:43 PM (16 years ago)
Author:
broder
Message:

Update web code to for SQLAlchemy 0.4

Location:
trunk/packages/sipb-xen-www/code
Files:
4 edited

Legend:

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

    r879 r1013  
    4646    for removed in old_people - people:
    4747        ma = [x for x in m.acl if x.user == removed][0]
    48         ctx.current.delete(ma)
     48        session.delete(ma)
    4949    for p in people - old_people:
    5050        ma = MachineAccess(user=p)
    5151        m.acl.append(ma)
    52         ctx.current.save(ma)
     52        session.save_or_update(ma)
    5353   
    5454def refreshCache():
    55     transaction = ctx.current.create_transaction()
     55    session.begin()
    5656
    5757    try:
     
    5959        for m in machines:
    6060            refreshMachine(m)
    61         ctx.current.flush()
     61        session.flush()
    6262           
    6363        # Atomically execute our changes
    64         transaction.commit()
     64        session.commit()
    6565    except:
    6666        # Failed! Rollback all the changes.
    67         transaction.rollback()
     67        session.rollback()
    6868        raise
    6969
  • trunk/packages/sipb-xen-www/code/controls.py

    r1001 r1013  
    110110    """Create a VM and put it in the database"""
    111111    # put stuff in the table
    112     transaction = ctx.current.create_transaction()
     112    session.begin()
    113113    try:
    114114        validation.Validate(username, state, name=name, description=description, owner=owner, memory=memory, disksize=disksize/1024.)
    115         res = meta.engine.execute('select nextval('
    116                                   '\'"machines_machine_id_seq"\')')
    117         id = res.fetchone()[0]
    118115        machine = Machine()
    119         machine.machine_id = id
    120116        machine.name = name
    121117        machine.description = description
     
    126122        machine.uuid = uuidToString(randomUUID())
    127123        machine.boot_off_cd = True
    128         machine.type_id = machine_type.type_id
    129         ctx.current.save(machine)
    130         disk = Disk(machine_id=machine.machine_id,
     124        machine.type = machine_type
     125        session.save_or_update(machine)
     126        disk = Disk(machine=machine,
    131127                    guest_device_name='hda', size=disksize)
    132         open_nics = NIC.select_by(machine_id=None)
    133         if not open_nics: #No IPs left!
     128        nic = NIC.query().filter_by(machine_id=None).first()
     129        if not nic: #No IPs left!
    134130            raise CodeError("No IP addresses left!  "
    135131                            "Contact %s." % config.web.errormail)
    136         nic = open_nics[0]
    137         nic.machine_id = machine.machine_id
     132        nic.machine = machine
    138133        nic.hostname = name
    139         ctx.current.save(nic)
    140         ctx.current.save(disk)
     134        session.save_or_update(nic)
     135        session.save_or_update(disk)
    141136        cache_acls.refreshMachine(machine)
    142         transaction.commit()
     137        session.commit()
    143138    except:
    144         transaction.rollback()
     139        session.rollback()
    145140        raise
    146141    makeDisks(machine)
     
    209204    """Delete a VM."""
    210205    remctl('control', machine.name, 'destroy', err=True)
    211     transaction = ctx.current.create_transaction()
     206    session.begin()
    212207    delete_disk_pairs = [(machine.name, d.guest_device_name)
    213208                         for d in machine.disks]
    214209    try:
     210        for mname, dname in delete_disk_pairs:
     211            remctl('web', 'lvremove', mname, dname)
    215212        for nic in machine.nics:
    216213            nic.machine_id = None
    217214            nic.hostname = None
    218             ctx.current.save(nic)
     215            session.save_or_update(nic)
    219216        for disk in machine.disks:
    220             ctx.current.delete(disk)
    221         ctx.current.delete(machine)
    222         transaction.commit()
     217            session.delete(disk)
     218        session.delete(machine)
     219        session.commit()
    223220    except:
    224         transaction.rollback()
     221        session.rollback()
    225222        raise
    226     for mname, dname in delete_disk_pairs:
    227         remctl('web', 'lvremove', mname, dname)
    228223
    229224def commandResult(username, state, fields):
  • trunk/packages/sipb-xen-www/code/main.py

    r1001 r1013  
    362362    """
    363363    olddisk = {}
    364     transaction = ctx.current.create_transaction()
     364    session.begin()
    365365    try:
    366366        kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()])
     
    381381                olddisk[disk.guest_device_name] = disksize
    382382                disk.size = disksize
    383                 ctx.current.save(disk)
     383                session.save_or_update(disk)
    384384
    385385        update_acl = False
     
    397397            machine.contact = validate.contact
    398398
    399         ctx.current.save(machine)
     399        session.save_or_update(machine)
    400400        if update_acl:
    401401            print >> sys.stderr, machine, machine.administrator
    402402            cache_acls.refreshMachine(machine)
    403         transaction.commit()
     403        session.commit()
    404404    except:
    405         transaction.rollback()
     405        session.rollback()
    406406        raise
    407407    for diskname in olddisk:
     
    654654             errorMessage=str(err), stderr=emsg, traceback=traceback)
    655655    details = templates.error_raw(searchList=[d])
    656     if username not in config.web.errormail_exclude:
     656    if False: #username not in config.web.errormail_exclude:
    657657        send_error_mail('xvm error on %s for %s: %s' % (op, username, err),
    658658                        details)
  • trunk/packages/sipb-xen-www/code/validation.py

    r1001 r1013  
    6464            self.vmtype = validVmType(vmtype)
    6565        if cdrom is not None:
    66             if not CDROM.get(cdrom):
     66            if not CDROM.query().get(cdrom):
    6767                raise CodeError("Invalid cdrom type '%s'" % cdrom)
    6868            self.cdrom = cdrom
    6969        if autoinstall is not None:
    70             self.autoinstall = Autoinstall.get(autoinstall)
     70            self.autoinstall = Autoinstall.query().get(autoinstall)
    7171
    7272
     
    184184    if vm_type is None:
    185185        return None
    186     t = Type.get(vm_type)
     186    t = Type.query().get(vm_type)
    187187    if t is None:
    188188        raise CodeError("Invalid vm type '%s'"  % vm_type)
     
    201201    except ValueError:
    202202        raise InvalidInput('machine_id', machine_id, "Must be an integer.")
    203     machine = Machine.get(machine_id)
     203    machine = Machine.query().get(machine_id)
    204204    if exists and machine is None:
    205205        raise InvalidInput('machine_id', machine_id, "Does not exist.")
     
    271271    if machine is not None and name == machine.name:
    272272        return None
    273     if not Machine.query().filter_by(name=name):
     273    if not Machine.query().filter_by(name=name).count():
    274274        if not validMachineName(name):
    275275            raise InvalidInput('name', name, 'You must provide a machine name.  Max 63 chars, alnum plus \'-\', does not begin or end with \'-\'.')
Note: See TracChangeset for help on using the changeset viewer.