Re: [sandbox PATCH 1/1] Add support for adding mountpoints via the command line.

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

 



On Thu, May 09, 2013 at 02:02:14PM -0400, dwalsh@xxxxxxxxxx wrote:
> From: Dan Walsh <dwalsh@xxxxxxxxxx>
> 
> Add similar support to virt-sandbox-service that is in virt-sandbox
> to add guest-bind, host-bind and host-image mount points on the command
> line.  Openshift wants to use this feature.
> ---
>  bin/virt-sandbox-service            | 62 ++++++++++++++++++++++++++++++++-----
>  bin/virt-sandbox-service-create.pod | 49 ++++++++++++++++++++++++++---
>  2 files changed, 98 insertions(+), 13 deletions(-)
> 
> diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service
> index d7f43a5..0ab6234 100755
> --- a/bin/virt-sandbox-service
> +++ b/bin/virt-sandbox-service
> @@ -76,6 +76,7 @@ class Container:
>          self.conn = None
>          self.image = None
>          self.uid = 0
> +        self.mounts = None
>  
>      def get_file_type(self):
>          return self.file_type
> @@ -107,6 +108,21 @@ class Container:
>      def get_homedir(self):
>          return self.config.get_homedir()
>  
> +    def set_mounts(self, mounts):
> +        self.mounts = mounts
> +
> +    def get_mounts(self):
> +        return self.mounts
> +
> +    def add_mounts(self):
> +        for m in self.mounts:
> +            if m["type"] == "guest-bind":
> +                self.add_guest_bind_mount(m["src"], m["dest"])
> +            if m["type"] == "host-bind":
> +                self.add_host_bind_mount(m["src"], m["dest"])
> +            if m["type"] == "host-image":
> +                self.add_host_image_mount(m["src"], m["dest"])
> +
>      def get_config_path(self, name = None):
>          if not name:
>              name = self.name
> @@ -301,10 +317,18 @@ class Container:
>          except GLib.GError, e:
>              return 0
>  
> -    def add_bind_mount(self, source, dest):
> +    def add_host_bind_mount(self, source, dest):
>          mount = LibvirtSandbox.ConfigMountHostBind.new(source, dest)
>          self.config.add_mount(mount)
>  
> +    def add_guest_bind_mount(self, source, dest):
> +        mount = LibvirtSandbox.ConfigMountGuestBind.new(source, dest)
> +        self.config.add_mount(mount)
> +
> +    def add_host_image_mount(self, source, dest):
> +        mount = LibvirtSandbox.ConfigMountHostImage.new(source, dest)
> +        self.config.add_mount(mount)


> @@ -1007,6 +1031,25 @@ class CheckUnit(argparse.Action):
>              unitfiles = [ (value, src) ]
>          setattr(namespace, self.dest, unitfiles)
>  
> +valid_mounts = { "host-bind", "host-image", "guest-bind" }
> +class AddMount(argparse.Action):
> +    def __call__(self, parser, namespace, values, option_string=None):
> +        mounts = getattr(namespace, self.dest)
> +        mrec = values.split(":")
> +        if mrec[0] not in valid_mounts:
> +            raise ValueError([_("Invalid mount type '%s'. Valid types %s." % ( mrec[0], ",".join(valid_mounts)))])
> +        try:
> +            dest,src = mrec[1].split("=");
> +            mdict = {"type":mrec[0], "src": src, "dest":dest }
> +        except (IndexError, ValueError):
> +            raise ValueError([_("Invalid mount '%s' specification.") % values ])
> +
> +        if mounts:
> +            mounts.append(mdict)
> +        else:
> +            mounts = [mdict]
> +        setattr(namespace, self.dest, mounts)


You shouldn't be doing any of this parsing yourself. The
GVirSandboxConfig class has an API for this. By using that
we ensure the syntax is identical to that used by the
virt-sandbox command. Call  config.add_mount_opts(string)
for the option arg, or config.add_mount_strv(string-array)
if you want to parse all options at once.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

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