[libvirt] [sandbox PATCH] Add support for virt-sandbox-service to add additional mount points.

dwalsh at redhat.com dwalsh at redhat.com
Fri May 10 19:05:15 UTC 2013


From: Dan Walsh <dwalsh at redhat.com>

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 needs feature.
---
 bin/virt-sandbox-service                    | 15 +++++++++
 bin/virt-sandbox-service-bash-completion.sh |  4 ++-
 bin/virt-sandbox-service-create.pod         | 49 ++++++++++++++++++++++++++---
 3 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service
index 942f788..4496b29 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 = []
 
     def get_file_type(self):
         return self.file_type
@@ -107,6 +108,15 @@ 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):
+        self.config.add_mount_strv(self.mounts)
+
     def get_config_path(self, name = None):
         if not name:
             name = self.name
@@ -319,6 +329,7 @@ class GenericContainer(Container):
     def gen_filesystems(self):
         Container.gen_filesystems(self)
         self.add_bind_mount(self.dest, self.path)
+        self.add_mounts()
 
     def create_generic(self):
         Container.create(self)
@@ -627,6 +638,7 @@ WantedBy=%(TARGET)s
             if not found:
                 source = "%s%s" % ( self.dest, d)
                 self.add_bind_mount(source, d)
+        self.add_mounts()
 
     def get_expanded_unit_template(self, unit):
         return unit.replace('@', '@' + self.name)
@@ -829,6 +841,7 @@ def create(args):
     container.set_gid(args.gid)
     container.set_path(args.path)
     container.set_file_type(args.file_type)
+    container.set_mounts(args.mounts)
     if args.imagesize:
         container.set_image(args.imagesize)
 
@@ -1053,6 +1066,8 @@ def gen_create_args(subparser):
     parser.add_argument("-i", "--imagesize", dest="imagesize", default = None,
                        action=SizeAction,
                        help=_("create image of this many megabytes."))
+    parser.add_argument("-m", "--mount", dest="mounts",default=[], nargs="*",
+                        help=_("Mount a filesytem in the sandbox"))
     parser.add_argument("-N", "--network", dest="network",
                         action=SetNet, default=[],
                         help=_("Specify the network configuration"))
diff --git a/bin/virt-sandbox-service-bash-completion.sh b/bin/virt-sandbox-service-bash-completion.sh
index 8f2b6d0..a101f4a 100755
--- a/bin/virt-sandbox-service-bash-completion.sh
+++ b/bin/virt-sandbox-service-bash-completion.sh
@@ -57,7 +57,7 @@ _virt_sandbox_service () {
     )
     local -A OPTS=(
         [ALL]='-h --help'
-        [CREATE]='-C --copy -f --filetype -G --gid  -i --imagesize --homedir -N --network -p --path -s --security -u --unitfile --username -U -uid'
+        [CREATE]='-C --copy -f --filetype -G --gid  -i --imagesize --homedir -m --mount -N --network -p --path -s --security -u --unitfile --username -U -uid'
         [LIST]='-r --running'
         [RELOAD]='-u --unitfile'
         [EXECUTE]='-N --noseclabel'
@@ -116,6 +116,8 @@ _virt_sandbox_service () {
         return 0
         elif test "$prev" = "-s" || test "$prev" = "--security" ; then
         return 0
+        elif test "$prev" = "-m" || test "$prev" = "--mount" ; then
+        return 0
         elif test "$prev" = "-n" || test "$prev" = "--network" ; then
         return 0
         elif test "$prev" = "-i" || test "$prev" = "--imagesize" ; then
diff --git a/bin/virt-sandbox-service-create.pod b/bin/virt-sandbox-service-create.pod
index 942c919..fb1cb62 100644
--- a/bin/virt-sandbox-service-create.pod
+++ b/bin/virt-sandbox-service-create.pod
@@ -5,11 +5,12 @@ virt-sandbox-service create - Create a Security container
 =head1 SYNOPSIS
 
   virt-sandbox-service [-c URI] create [-h] [-C] [-f FILE_TYPE]
-				   [--homedir HOMEDIR] [-G GID] [-i IMAGESIZE]
-				   [-N NETWORK] [-p PATH] [-s SECURITY]
-				   [-u UNITFILES] [--username USERNAME]
-				   [-U UID] [-P package]
-				   name [command [command ...]]
+                                   [--homedir HOMEDIR] [-G GID] [-i IMAGESIZE]
+                                   [[-m TYPE:DST=SRC ] ...]
+                                   [-N NETWORK] [-p PATH] [-s SECURITY]
+                                   [[-u UNITFILES] ...] [--username USERNAME]
+                                   [-U UID] [-P package]
+                                   name [command [command ...]]
 
 =head1 DESCRIPTION
 
@@ -67,6 +68,44 @@ Set homedir path to use within container.
 
 Default: C<UID's Homedir>.
 
+=item B<-m TYPE:DST=SRC>, B<--mount TYPE:DST=SRC>
+
+Sets up a mount inside the sandbox at B<DST> backed by B<SRC>. The meaning of B<SRC> depends on the value of "TYPE" specified:
+
+=over 4
+
+=item host-bind
+
+If B<TYPE> is B<host-bind>, then B<SRC> is interpreted as the path to a directory on the host filesystem. If "SRC" is the empty string, then a temporary (empty) directory is created on the host before starting the sandbox and deleted afterwards. The "--include" option is useful for populating these temporary directories with copies of host files.
+
+=back
+
+=over 4
+
+=item host-image
+
+If B<TYPE> is B<host-image>, then B<SRC> is interpreted as the path to a disk image file on the host filesystem. The image should be formatted with a filesystem that can be auto-detected by the sandbox, such as B<ext3, ext4>, etc. The disk image itself should be a raw file, not qcow2 or any other special format
+
+=back
+
+=over 4
+
+=item guest-bind
+
+If B<TYPE> is B<guest-bind>, then B<SRC> is interpreted as the path to another directory in the container filesystem.
+
+=back
+
+=over 4
+
+=item Some examples
+
+    -m host-bind:/tmp=/var/lib/sandbox/demo/tmp
+    -m host-image:/=/var/lib/sandbox/demo.img
+    -m guest-bind:/home=/tmp/home
+
+=back
+
 =item B<-N NETWORK-OPTIONS>, B<--network NETWORK-OPTIONS>
 
 Add a network interface to the sandbox. By default the sandbox will
-- 
1.8.2.1




More information about the libvir-list mailing list