Index: trunk/scripts/xvm-migrate-machine
===================================================================
--- trunk/scripts/xvm-migrate-machine	(revision 1631)
+++ trunk/scripts/xvm-migrate-machine	(revision 1632)
@@ -59,11 +59,11 @@
 
 ## add to prod db
-def restore_data(machine):
+def restore_data(machine, session):
   # The machine's type is still the one attached to the dev database;
   # get the right one
-  machine.type = prod_sess.query(database.Type).filter_by(type_id=machine.type.type_id).one()
-  prod_sess.begin()
-  prod_sess.save(machine)
-  prod_sess.commit()
+  machine.type = session.query(database.Type).filter_by(type_id=machine.type.type_id).one()
+  session.begin()
+  session.save(machine)
+  session.commit()
   
 def migrate_vm(machine_name):
@@ -77,9 +77,11 @@
   machine = take_data(machine_name)
   
+  success = True
   ## copy disk image... copy, copy...
   for disk in machine.disks:
     lvname='d_%s_%s' % (machine.name, disk.guest_device_name)
     
-    subprocess.check_call(['lvcreate', '-L%sM' % str(disk.size), '-n', lvname, 'xenvg'])
+    if 0 != subprocess.call(['lvcreate', '-L%sM' % str(disk.size), '-n', lvname, 'xenvg']):
+      success = False
     
     ssh = subprocess.Popen(['ssh', '-o', 'GSSAPIDelegateCredentials=no',
@@ -89,7 +91,17 @@
     dd = subprocess.Popen(['dd', 'of=/dev/xenvg/%s' % lvname, 'bs=1M'],
                 stdin=ssh.stdout)
-    dd.wait()
+    if 0 != dd.wait():
+      success = False
+    if 0 != ssh.wait():
+      success = False
   
-  restore_data(machine)
+  if not success:
+    restore_data(machine, dev_sess)
+    
+    print '==============================================='
+    print 'ERROR: VM %s failed to migrate' % machine.name
+    print '==============================================='
+  else:
+    restore_data(machine, prod_sess)
 
 if __name__ == '__main__':
