-#!/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
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:])