1 | #!/bin/python |
---|
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. |
---|
7 | not_ready_yet_do_not_run_me |
---|
8 | |
---|
9 | |
---|
10 | from lib import database |
---|
11 | |
---|
12 | dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen' |
---|
13 | database.connect(dev_db_uri) |
---|
14 | dev_sess = database.session |
---|
15 | |
---|
16 | database.connect() |
---|
17 | prod_sess = database.session |
---|
18 | |
---|
19 | def take_data(machine_name): |
---|
20 | ## dump from dev db; save info well |
---|
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 |
---|
30 | for r in disks + nics + [machine]: |
---|
31 | database.session.delete(r) |
---|
32 | |
---|
33 | database.session.commit() |
---|
34 | |
---|
35 | for r in disks + nics + [machine]: |
---|
36 | dev_sess.expunge(r) |
---|
37 | del r._instance_key |
---|
38 | |
---|
39 | return machine |
---|
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 |
---|
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() |
---|
55 | ## now copy machine, disks, nics to new ORM objects (yuck, oh well) |
---|
56 | ## and database.session.save(those) |
---|
57 | prod_sess.save(machine) |
---|
58 | prod_sess.commit() |
---|
59 | |
---|
60 | |
---|
61 | ## power on if desired |
---|
62 | |
---|
63 | |
---|