Ignore:
Timestamp:
Jun 26, 2010, 8:33:53 PM (14 years ago)
Author:
quentin
Message:

Allow partial success when modifying a VM, so the database will more likely match reality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-web/code/main.py

    r2979 r3027  
    538538            machine.type = validate.vmtype
    539539
     540        update_acl = False
     541        if hasattr(validate, 'owner') and validate.owner != machine.owner:
     542            machine.owner = validate.owner
     543            update_acl = True
     544        if hasattr(validate, 'description'):
     545            machine.description = validate.description
     546        if hasattr(validate, 'admin') and validate.admin != machine.administrator:
     547            machine.administrator = validate.admin
     548            update_acl = True
     549        if hasattr(validate, 'contact'):
     550            machine.contact = validate.contact
     551
     552        session.save_or_update(machine)
     553        session.commit()
     554    except:
     555        session.rollback()
     556        raise
     557
     558    session.begin()
     559    try:
    540560        if hasattr(validate, 'disksize'):
    541561            disksize = validate.disksize
     
    545565                disk.size = disksize
    546566                session.save_or_update(disk)
    547 
    548         update_acl = False
    549         if hasattr(validate, 'owner') and validate.owner != machine.owner:
    550             machine.owner = validate.owner
    551             update_acl = True
     567        for diskname in olddisk:
     568            controls.resizeDisk(oldname, diskname, str(olddisk[diskname]))
     569        session.save_or_update(machine)
     570        session.commit()
     571    except:
     572        session.rollback()
     573        raise
     574
     575    session.begin()
     576    try:
    552577        if hasattr(validate, 'name'):
    553578            machine.name = validate.name
     
    555580                if n.hostname == oldname:
    556581                    n.hostname = validate.name
    557         if hasattr(validate, 'description'):
    558             machine.description = validate.description
    559         if hasattr(validate, 'admin') and validate.admin != machine.administrator:
    560             machine.administrator = validate.admin
    561             update_acl = True
    562         if hasattr(validate, 'contact'):
    563             machine.contact = validate.contact
    564 
     582        if hasattr(validate, 'name'):
     583            controls.renameMachine(machine, oldname, validate.name)
    565584        session.save_or_update(machine)
    566         if update_acl:
    567             cache_acls.refreshMachine(machine)
    568585        session.commit()
    569586    except:
    570587        session.rollback()
    571588        raise
    572     for diskname in olddisk:
    573         controls.resizeDisk(oldname, diskname, str(olddisk[diskname]))
    574     if hasattr(validate, 'name'):
    575         controls.renameMachine(machine, oldname, validate.name)
     589
     590    if update_acl:
     591        cache_acls.refreshMachine(machine)
     592
    576593    return dict(machine=machine)
    577594
Note: See TracChangeset for help on using the changeset viewer.