[sandbox v2 2/5] virt-image-sandbox: tarball extracting function to be reusable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The virt-builder source will need this function too, let's move it to
the Source abstraction for reusability. Note that the function now
checks for tarball filename to end with ".gz" to add the proper
tar option.
---
 libvirt-sandbox/image/sources/DockerSource.py | 25 +++++--------------------
 libvirt-sandbox/image/sources/Source.py       | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/libvirt-sandbox/image/sources/DockerSource.py b/libvirt-sandbox/image/sources/DockerSource.py
index 93d7f17..0d76717 100644
--- a/libvirt-sandbox/image/sources/DockerSource.py
+++ b/libvirt-sandbox/image/sources/DockerSource.py
@@ -266,7 +266,11 @@ class DockerSource(Source):
             if parentImage is None:
                 self.format_disk(templateImage,format,connect)
 
-            self._extract_tarballs(templatedir + "/" + imagetagid + "/template.",format,connect)
+            path = templatedir + "/" + imagetagid + "/template."
+            self.extract_tarball(path + "qcow2",
+                                 format,
+                                 path + "tar.gz",
+                                 connect)
             parentImage = templateImage
 
 
@@ -302,25 +306,6 @@ class DockerSource(Source):
             imagetagid = parent
         return imagelist
 
-    def _extract_tarballs(self,directory,format,connect):
-        tarfile = directory + "tar.gz"
-        diskfile = directory + "qcow2"
-        cmd = ['virt-sandbox']
-        if connect is not None:
-            cmd.append("-c")
-            cmd.append(connect)
-        cmd.append("-p")
-        params = ['-m',
-                  'host-image:/mnt=%s,format=%s' %(diskfile,format),
-                  '--',
-                  '/bin/tar',
-                  'zxf',
-                  '%s' %tarfile,
-                  '-C',
-                  '/mnt']
-        cmd = cmd + params
-        subprocess.call(cmd)
-
     def delete_template(self, template, templatedir):
         imageusage = {}
         imageparent = {}
diff --git a/libvirt-sandbox/image/sources/Source.py b/libvirt-sandbox/image/sources/Source.py
index 708f2aa..15737c1 100644
--- a/libvirt-sandbox/image/sources/Source.py
+++ b/libvirt-sandbox/image/sources/Source.py
@@ -119,3 +119,23 @@ class Source():
                   '/dev/disk/by-tag/disk_image']
         cmd = cmd + params
         subprocess.call(cmd)
+
+    def extract_tarball(self, diskfile, format, tarfile, connect):
+        cmd = ['virt-sandbox']
+        if connect is not None:
+            cmd.append("-c")
+            cmd.append(connect)
+        cmd.append("-p")
+        compression = ""
+        if tarfile.endswith(".gz"):
+            compression = "z"
+        params = ['-m',
+                  'host-image:/mnt=%s,format=%s' % (diskfile, format),
+                  '--',
+                  '/bin/tar',
+                  'xf%s' % compression,
+                  '%s' % tarfile,
+                  '-C',
+                  '/mnt']
+        cmd = cmd + params
+        subprocess.call(cmd)
-- 
2.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]