source: trunk/scripts/xvm-migrate-machine @ 1611

Last change on this file since 1611 was 1611, checked in by broder, 15 years ago

Eliminate the need for a deep copy of database objects during the
migration with weird SQLAlchemy haxory.

This requires the migration script to have its own unique version of
the database library

File size: 1.6 KB
Line 
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.
7not_ready_yet_do_not_run_me
8
9
10from lib import database
11
12dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen'
13database.connect(dev_db_uri)
14dev_sess = database.session
15
16database.connect()
17prod_sess = database.session
18
19def 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(i)
37    del i._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:
46lvname="d_${MACHINE}_${guest_device_name}"
47lvcreate xenvg -n "$lvname" -L "${size}"M
48ssh 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
52def 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
Note: See TracBrowser for help on using the repository browser.