some cleanups in copying autoinstaller
authorGreg Price <price@mit.edu>
Sun, 30 Mar 2008 08:02:48 +0000 (04:02 -0400)
committerGreg Price <price@mit.edu>
Sun, 30 Mar 2008 08:02:48 +0000 (04:02 -0400)
svn path=/trunk/packages/sipb-xen-guest-installer/; revision=338

files/usr/sbin/sipb-xen-lvcopy [moved from files/usr/sbin/sipb-xen-duplicate with 87% similarity]

similarity index 87%
rename from files/usr/sbin/sipb-xen-duplicate
rename to files/usr/sbin/sipb-xen-lvcopy
index a01bf80..960f726 100755 (executable)
@@ -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))