Skip to content

Commit e572531

Browse files
author
Romain LE DISEZ
committed
Add an option to setup mountpoints when fetching a plugin
Add the option --mountpoints/-M to the fetch subcommand. It gives the possibility to setup one or many mountpoints at the jail creation of a plugin, before the initial start. It mimicks the format of the Docker --volume option: source:destination[:options] Example: iocage fetch -P ./plugin.json -M /mnt/tank/plugin-data:/data:ro
1 parent ea74589 commit e572531

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

iocage_cli/fetch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ def validate_count(ctx, param, value):
150150
'--proxy', '-S', default=None,
151151
help='Provide proxy to use for creating jail'
152152
)
153+
@click.option(
154+
"--mountpoints", "-M", multiple=True,
155+
help="Specify a mountpoint to setup in the jail. Format is "
156+
"source:destination[:options].\n(only applicable if "
157+
"fetching a plugin)"
158+
)
153159
def cli(**kwargs):
154160
"""CLI command that calls fetch_release()"""
155161
release = kwargs.get("release", None)

iocage_lib/ioc_plugin.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import iocage_lib.ioc_create
4747
import iocage_lib.ioc_destroy
4848
import iocage_lib.ioc_exec
49+
import iocage_lib.ioc_fstab
4950
import iocage_lib.ioc_list
5051
import iocage_lib.ioc_json
5152
import iocage_lib.ioc_start
@@ -94,6 +95,7 @@ def __init__(
9495
self.plugin_json_path = None
9596
self.plugin = plugin
9697
self.jail = jail
98+
self.mountpoints = kwargs.pop("mountpoints", [])
9799
self.http = kwargs.pop("http", True)
98100
self.hardened = kwargs.pop("hardened", False)
99101
self.date = datetime.datetime.utcnow().strftime("%F")
@@ -321,6 +323,7 @@ def fetch_plugin(self, props, num, accept_license):
321323

322324
try:
323325
jaildir, _conf, repo_dir = self.__fetch_plugin_create__(props)
326+
self.__fetch_plugin_add_mountpoints__(jaildir)
324327
# As soon as we create the jail, we should write the plugin manifest to jail directory
325328
# This is done to ensure that subsequent starts of the jail make use of the plugin
326329
# manifest as required
@@ -607,6 +610,52 @@ def __fetch_plugin_create__(self, create_props):
607610

608611
return jaildir, _conf, repo_dir
609612

613+
def __fetch_plugin_add_mountpoints__(self, jaildir):
614+
for mountpoint in self.mountpoints:
615+
fstype = "nullfs"
616+
options = "rw"
617+
dump = "0"
618+
_pass = "0"
619+
620+
parts = mountpoint.split(":")
621+
if len(parts) < 2 or len(parts) > 3:
622+
raise RuntimeError(
623+
f"Ignoring invalid mountpoint `{mountpoint}`, expecting "
624+
"`source:destination[:options]`."
625+
)
626+
else:
627+
source = parts[0].strip()
628+
destination = parts[1].strip()
629+
if len(parts) == 3:
630+
options = parts[2]
631+
632+
if (not source or source[0] != "/"
633+
or not destination or destination[0] != "/"
634+
or not options):
635+
raise RuntimeError(
636+
f"Ignoring invalid mountpoint `{mountpoint}`, source and "
637+
"destination must be absolute path, options cannot be "
638+
"empty."
639+
)
640+
641+
destination = f"{jaildir}/root{destination}"
642+
if destination and len(destination) > 88:
643+
iocage_lib.ioc_common.logit(
644+
{
645+
"level":
646+
"WARNING",
647+
"message":
648+
"The destination's mountpoint exceeds 88 "
649+
"characters, this may cause failure!"
650+
},
651+
silent=self.silent)
652+
653+
os.makedirs(destination, exist_ok=True)
654+
iocage_lib.ioc_fstab.IOCFstab(
655+
self.jail, "add", source, destination,
656+
fstype, options, dump, _pass
657+
)
658+
610659
def __fetch_plugin_install_packages__(self, jaildir, conf, pkg_repos,
611660
create_props, repo_dir):
612661
"""Attempts to start the jail and install the packages"""

0 commit comments

Comments
 (0)