From: Eren Yagdiran <erenyagdi...@gmail.com>

Provide a way to know which disk image to use for the sandbox depending on the 
used source
DockerSource will need to locate the topmost disk image among all the layers 
images

Signed-off-by: Daniel P. Berrange <berra...@redhat.com>
---
 libvirt-sandbox/image/sources/DockerSource.py | 12 ++++++++++++
 libvirt-sandbox/image/sources/Source.py       | 12 ++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/libvirt-sandbox/image/sources/DockerSource.py 
b/libvirt-sandbox/image/sources/DockerSource.py
index 2607011..31c1d80 100644
--- a/libvirt-sandbox/image/sources/DockerSource.py
+++ b/libvirt-sandbox/image/sources/DockerSource.py
@@ -362,6 +362,18 @@ class DockerSource(Source):
         configfile = templatedir + "/" + toplayer + "/template.json"
         return configfile, diskfile
 
+    def get_disk(self,templatename, templatedir, imagedir, sandboxname):
+        configfile, diskfile = self._get_template_data(templatename, 
templatedir)
+        tempfile = imagedir + "/" + sandboxname + ".qcow2"
+        if not os.path.exists(imagedir):
+            os.makedirs(imagedir)
+        cmd = ["qemu-img","create","-q","-f","qcow2"]
+        cmd.append("-o")
+        cmd.append("backing_fmt=qcow2,backing_file=%s" % diskfile)
+        cmd.append(tempfile)
+        subprocess.call(cmd)
+        return tempfile
+
     def get_command(self, templatename, templatedir, userargs):
         configfile, diskfile = self._get_template_data(templatename, 
templatedir)
         configParser = DockerConfParser(configfile)
diff --git a/libvirt-sandbox/image/sources/Source.py 
b/libvirt-sandbox/image/sources/Source.py
index 4305d0b..a5d3844 100644
--- a/libvirt-sandbox/image/sources/Source.py
+++ b/libvirt-sandbox/image/sources/Source.py
@@ -83,3 +83,15 @@ class Source():
         is specified, then this should override the default args in
         the image"""
         pass
+
+    @abstractmethod
+    def get_disk(self,templatename, templatedir, imagedir, sandboxname):
+        """
+        :param templatename: name of the template image to download
+        :param templatedir: local directory path in which to find template
+        :param imagedir: local directory in which to storage disk image
+
+        Creates an instance private disk image, backed by the content
+        of a template.
+        """
+        pass
-- 
2.4.3

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

Reply via email to