Ignore:
Timestamp:
Nov 15, 2008, 6:19:03 PM (16 years ago)
Author:
broder
Message:

The script we finally used to do the actual migration

File:
1 edited

Legend:

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

    r1633 r1662  
    77import subprocess
    88import sys
     9import time
     10import os
     11
     12sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
     13
     14kinit = dict(principal='host/aperture-science.mit.edu', keytab='/etc/krb5.keytab')
    915
    1016dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen'
     
    5056    dev_sess.delete(r)
    5157 
    52   dev_sess.commit()
     58  dev_sess.flush()
    5359 
    5460  for r in disks + nics + [machine]:
     
    7278  # This has to be done first, because once the machine is deleted
    7379  # from the database, we can't remctl for it anymore
    74   out, err = r.remctl('xvm-remote.mit.edu', 'control', machine_name, 'destroy', err=True)
     80  out, err = r.remctl('xvm-remote.mit.edu', 'control', machine_name, 'destroy', err=True, **kinit)
    7581  print out
    7682 
    7783  machine = take_data(machine_name)
     84  subprocess.call(['zwrite', '-d', '-c', 'xvm-auto', '-i', 'migration', '-s', 'XVM Migration Script', '-m',
     85                   'Migrating %s, disk size %0.2fG...' % (machine.name, sum(disk.size for disk in machine.disks) / 1024.0)])
    7886 
    7987  success = True
     
    8694      break
    8795   
    88     ssh = subprocess.Popen(['ssh', '-o', 'GSSAPIDelegateCredentials=no',
    89                 'torchwood-institute.mit.edu',
     96    ssh = subprocess.Popen(['rsh',
     97                '10.6.0.165',
    9098                'dd', 'if=/dev/xenvg/%s' % lvname, 'bs=1M'],
    9199                 stdout=subprocess.PIPE)
     
    100108 
    101109  if not success:
    102     restore_data(machine, dev_sess)
     110    dev_sess.rollback()
    103111   
    104112    print '==============================================='
     
    107115  else:
    108116    restore_data(machine, prod_sess)
     117    dev_sess.commit()
     118 
     119  return success
    109120
    110121if __name__ == '__main__':
    111   for vm in sys.argv[1:]:
     122  while True:
     123    r.checkKinit(**kinit)
     124    p = subprocess.Popen(['curl', '-s', '-k', '--negotiate', '-u', ':', 'https://xvm.mit.edu:442/offlist'], stdout=subprocess.PIPE)
     125    if 0 != p.wait():
     126        subprocess.call(['zwrite', '-d', '-c', 'xvm', '-i', 'migration', '-s', 'XVM Migration Script', '-m',
     127                         'Failed to get list of remaining VMs. Will try again in 15 seconds'])
     128        time.sleep(15)
     129        continue
     130   
     131    next_line = p.stdout.read().split('\n')[0]
     132    if next_line == '':
     133      subprocess.call(['zwrite', '-d', '-c', 'xvm', '-i', 'migration', '-s', 'XVM Migration Script', '-m',
     134                       'XVM migration complete'])
     135      break
     136   
     137    next, uptime = next_line.split('\t')[:2]
     138   
    112139    print '==============================================='
    113     print 'Migrating %s' % vm
     140    print 'Migrating %s' % next
    114141    print '==============================================='
    115     migrate_vm(vm.strip())
     142    if not migrate_vm(next):
     143      subprocess.call(['zwrite', '-d', '-c', 'xvm', '-i', 'migration', '-s', 'XVM Migration Script', '-m',
     144                       'Error in migrating %s' % next])
     145      sys.exit(1)
     146    if uptime.strip() != '':
     147      r.remctl('xvm-remote-dev.mit.edu', 'control', next, 'create', **kinit)
     148   
     149    subprocess.call(['zwrite', '-d', '-c', 'xvm-auto', '-i', 'migration', '-s', 'XVM Migration Script', '-m',
     150                     'done'])
Note: See TracChangeset for help on using the changeset viewer.