- Timestamp:
- Nov 10, 2008, 11:41:13 PM (16 years ago)
- Location:
- trunk/scripts
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/xvm-migrate-machine
r1437 r1611 8 8 9 9 10 from invirtimport database10 from lib import database 11 11 12 12 dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen' 13 database.connect(dev_db_uri) 14 dev_sess = database.session 13 15 16 database.connect() 17 prod_sess = database.session 14 18 15 19 def take_data(machine_name): 16 20 ## dump from dev db; save info well 17 database.connect(dev_db_uri) 18 database.session.begin() 19 machine = database.Machine.query().get_by(name=machine_name) 20 disks = database.Disk.query().filter_by(machine=machine).all() 21 nics = database.NIC.query().filter_by(machine=machine).all() 22 ## remove from dev db; ideally atomic with dump 21 dev_sess.begin() 22 machine = dev_sess.query(database.Machine).filter_by(name=machine_name).one() 23 24 # Clean out the ACL just so we don't have to think about it 25 machine.acl = [] 26 dev_sess.update(machine) 27 28 disks = machine.disks 29 nics = machine.nics 23 30 for r in disks + nics + [machine]: 24 31 database.session.delete(r) 32 25 33 database.session.commit() 26 return machine, disks, nics 27 34 35 for r in disks + nics + [machine]: 36 dev_sess.expunge(i) 37 del i._instance_key 38 39 return machine 28 40 29 41 ## shut down if up … … 38 50 39 51 ## add to dev db 40 def restore_data(machine , disks, nics):41 database.connect() # to prod DB42 database.session.begin()52 def restore_data(machine): 53 machine.type = prod_sess.query(database.Type).filter_by(type_id=machine.type.type_id).one() 54 prod_sess.begin() 43 55 ## now copy machine, disks, nics to new ORM objects (yuck, oh well) 44 56 ## and database.session.save(those) 45 database.session.commit() 57 prod_sess.save(machine) 58 prod_sess.commit() 46 59 47 60
Note: See TracChangeset
for help on using the changeset viewer.