diff options
author | Chen Hanxiao <chenhanxiao@cn.fujitsu.com> | 2014-02-09 23:25:25 +0800 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2014-02-09 13:16:34 -0500 |
commit | fcac052cdc987cd1b6429860ba53a47507de3f07 (patch) | |
tree | 78f4e6781a9a253b017e6b68491817672092c036 /virtinst | |
parent | e067051287bcc4588d0ef18a5cd708d04f015df8 (diff) | |
download | virt-manager-fcac052cdc987cd1b6429860ba53a47507de3f07.tar.gz |
virt-install: add support for user namespace
This patch will enable configuring idmap.
It could be used as enable user namespace
for LXC containers.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Diffstat (limited to 'virtinst')
-rw-r--r-- | virtinst/__init__.py | 1 | ||||
-rw-r--r-- | virtinst/cli.py | 24 | ||||
-rw-r--r-- | virtinst/guest.py | 6 | ||||
-rw-r--r-- | virtinst/idmap.py | 37 |
4 files changed, 66 insertions, 2 deletions
diff --git a/virtinst/__init__.py b/virtinst/__init__.py index b9186e0d..62b6b364 100644 --- a/virtinst/__init__.py +++ b/virtinst/__init__.py @@ -31,6 +31,7 @@ from virtinst.clock import Clock from virtinst.cpu import CPU, CPUFeature from virtinst.seclabel import Seclabel from virtinst.pm import PM +from virtinst.idmap import IdMap import virtinst.capabilities as CapabilitiesParser from virtinst.interface import Interface, InterfaceProtocol diff --git a/virtinst/cli.py b/virtinst/cli.py index 6b0c12ac..09e24174 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -802,6 +802,12 @@ def add_disk_option(stog, editexample=False): "--disk=?") + editmsg) +def add_idmap_option(insg): + insg.add_argument("--idmap", + help=_("Enable user namespace for LXC container. Ex.\n" + "--idmap uid_start=0,uid_target=1000,uid_count=10,gid_start=0,gid_target=1000,gid_count=10")) + + ############################################# # CLI complex parsing helpers # # (for options like --disk, --network, etc. # @@ -1400,6 +1406,23 @@ class ParserBoot(VirtCLIParser): ###################### +# --idmap parsing # +###################### + +class ParserIdmap(VirtCLIParser): + def _init_params(self): + self.clear_attr = "idmap" + + self.set_param("idmap.uid_start", "uid_start") + self.set_param("idmap.uid_target", "uid_target") + self.set_param("idmap.uid_count", "uid_count") + + self.set_param("idmap.gid_start", "gid_start") + self.set_param("idmap.gid_target", "gid_target") + self.set_param("idmap.gid_count", "gid_count") + + +###################### # --security parsing # ###################### @@ -2129,6 +2152,7 @@ def build_parser_map(options, skip=None, only=None): register_parser("cpu", ParserCPU) register_parser("numatune", ParserNumatune) register_parser("blkiotune", ParserBlkiotune) + register_parser("idmap", ParserIdmap) register_parser("boot", ParserBoot) register_parser("security", ParserSecurity) register_parser("features", ParserFeatures) diff --git a/virtinst/guest.py b/virtinst/guest.py index d55c2a0e..0cbda08e 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -38,6 +38,7 @@ from virtinst import DomainNumatune from virtinst import DomainBlkiotune from virtinst import DomainFeatures from virtinst import PM +from virtinst import IdMap from virtinst.xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty from virtinst import osdict @@ -91,8 +92,8 @@ class Guest(XMLBuilder): _XML_ROOT_NAME = "domain" _XML_PROP_ORDER = ["type", "name", "uuid", "title", "description", "maxmemory", "memory", "hugepage", "vcpus", "curvcpus", - "numatune", "blkiotune", "bootloader", "os", "features", "cpu", "clock", - "on_poweroff", "on_reboot", "on_crash", "pm", "emulator", "_devices", + "numatune", "blkiotune", "bootloader", "os", "idmap", "features", "cpu", + "clock", "on_poweroff", "on_reboot", "on_crash", "pm", "emulator", "_devices", "seclabel"] def __init__(self, *args, **kwargs): @@ -191,6 +192,7 @@ class Guest(XMLBuilder): numatune = XMLChildProperty(DomainNumatune, is_single=True) pm = XMLChildProperty(PM, is_single=True) blkiotune = XMLChildProperty(DomainBlkiotune, is_single=True) + idmap = XMLChildProperty(IdMap, is_single=True) ############################### diff --git a/virtinst/idmap.py b/virtinst/idmap.py new file mode 100644 index 00000000..dae499ec --- /dev/null +++ b/virtinst/idmap.py @@ -0,0 +1,37 @@ +# +# Copyright 2014 Fujitsu Limited. +# Chen Hanxiao <chenhanxiao at cn.fujitsu.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA. + +from virtinst.xmlbuilder import XMLBuilder, XMLProperty + + +class IdMap(XMLBuilder): + """ + Class for generating user namespace related XML + """ + _XML_ROOT_NAME = "idmap" + _XML_PROP_ORDER = ["uid_start", "uid_target", "uid_count", + "gid_start", "gid_target", "gid_count"] + + uid_start = XMLProperty("./uid/@start", is_int=True) + uid_target = XMLProperty("./uid/@target", is_int=True) + uid_count = XMLProperty("./uid/@count", is_int=True) + + gid_start = XMLProperty("./gid/@start", is_int=True) + gid_target = XMLProperty("./gid/@target", is_int=True) + gid_count = XMLProperty("./gid/@count", is_int=True) |