Changeset 1662 for trunk/scripts
- Timestamp:
- Nov 15, 2008, 6:19:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/xvm-migrate-machine
r1633 r1662 7 7 import subprocess 8 8 import sys 9 import time 10 import os 11 12 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) 13 14 kinit = dict(principal='host/aperture-science.mit.edu', keytab='/etc/krb5.keytab') 9 15 10 16 dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen' … … 50 56 dev_sess.delete(r) 51 57 52 dev_sess. commit()58 dev_sess.flush() 53 59 54 60 for r in disks + nics + [machine]: … … 72 78 # This has to be done first, because once the machine is deleted 73 79 # 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) 75 81 print out 76 82 77 83 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)]) 78 86 79 87 success = True … … 86 94 break 87 95 88 ssh = subprocess.Popen([' ssh', '-o', 'GSSAPIDelegateCredentials=no',89 ' torchwood-institute.mit.edu',96 ssh = subprocess.Popen(['rsh', 97 '10.6.0.165', 90 98 'dd', 'if=/dev/xenvg/%s' % lvname, 'bs=1M'], 91 99 stdout=subprocess.PIPE) … … 100 108 101 109 if not success: 102 restore_data(machine, dev_sess)110 dev_sess.rollback() 103 111 104 112 print '===============================================' … … 107 115 else: 108 116 restore_data(machine, prod_sess) 117 dev_sess.commit() 118 119 return success 109 120 110 121 if __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 112 139 print '===============================================' 113 print 'Migrating %s' % vm140 print 'Migrating %s' % next 114 141 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.