+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])
+
+