Changeset 1632 for trunk


Ignore:
Timestamp:
Nov 12, 2008, 10:51:43 PM (16 years ago)
Author:
broder
Message:

Fault tolerance is a good thing - add some to the migration script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/xvm-migrate-machine

    r1629 r1632  
    5959
    6060## add to prod db
    61 def restore_data(machine):
     61def restore_data(machine, session):
    6262  # The machine's type is still the one attached to the dev database;
    6363  # 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()
    6868 
    6969def migrate_vm(machine_name):
     
    7777  machine = take_data(machine_name)
    7878 
     79  success = True
    7980  ## copy disk image... copy, copy...
    8081  for disk in machine.disks:
    8182    lvname='d_%s_%s' % (machine.name, disk.guest_device_name)
    8283   
    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
    8486   
    8587    ssh = subprocess.Popen(['ssh', '-o', 'GSSAPIDelegateCredentials=no',
     
    8991    dd = subprocess.Popen(['dd', 'of=/dev/xenvg/%s' % lvname, 'bs=1M'],
    9092                stdin=ssh.stdout)
    91     dd.wait()
     93    if 0 != dd.wait():
     94      success = False
     95    if 0 != ssh.wait():
     96      success = False
    9297 
    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)
    94106
    95107if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.