X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/prod-migration.git/blobdiff_plain/3f9edfd1f3d017268ceb54f7902a8f0d290916b6..40202455665d13069ac7b086a99e2128fea43a55:/xvm-migrate-machine diff --git a/xvm-migrate-machine b/xvm-migrate-machine index d8c729e..02f393e 100644 --- a/xvm-migrate-machine +++ b/xvm-migrate-machine @@ -1,19 +1,42 @@ -##!/bin/bash +#!/bin/python # Migrates the machine named $1 from the dev cluster. # To be run on the prod cluster. ## The present version is NOT A REAL SCRIPT. ## Things may not even be tested. Copy and paste. +not_ready_yet_do_not_run_me -## dump from dev db; save info well -#echo "\\a \\t \\\\ select * from machines where name = '$MACHINE';" \ -# | psql -h xvm -U sipb-xen sipb_xen -q -## 581|fsck|256|price|price|2ab6638f-3f65-2b32-3fd3-c16b74a9b7fe|linux|f|1|price|test|f -## watch out for funny characters in description; better (non-)quoting needed -## also disks, nics +from lib import database + +dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen' +database.connect(dev_db_uri) +dev_sess = database.session -## remove from dev db; ideally atomic with dump +database.connect() +prod_sess = database.session + +def take_data(machine_name): +## dump from dev db; save info well + dev_sess.begin() + machine = dev_sess.query(database.Machine).filter_by(name=machine_name).one() + + # Clean out the ACL just so we don't have to think about it + machine.acl = [] + dev_sess.update(machine) + + disks = machine.disks + nics = machine.nics + for r in disks + nics + [machine]: + database.session.delete(r) + + database.session.commit() + + for r in disks + nics + [machine]: + dev_sess.expunge(r) + del r._instance_key + + return machine ## shut down if up #remctl remote control $MACHINE destroy @@ -26,5 +49,15 @@ ssh t-i dd if=/dev/xenvg/"$lvname" of=/dev/stdout bs=1M \ | dd if=/dev/stdin of=/dev/xenvg/"$lvname" bs=1M ## add to dev db +def restore_data(machine): + machine.type = prod_sess.query(database.Type).filter_by(type_id=machine.type.type_id).one() + prod_sess.begin() + ## now copy machine, disks, nics to new ORM objects (yuck, oh well) + ## and database.session.save(those) + prod_sess.save(machine) + prod_sess.commit() + ## power on if desired + +