Neal Gompa 8c8af0
From 042ec7b7c2f5e6a4b0bbf1818c2cd93ba9ebde8f Mon Sep 17 00:00:00 2001
Neal Gompa 8c8af0
From: Lubomir Rintel <lkundrak@v3.sk>
Neal Gompa 8c8af0
Date: Mon, 5 Oct 2015 05:14:42 -0400
Neal Gompa 8c8af0
Subject: [PATCH 2/2] Make it possible to disable compression
Neal Gompa 8c8af0
Neal Gompa 8c8af0
---
Neal Gompa 8c8af0
 appcreate/appliance.py     | 25 +++++++++++++++----------
Neal Gompa 8c8af0
 docs/appliance-creator.pod |  6 +++++-
Neal Gompa 8c8af0
 tools/appliance-creator    |  4 +++-
Neal Gompa 8c8af0
 3 files changed, 23 insertions(+), 12 deletions(-)
Neal Gompa 8c8af0
Neal Gompa 8c8af0
diff --git a/appcreate/appliance.py b/appcreate/appliance.py
Neal Gompa 8c8af0
index f77b13b..258396d 100644
Neal Gompa 8c8af0
--- a/appcreate/appliance.py
Neal Gompa 8c8af0
+++ b/appcreate/appliance.py
Neal Gompa 8c8af0
@@ -43,7 +43,7 @@ class ApplianceImageCreator(ImageCreator):
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
     """
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
-    def __init__(self, ks, name, disk_format, vmem, vcpu, releasever=None):
Neal Gompa 8c8af0
+    def __init__(self, ks, name, disk_format, vmem, vcpu, releasever=None, no_compress=False):
Neal Gompa 8c8af0
         """Initialize a ApplianceImageCreator instance.
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
         This method takes the same arguments as ImageCreator.__init__()
Neal Gompa 8c8af0
@@ -55,6 +55,7 @@ class ApplianceImageCreator(ImageCreator):
Neal Gompa 8c8af0
         self.__imgdir = None
Neal Gompa 8c8af0
         self.__disks = {}
Neal Gompa 8c8af0
         self.__disk_format = disk_format
Neal Gompa 8c8af0
+        self.__compress = not no_compress
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
         #appliance parameters
Neal Gompa 8c8af0
         self.vmem = vmem
Neal Gompa 8c8af0
@@ -629,14 +630,18 @@ class ApplianceImageCreator(ImageCreator):
Neal Gompa 8c8af0
         else:
Neal Gompa 8c8af0
             logging.debug("moving disks to stage location")
Neal Gompa 8c8af0
             for name in self.__disks.keys():
Neal Gompa 8c8af0
-                rc = subprocess.call(["xz", "-z", "%s/%s-%s.%s" %(self.__imgdir, self.name, name, self.__disk_format)])
Neal Gompa 8c8af0
-                if rc == 0:
Neal Gompa 8c8af0
-                    logging.debug("compression successful")
Neal Gompa 8c8af0
-                if rc != 0:
Neal Gompa 8c8af0
-                    raise CreatorError("Unable to compress disk to %s" % self.__disk_format)
Neal Gompa 8c8af0
-
Neal Gompa 8c8af0
-                src = "%s/%s-%s.%s.xz" % (self.__imgdir, self.name, name, self.__disk_format)
Neal Gompa 8c8af0
-                dst = "%s/%s-%s.%s.xz" % (self._outdir, self.name, name, self.__disk_format)
Neal Gompa 8c8af0
+                src = "%s/%s-%s.%s" % (self.__imgdir, self.name, name, self.__disk_format)
Neal Gompa 8c8af0
+                dst = "%s/%s-%s.%s" % (self._outdir, self.name, name, self.__disk_format)
Neal Gompa 8c8af0
+
Neal Gompa 8c8af0
+                if self.__compress:
Neal Gompa 8c8af0
+                    rc = subprocess.call(["xz", "-z", src])
Neal Gompa 8c8af0
+                    if rc == 0:
Neal Gompa 8c8af0
+                        logging.debug("compression successful")
Neal Gompa 8c8af0
+                    if rc != 0:
Neal Gompa 8c8af0
+                        raise CreatorError("Unable to compress disk to %s" % self.__disk_format)
Neal Gompa 8c8af0
+                    src = "%s.xz" % (src)
Neal Gompa 8c8af0
+                    dst = "%s.xz" % (dst)
Neal Gompa 8c8af0
+
Neal Gompa 8c8af0
                 logging.debug("moving %s to %s" % (src, dst))
