X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-autoinstaller.git/blobdiff_plain/db71340c2668dc8de6a9412bcb526dc4336e8471..ff6990914e27571b5c66e6411a7bf416ca8f90a5:/files/usr/sbin/sipb-xen-duplicate?ds=sidebyside diff --git a/files/usr/sbin/sipb-xen-duplicate b/files/usr/sbin/sipb-xen-duplicate index fa24e23..a78d3a1 100755 --- a/files/usr/sbin/sipb-xen-duplicate +++ b/files/usr/sbin/sipb-xen-duplicate @@ -1,10 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.5 import sys import os import shutil import tempfile -from subprocess import call, Popen +from subprocess import call, check_call, Popen # TODO: # . pick a loop device sanely @@ -71,5 +71,30 @@ def duplicate_lv(source, dest): print 'losetup -d '+sourcefs print 'losetup -d '+destfs +def duplicate_by_vm(source, target, *args): + # source, target should be machine names + prefix = 'd_' + # 1. copy (by dd) source to target + source_device = '/dev/xenvg/' + prefix + source + '_hda' + target_device = '/dev/xenvg/' + prefix + target + '_hda' + #check_call(['/bin/dd', 'bs=1M', 'conv=nocreat', + # 'if='+source_device, 'of='+target_device]) + # 2. prepare arguments volume + args_volume = prefix+target+'_args' + args_device = '/dev/xenvg/' + args_volume + check_call(['/sbin/lvcreate', 'xenvg', '--name', args_volume, '--size', '4K']) + file(args_device, 'w').write('\n'.join(args) + '\n') + + copier_device = '/dev/xenvg/d_wert_hda' + check_call(['/usr/sbin/xm', 'create', 'sipb-database', + 'machine_name='+target, + 'disks=' + ' '.join(['phy:'+copier_device+',hda,w', + 'phy:'+target_device+',hdc,w', + 'phy:'+args_device+',hdd,w'])]) + boot = 'c' + + # XXX make this happen! check_call(['/sbin/lvremove', '-f', 'xenvg/'+args_volume]) + + if __name__ == '__main__': - duplicate_lv(*sys.argv[1:]) + duplicate_by_vm(*sys.argv[1:])