From 4a2fd05c4fad9b757ad1ae2df973ddc790a6921e Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Wed, 16 May 2012 15:23:34 +0300 Subject: [PATCH] Add remove_swap_entry sysprep in linux This action will remove the swap entry from the fstab. --- image_creator/os_type/__init__.py | 5 +++-- image_creator/os_type/linux.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index b19d573..052a3e3 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -120,6 +120,7 @@ class OSBase(object): wrapper = textwrap.TextWrapper() wrapper.subsequent_indent = '\t' wrapper.initial_indent = '\t' + wrapper.width = 72 output("Enabled system preperation operations:") if len(enabled) == 0: @@ -127,7 +128,7 @@ class OSBase(object): else: for sysprep in enabled: name = sysprep.__name__.replace('_', '-') - descr = wrapper.fill(sysprep.__doc__) + descr = wrapper.fill(textwrap.dedent(sysprep.__doc__)) output(' %s:\n%s\n' % (name, descr)) output("Disabled system preperation operations:") @@ -136,7 +137,7 @@ class OSBase(object): else: for sysprep in disabled: name = sysprep.__name__.replace('_', '-') - descr = wrapper.fill(sysprep.__doc__) + descr = wrapper.fill(textwrap.dedent(sysprep.__doc__)) output(' %s:\n%s\n' % (name, descr)) @add_prefix diff --git a/image_creator/os_type/linux.py b/image_creator/os_type/linux.py index de82e7d..e128396 100644 --- a/image_creator/os_type/linux.py +++ b/image_creator/os_type/linux.py @@ -126,6 +126,29 @@ class Linux(Unix): self.g.rm(rule_file) @sysprep() + def remove_swap_entry(self, print_header=True): + """Remove swap entry from /etc/fstab. If swap is the last partition + then the partition will be removed when shrinking is performed. If the + swap partition is not the last partition in the disk or if you are not + going to shrink the image you should probably disable this. + """ + + if print_header: + output('Removing swap entry from fstab') + + new_fstab = "" + fstab = self.g.cat('/etc/fstab') + for line in fstab.splitlines(): + + entry = line.split('#')[0].strip().split() + if len(entry) == 6 and entry[2] == 'swap': + continue + + new_fstab += "%s\n" % line + + self.g.write('/etc/fstab', new_fstab) + + @sysprep() def persistent_devs(self, print_header=True): """Scan fstab & grub configuration files and replace all non-persistent device appearences with UUIDs. -- 1.7.10.4