Re: [sandbox PATCH v2 13/19] Image: Add Volume Support

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

 



On Tue, 2015-08-04 at 20:11 +0000, Eren Yagdiran wrote:
> Volumes let user to map host-paths into guest. Docker containers need volumes because its
> filesystem read-only by default.

Docker doesn't set / read-only by default. Docker volumes are only a way
to share data with the host or other containers. See here:

http://docs.docker.com/userguide/dockervolumes/#volume

--
Cedric

> ---
>  virt-sandbox-image/sources/DockerSource.py | 12 ++++++++++++
>  virt-sandbox-image/sources/Source.py       |  4 ++++
>  virt-sandbox-image/virt-sandbox-image.py   | 22 ++++++++++++++++++++++
>  3 files changed, 38 insertions(+)
> 
> diff --git a/virt-sandbox-image/sources/DockerSource.py b/virt-sandbox-image/sources/DockerSource.py
> index 74feb3e..44bc238 100644
> --- a/virt-sandbox-image/sources/DockerSource.py
> +++ b/virt-sandbox-image/sources/DockerSource.py
> @@ -31,6 +31,7 @@ import traceback
>  import os
>  import subprocess
>  import shutil
> +import collections
>  
>  class DockerConfParser():
>  
> @@ -40,6 +41,13 @@ class DockerConfParser():
>      def getRunCommand(self):
>          cmd = self.json_data['container_config']['Cmd'][2]
>          return cmd[cmd.index('"') + 1:cmd.rindex('"')]
> +    def getVolumes(self):
> +        volumes = self.json_data['container_config']['Volumes']
> +        volumelist = []
> +        if isinstance(volumes,collections.Iterable):
> +          for key,value in volumes.iteritems():
> +            volumelist.append(key)
> +        return volumelist
>  
>  class DockerSource(Source):
>      default_index_server = "index.docker.io"
> @@ -399,5 +407,9 @@ class DockerSource(Source):
>          commandToRun = configParser.getRunCommand()
>          return commandToRun
>  
> +    def get_volume(self,configfile):
> +        configParser = DockerConfParser(configfile)
> +        return configParser.getVolumes()
> +
>  def debug(msg):
>      sys.stderr.write(msg)
> diff --git a/virt-sandbox-image/sources/Source.py b/virt-sandbox-image/sources/Source.py
> index 6e2f5fb..6898c15 100644
> --- a/virt-sandbox-image/sources/Source.py
> +++ b/virt-sandbox-image/sources/Source.py
> @@ -49,3 +49,7 @@ class Source():
>      @abstractmethod
>      def get_disk(self,**args):
>        pass
> +
> +    @abstractmethod
> +    def get_volume(self,**args):
> +      pass
> diff --git a/virt-sandbox-image/virt-sandbox-image.py b/virt-sandbox-image/virt-sandbox-image.py
> index 5fc7f44..b12b99b 100755
> --- a/virt-sandbox-image/virt-sandbox-image.py
> +++ b/virt-sandbox-image/virt-sandbox-image.py
> @@ -103,6 +103,7 @@ def check_connect(connectstr):
>  
>  def run(args):
>      try:
> +        default_dir = "/var/lib/libvirt/storage"
>          if args.connect is not None:
>              check_connect(args.connect)
>          source = dynamic_source_loader(args.source)
> @@ -121,6 +122,25 @@ def run(args):
>          if networkArgs is not None:
>              params.append('-N')
>              params.append(networkArgs)
> +        allVolumes = source.get_volume(configfile)
> +        volumeArgs = args.volume
> +        if volumeArgs is not None:
> +            allVolumes = allVolumes + volumeArgs
> +        for volume in allVolumes:
> +            volumeSplit = volume.split(":")
> +            volumelen = len(volumeSplit)
> +            if volumelen == 2:
> +                hostPath = volumeSplit[0]
> +                guestPath = volumeSplit[1]
> +            elif volumelen == 1:
> +                guestPath = volumeSplit[0]
> +                hostPath = default_dir + guestPath
> +                if not os.path.exists(hostPath):
> +                    os.makedirs(hostPath)
> +            else:
> +                pass
> +            params.append("--mount")
> +            params.append("host-bind:%s=%s" %(guestPath,hostPath))
>          params.append('--')
>          params.append(commandToRun)
>          cmd = cmd + params
> @@ -193,6 +213,8 @@ def gen_run_args(subparser):
>                          help=_("Igniter command for image"))
>      parser.add_argument("-n","--network",
>                          help=_("Network params for running template"))
> +    parser.add_argument("-v","--volume",action="append",
> +                        help=_("Volume params for running template"))
>      parser.set_defaults(func=run)
>  
>  if __name__ == '__main__':


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