Provide a way to know how a template can be started depending on the used source
DockerSource will need to parse the topmost config file in order to find the igniter
command
---
virt-sandbox-image/sources/DockerSource.py | 14 ++++++++++++++
virt-sandbox-image/sources/Source.py | 4 ++++
2 files changed, 18 insertions(+)
diff --git a/virt-sandbox-image/sources/DockerSource.py
b/virt-sandbox-image/sources/DockerSource.py
index 03f50aa..2f4646f 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -32,6 +32,15 @@ import os
import subprocess
import shutil
+class DockerConfParser():
+
+ def __init__(self,jsonfile):
+ with open(jsonfile) as json_file:
+ self.json_data = json.load(json_file)
+ def getRunCommand(self):
+ cmd = self.json_data['container_config']['Cmd'][2]
+ return cmd[cmd.index('"') + 1:cmd.rindex('"')]
+
class DockerSource(Source):
default_index_server = "index.docker.io"
default_template_dir = "/var/lib/libvirt/templates"
@@ -376,5 +385,10 @@ class DockerSource(Source):
parent = None
imagetagid = parent
+ def get_command(self,configfile):
+ configParser = DockerConfParser(configfile)
+ commandToRun = configParser.getRunCommand()
+ return commandToRun
+
def debug(msg):
sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py b/virt-sandbox-image/sources/Source.py
index ceda58f..01f8560 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -41,3 +41,7 @@ class Source():
@abstractmethod
def delete_template(self,**args):
pass
+
+ @abstractmethod
+ def get_command(self,**args):
+ pass
--
2.1.0