Neal Gompa 8c8af0
                 shutil.move(src, dst)
Neal Gompa 8c8af0
         #write meta data in stage dir
Neal Gompa 8c8af0
@@ -647,7 +652,7 @@ class ApplianceImageCreator(ImageCreator):
Neal Gompa 8c8af0
         for name in self.__disks.keys():
Neal Gompa 8c8af0
             dst = "%s/%s-%s.%s" % (self._outdir, self.name, name, self.__disk_format)
Neal Gompa 8c8af0
             logging.debug("converting %s image to %s" % (self.__disks[name].lofile, dst))
Neal Gompa 8c8af0
-            if self.__disk_format == "qcow2":
Neal Gompa 8c8af0
+            if self.__compress and self.__disk_format == "qcow2":
Neal Gompa 8c8af0
                 logging.debug("using compressed qcow2")
Neal Gompa 8c8af0
                 compressflag = "-c"
Neal Gompa 8c8af0
             else:
Neal Gompa 8c8af0
diff --git a/docs/appliance-creator.pod b/docs/appliance-creator.pod
Neal Gompa 8c8af0
index 93bebad..a0ad804 100644
Neal Gompa 8c8af0
--- a/docs/appliance-creator.pod
Neal Gompa 8c8af0
+++ b/docs/appliance-creator.pod
Neal Gompa 8c8af0
@@ -38,7 +38,7 @@ Name of appliance image to be created (default based on config name)
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
 =item -f FORMAT, --format=FORMAT
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
-Disk format, this will take any input that qemu-img convert will take (raw, qcow2, vmdk, ...) Note: not all disk formats with work with all virt technologies. raw images are xz compressed, qcow2 images use compression.
Neal Gompa 8c8af0
+Disk format, this will take any input that qemu-img convert will take (raw, qcow2, vmdk, ...) Note: not all disk formats with work with all virt technologies. raw images are xz compressed, qcow2 images use compression (unless disabled with --no-compress option.
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
 =item --vmem=VMEM
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
@@ -52,6 +52,10 @@ Number of virtual cpus for appliance (default: 1)
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
 Generate a checksum for the created appliance
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
+=item --no-compress
Neal Gompa 8c8af0
+
Neal Gompa 8c8af0
+Disable image compression.
Neal Gompa 8c8af0
+
Neal Gompa 8c8af0
 =back
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
 =head1 SYSTEM DIRECTORY OPTIONS
Neal Gompa 8c8af0
diff --git a/tools/appliance-creator b/tools/appliance-creator
Neal Gompa 8c8af0
index 9e3fa15..3ffc22c 100755
Neal Gompa 8c8af0
--- a/tools/appliance-creator
Neal Gompa 8c8af0
+++ b/tools/appliance-creator
Neal Gompa 8c8af0
@@ -57,6 +57,8 @@ def parse_options(args):
Neal Gompa 8c8af0
                       help=("Generate a checksum for the created appliance"))
Neal Gompa 8c8af0
     appopt.add_option("-f", "--format", type="string", dest="disk_format", default="raw",
Neal Gompa 8c8af0
                       help="Disk format (default: raw)")
Neal Gompa 8c8af0
+    appopt.add_option("", "--no-compress", action="store_true", dest="no_compress", default=False,
Neal Gompa 8c8af0
+                      help="Avoid compressing the image")
Neal Gompa 8c8af0
     parser.add_option_group(appopt)
Neal Gompa 8c8af0
     
Neal Gompa 8c8af0
     
Neal Gompa 8c8af0
@@ -129,7 +131,7 @@ def main():
Neal Gompa 8c8af0
     if options.name:
Neal Gompa 8c8af0
         name = options.name
Neal Gompa 8c8af0
             
Neal Gompa 8c8af0
-    creator = appcreate.ApplianceImageCreator(ks, name, options.disk_format, options.vmem, options.vcpu, releasever=options.version)
Neal Gompa 8c8af0
+    creator = appcreate.ApplianceImageCreator(ks, name, options.disk_format, options.vmem, options.vcpu, releasever=options.version, no_compress=options.no_compress)
Neal Gompa 8c8af0
     creator.tmpdir = options.tmpdir
Neal Gompa 8c8af0
     creator.checksum = options.checksum
Neal Gompa 8c8af0
 
Neal Gompa 8c8af0
-- 
Neal Gompa 8c8af0
2.9.3
Neal Gompa 8c8af0