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

Last change on this file since 1624 was 1620, checked in by broder, 16 years ago

Fix typo in xvm-migrate-machine

File size: 1.6 KB
RevLine 
[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]7not_ready_yet_do_not_run_me
[1429]8
9
[1611]10from lib import database
[1429]11
[1437]12dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen'
[1611]13database.connect(dev_db_uri)
14dev_sess = database.session
[1437]15
[1611]16database.connect()
17prod_sess = database.session
[1437]18
19def 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:
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
[1611]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()
[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
Note: See TracBrowser for help on using the repository browser.