Re: [PATCH sandbox v5 09/20] Image: Add get_command function to Source

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

 



On Tue, 2015-09-08 at 17:29 +0100, Daniel P. Berrange wrote:
> From: Eren Yagdiran <erenyagdiran@xxxxxxxxx>
> 
> 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
> 
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  libvirt-sandbox/image/sources/DockerSource.py | 31 +++++++++++++++++++++++++++
>  libvirt-sandbox/image/sources/Source.py       | 12 +++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/libvirt-sandbox/image/sources/DockerSource.py b/libvirt-sandbox/image/sources/DockerSource.py
> index ab18b52..2607011 100644
> --- a/libvirt-sandbox/image/sources/DockerSource.py
> +++ b/libvirt-sandbox/image/sources/DockerSource.py
> @@ -29,6 +29,16 @@ 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 getCommand(self):
> +        return self.json_data['config']['Cmd']
> +    def getEntrypoint(self):
> +        return self.json_data['config']['Entrypoint']
> +
>  class DockerSource(Source):
>  
>      www_auth_username = None
> @@ -345,5 +355,26 @@ class DockerSource(Source):
>                      parent = None
>              imagetagid = parent
>  
> +    def _get_template_data(self, templatename, templatedir):
> +        imageList = self._get_image_list(templatename, templatedir)
> +        toplayer = imageList[0]
> +        diskfile = templatedir + "/" + toplayer + "/template.qcow2"
> +        configfile = templatedir + "/" + toplayer + "/template.json"
> +        return configfile, diskfile
> +
> +    def get_command(self, templatename, templatedir, userargs):
> +        configfile, diskfile = self._get_template_data(templatename, templatedir)
> +        configParser = DockerConfParser(configfile)
> +        cmd = configParser.getCommand()
> +        entrypoint = configParser.getEntrypoint()
> +        if entrypoint is None:
> +            entrypoint = []
> +        if cmd is None:
> +            cmd = []
> +        if userargs is not None and len(userargs) > 0:
> +            return entrypoint + userargs
> +        else:
> +            return entrypoint + cmd
> +
>  def debug(msg):
>      sys.stderr.write(msg)
> diff --git a/libvirt-sandbox/image/sources/Source.py b/libvirt-sandbox/image/sources/Source.py
> index 4aea5c9..4305d0b 100644
> --- a/libvirt-sandbox/image/sources/Source.py
> +++ b/libvirt-sandbox/image/sources/Source.py
> @@ -71,3 +71,15 @@ class Source():
>          Delete all local files associated with the template
>          """
>          pass
> +
> +    @abstractmethod
> +    def get_command(self, templatename, templatedir, userargs):
> +        """
> +        :param templatename: name of the template image to query
> +        :param templatedir: local directory path in which templates are stored
> +        :param userargs: user specified arguments to run
> +
> +        Get the command line to invoke in the container. If userargs
> +        is specified, then this should override the default args in
> +        the image"""
> +        pass

ACK

--
Cedric


--
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]