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

Last change on this file since 1469 was 1437, checked in by price, 16 years ago

more detail on migration: moving db entries

File size: 1.4 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 invirt import database
11
12dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen'
13
14
15def take_data(machine_name):
16## dump from dev db; save info well
17  database.connect(dev_db_uri)
18  database.session.begin()
19  machine = database.Machine.query().get_by(name=machine_name)
20  disks = database.Disk.query().filter_by(machine=machine).all()
21  nics = database.NIC.query().filter_by(machine=machine).all()
22## remove from dev db; ideally atomic with dump
23  for r in disks + nics + [machine]:
24    database.session.delete(r)
25  database.session.commit()
26  return machine, disks, nics
27
28
29## shut down if up
30#remctl remote control $MACHINE destroy
31
32## copy disk image... copy, copy...
33## for each disk:
34lvname="d_${MACHINE}_${guest_device_name}"
35lvcreate xenvg -n "$lvname" -L "${size}"M
36ssh t-i dd if=/dev/xenvg/"$lvname" of=/dev/stdout bs=1M \
37 | dd if=/dev/stdin of=/dev/xenvg/"$lvname" bs=1M
38
39## add to dev db
40def restore_data(machine, disks, nics):
41  database.connect() # to prod DB
42  database.session.begin()
43  ## now copy machine, disks, nics to new ORM objects (yuck, oh well)
44  ## and database.session.save(those)
45  database.session.commit()
46
47
48## power on if desired
49
50
Note: See TracBrowser for help on using the repository browser.