Changeset 1632 for trunk/scripts/xvm-migrate-machine
- Timestamp:
- Nov 12, 2008, 10:51:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/xvm-migrate-machine
r1629 r1632 59 59 60 60 ## add to prod db 61 def restore_data(machine ):61 def restore_data(machine, session): 62 62 # The machine's type is still the one attached to the dev database; 63 63 # get the right one 64 machine.type = prod_sess.query(database.Type).filter_by(type_id=machine.type.type_id).one()65 prod_sess.begin()66 prod_sess.save(machine)67 prod_sess.commit()64 machine.type = session.query(database.Type).filter_by(type_id=machine.type.type_id).one() 65 session.begin() 66 session.save(machine) 67 session.commit() 68 68 69 69 def migrate_vm(machine_name): … … 77 77 machine = take_data(machine_name) 78 78 79 success = True 79 80 ## copy disk image... copy, copy... 80 81 for disk in machine.disks: 81 82 lvname='d_%s_%s' % (machine.name, disk.guest_device_name) 82 83 83 subprocess.check_call(['lvcreate', '-L%sM' % str(disk.size), '-n', lvname, 'xenvg']) 84 if 0 != subprocess.call(['lvcreate', '-L%sM' % str(disk.size), '-n', lvname, 'xenvg']): 85 success = False 84 86 85 87 ssh = subprocess.Popen(['ssh', '-o', 'GSSAPIDelegateCredentials=no', … … 89 91 dd = subprocess.Popen(['dd', 'of=/dev/xenvg/%s' % lvname, 'bs=1M'], 90 92 stdin=ssh.stdout) 91 dd.wait() 93 if 0 != dd.wait(): 94 success = False 95 if 0 != ssh.wait(): 96 success = False 92 97 93 restore_data(machine) 98 if not success: 99 restore_data(machine, dev_sess) 100 101 print '===============================================' 102 print 'ERROR: VM %s failed to migrate' % machine.name 103 print '===============================================' 104 else: 105 restore_data(machine, prod_sess) 94 106 95 107 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.