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