From 8bd239af3d21339a4720ef5b1974447bc8812403 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 30 Mar 2008 04:02:48 -0400 Subject: [PATCH] some cleanups in copying autoinstaller svn path=/trunk/packages/sipb-xen-guest-installer/; revision=338 --- .../sbin/{sipb-xen-duplicate => sipb-xen-lvcopy} | 30 ++++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) rename files/usr/sbin/{sipb-xen-duplicate => sipb-xen-lvcopy} (87%) diff --git a/files/usr/sbin/sipb-xen-duplicate b/files/usr/sbin/sipb-xen-lvcopy similarity index 87% rename from files/usr/sbin/sipb-xen-duplicate rename to files/usr/sbin/sipb-xen-lvcopy index a01bf80..960f726 100755 --- a/files/usr/sbin/sipb-xen-duplicate +++ b/files/usr/sbin/sipb-xen-lvcopy @@ -78,6 +78,7 @@ def duplicate_lv(source, dest): print 'losetup -d '+destfs def frob_copy(target, *args): + '''UNUSED: maybe we'll use this someday; it does isolate the frobber.''' # 1. prepare arguments volume args_volume = prefix+target+'_args' args_device = '/dev/xenvg/' + args_volume @@ -94,7 +95,7 @@ def frob_copy(target, *args): # XXX should check_call(['/sbin/lvremove', '-f', 'xenvg/'+args_volume]) -def frob_copy_simple(target, hostname, rootpw, *args): +def frob_copy_simple(target, hostname, rootpw): """target should be an LV device filename This is highly specific to the etch install produced by sipb-xen-make-iso. @@ -127,18 +128,35 @@ def frob_copy_simple(target, hostname, rootpw, *args): # 3: clean up os.chdir('/') call(['umount', mntdir]) + os.rmdir(mntdir) call(['losetup', '-d', fs]) -def duplicate_by_vm(source, target, *args): +def duplicate_by_vm(source, target, rootpw, nodd=False): # 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]) + if not nodd: + check_call(['/bin/dd', 'bs=1M', 'conv=nocreat', + 'if='+source_device, 'of='+target_device]) # 2. frob target - frob_copy_simple(target_device, *args) + frob_copy_simple(target_device, target, rootpw) + +def main(*argv): + subcommand = argv[1] + args = argv[2:] + os.environ['PATH'] = '/usr/sbin:/usr/bin:/sbin:/bin' + if subcommand == 'lvcopy': + kwargs = {} + if args[0] == '--nodd': + args = args[1:] + kwargs['nodd'] = True + duplicate_by_vm(*args, **kwargs) + else: + print >>sys.stderr, argv[0]+": unknown subcommand: "+subcommand + return 2 + return 0 if __name__ == '__main__': - duplicate_by_vm(*sys.argv[1:]) + sys.exit(main(*sys.argv)) -- 1.7.9.5