[sandbox 06/11] virt-sandbox-image: move DockerSource _format_disk to Source

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

 



Formatting a disk is a generic operation that will be needed by other
sources, at least a virt-builder one.
---
 libvirt-sandbox/image/sources/DockerSource.py | 14 +-------------
 libvirt-sandbox/image/sources/Source.py       | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/libvirt-sandbox/image/sources/DockerSource.py b/libvirt-sandbox/image/sources/DockerSource.py
index 6c02cc3..41df7a7 100644
--- a/libvirt-sandbox/image/sources/DockerSource.py
+++ b/libvirt-sandbox/image/sources/DockerSource.py
@@ -261,7 +261,7 @@ class DockerSource(Source):
             subprocess.call(cmd)
 
             if parentImage is None:
-                self._format_disk(templateImage,format,connect)
+                self.format_disk(templateImage,format,connect)
 
             self._extract_tarballs(templatedir + "/" + imagetagid + "/template.",format,connect)
             parentImage = templateImage
@@ -299,18 +299,6 @@ class DockerSource(Source):
             imagetagid = parent
         return imagelist
 
-    def _format_disk(self,disk,format,connect):
-        cmd = ['virt-sandbox']
-        if connect is not None:
-            cmd.append("-c")
-            cmd.append(connect)
-        cmd.append("-p")
-        params = ['--disk=file:disk_image=%s,format=%s' %(disk,format),
-                  '/sbin/mkfs.ext3',
-                  '/dev/disk/by-tag/disk_image']
-        cmd = cmd + params
-        subprocess.call(cmd)
-
     def _extract_tarballs(self,directory,format,connect):
         tarfile = directory + "tar.gz"
         diskfile = directory + "qcow2"
diff --git a/libvirt-sandbox/image/sources/Source.py b/libvirt-sandbox/image/sources/Source.py
index 20f4af0..444baa3 100644
--- a/libvirt-sandbox/image/sources/Source.py
+++ b/libvirt-sandbox/image/sources/Source.py
@@ -21,6 +21,7 @@
 # Author: Eren Yagdiran <erenyagdiran@xxxxxxxxx>
 
 from abc import ABCMeta, abstractmethod
+import subprocess
 
 class Source():
     '''The Source class defines the base interface for
@@ -114,3 +115,18 @@ class Source():
         cleanup.
         """
         pass
+
+
+    # Utility functions to share between the sources.
+
+    def format_disk(self,disk,format,connect):
+        cmd = ['virt-sandbox']
+        if connect is not None:
+            cmd.append("-c")
+            cmd.append(connect)
+        cmd.append("-p")
+        params = ['--disk=file:disk_image=%s,format=%s' %(disk,format),
+                  '/sbin/mkfs.ext3',
+                  '/dev/disk/by-tag/disk_image']
+        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]