[1437] | 1 | #!/bin/python |
---|
[1429] | 2 | # Migrates the machine named $1 from the dev cluster. |
---|
| 3 | # To be run on the prod cluster. |
---|
| 4 | |
---|
| 5 | ## The present version is NOT A REAL SCRIPT. |
---|
| 6 | ## Things may not even be tested. Copy and paste. |
---|
[1437] | 7 | not_ready_yet_do_not_run_me |
---|
[1429] | 8 | |
---|
| 9 | |
---|
[1611] | 10 | from lib import database |
---|
[1429] | 11 | |
---|
[1437] | 12 | dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen' |
---|
[1611] | 13 | database.connect(dev_db_uri) |
---|
| 14 | dev_sess = database.session |
---|
[1437] | 15 | |
---|
[1611] | 16 | database.connect() |
---|
| 17 | prod_sess = database.session |
---|
[1437] | 18 | |
---|
| 19 | def take_data(machine_name): |
---|
| 20 | ## dump from dev db; save info well |
---|
[1611] | 21 | dev_sess.begin() |
---|
| 22 | machine = dev_sess.query(database.Machine).filter_by(name=machine_name).one() |
---|
| 23 | |
---|
| 24 | # Clean out the ACL just so we don't have to think about it |
---|
| 25 | machine.acl = [] |
---|
| 26 | dev_sess.update(machine) |
---|
| 27 | |
---|
| 28 | disks = machine.disks |
---|
| 29 | nics = machine.nics |
---|
[1437] | 30 | for r in disks + nics + [machine]: |
---|
| 31 | database.session.delete(r) |
---|
[1611] | 32 | |
---|
[1437] | 33 | database.session.commit() |
---|
[1611] | 34 | |
---|
| 35 | for r in disks + nics + [machine]: |
---|
[1620] | 36 | dev_sess.expunge(r) |
---|
| 37 | del r._instance_key |
---|
[1611] | 38 | |
---|
| 39 | return machine |
---|
[1429] | 40 | |
---|
| 41 | ## shut down if up |
---|
| 42 | #remctl remote control $MACHINE destroy |
---|
| 43 | |
---|
| 44 | ## copy disk image... copy, copy... |
---|
| 45 | ## for each disk: |
---|
| 46 | lvname="d_${MACHINE}_${guest_device_name}" |
---|
| 47 | lvcreate xenvg -n "$lvname" -L "${size}"M |
---|
| 48 | ssh t-i dd if=/dev/xenvg/"$lvname" of=/dev/stdout bs=1M \ |
---|
| 49 | | dd if=/dev/stdin of=/dev/xenvg/"$lvname" bs=1M |
---|
| 50 | |
---|
| 51 | ## add to dev db |
---|
[1611] | 52 | def restore_data(machine): |
---|
| 53 | machine.type = prod_sess.query(database.Type).filter_by(type_id=machine.type.type_id).one() |
---|
| 54 | prod_sess.begin() |
---|
[1437] | 55 | ## now copy machine, disks, nics to new ORM objects (yuck, oh well) |
---|
| 56 | ## and database.session.save(those) |
---|
[1611] | 57 | prod_sess.save(machine) |
---|
| 58 | prod_sess.commit() |
---|
[1429] | 59 | |
---|
[1437] | 60 | |
---|
[1429] | 61 | ## power on if desired |
---|
[1437] | 62 | |
---|
| 63 | |
---|