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
---
 virt-sandbox-image/sources/DockerSource.py | 18 ++++++++++++++++++
 virt-sandbox-image/sources/Source.py       |  4 ++++
 2 files changed, 22 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 3e0362b..1e7f633 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -28,6 +28,8 @@ import traceback
 import os
 import subprocess
 import shutil
+import random
+import string
 
 class DockerConfParser():
 
@@ -372,6 +374,22 @@ class DockerSource(Source):
                     parent = None
             imagetagid = parent
 
+    def get_disk(self,**args):
+        name = args['name']
+        destdir = args['templatedir']
+        imageList = self._get_image_list(name,destdir)
+        toplayer = imageList[0]
+        diskfile = destdir + "/" + toplayer + "/template.qcow2"
+        configfile = destdir + "/" + toplayer + "/template.json"
+        tempfile = ''.join(random.choice(string.lowercase) for i in range(10))
+        tempfile = destdir + "/" + toplayer + "/" + tempfile + ".qcow2"
+        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,configfile)
+
     def get_command(self,configfile):
         configParser = DockerConfParser(configfile)
         commandToRun = configParser.getRunCommand()
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9daf62d..9a3da59 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -41,3 +41,7 @@ class Source():
     @abstractmethod
     def get_command(self,**args):
       pass
+
+    @abstractmethod
+    def get_disk(self,**args):
+      pass
-- 
2.1.0

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

Reply via email to