From 6a8768fb2f872ef3808bd8fab8f0fe73ac69a132 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 10 Oct 2020 16:37:33 +0200 Subject: [PATCH] bundles/nfs-client: introduce --- bundles/nfs-client/files/nfs.automount | 6 +++ bundles/nfs-client/files/nfs.mount | 14 +++++++ bundles/nfs-client/items.py | 55 ++++++++++++++++++++++++++ bundles/nfs-client/metadata.py | 7 ++++ nodes/home/kodi-wohnzimmer.py | 16 +++++--- 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 bundles/nfs-client/files/nfs.automount create mode 100644 bundles/nfs-client/files/nfs.mount create mode 100644 bundles/nfs-client/items.py create mode 100644 bundles/nfs-client/metadata.py diff --git a/bundles/nfs-client/files/nfs.automount b/bundles/nfs-client/files/nfs.automount new file mode 100644 index 0000000..46d68d9 --- /dev/null +++ b/bundles/nfs-client/files/nfs.automount @@ -0,0 +1,6 @@ +[Unit] +Description=Automount ${mount} on access + +[Automount] +Where=${mountpoint} +TimeoutIdleSec=5min diff --git a/bundles/nfs-client/files/nfs.mount b/bundles/nfs-client/files/nfs.mount new file mode 100644 index 0000000..da4823a --- /dev/null +++ b/bundles/nfs-client/files/nfs.mount @@ -0,0 +1,14 @@ +[Unit] +Description=Mount ${mount} + +After=network.target + + +[Mount] +What=${serverpath} +Where=${mountpoint} +Type=nfs +Options=${','.join(sorted(mount_options))} + +[Install] +WantedBy=multi-user.target diff --git a/bundles/nfs-client/items.py b/bundles/nfs-client/items.py new file mode 100644 index 0000000..f71b405 --- /dev/null +++ b/bundles/nfs-client/items.py @@ -0,0 +1,55 @@ +for mount, data in node.metadata.get('nfs-client',{}).get('mounts',{}).items(): + data['mount'] = mount + data['mount_options'] = set(data.get('mount_options', set())) + + unitname = data.get('mountpoint','')[1:].replace('-','\\x2d').replace('/','-') + + directories[data['mountpoint']] = {} + + for parameter in ['mode', 'owner', 'group']: + if parameter in data: + directories[data['mountpoint']][parameter] = data[parameter] + + if data.get('automount', True): + data['mount_options'].add('x-systemd.automount') + + files['/etc/systemd/system/{}.automount'.format(unitname)] = { + 'mode': "0644", + 'owner': "root", + 'group': "root", + 'source': "nfs.automount", + 'content_type': 'mako', + 'context': data, + 'triggers': { + "action:systemd-reload", + }, + } + + svc_systemd['{}.automount'.format(unitname)] = { + 'needs': { + 'file:/etc/systemd/system/{}.mount'.format(unitname), + 'file:/etc/systemd/system/{}.automount'.format(unitname), + 'directory:{}'.format(data['mountpoint']), + 'pkg_apt:nfs-common', + }, + } + else: + svc_systemd['{}.mount'.format(unitname)] = { + 'needs': { + 'file:/etc/systemd/system/{}.mount'.format(unitname), + 'directory:{}'.format(data['mountpoint']), + 'pkg_apt:nfs-common', + }, + } + + files['/etc/systemd/system/{}.mount'.format(unitname)] = { + 'mode': "0644", + 'owner': "root", + 'group': "root", + 'source': "nfs.mount", + 'content_type': 'mako', + 'context': data, + 'triggers': { + "action:systemd-reload", + }, + } diff --git a/bundles/nfs-client/metadata.py b/bundles/nfs-client/metadata.py new file mode 100644 index 0000000..00ffd00 --- /dev/null +++ b/bundles/nfs-client/metadata.py @@ -0,0 +1,7 @@ +defaults = { + 'apt': { + 'packages': { + 'nfs-common': {}, + }, + }, +} diff --git a/nodes/home/kodi-wohnzimmer.py b/nodes/home/kodi-wohnzimmer.py index 91606e6..55a396c 100644 --- a/nodes/home/kodi-wohnzimmer.py +++ b/nodes/home/kodi-wohnzimmer.py @@ -2,6 +2,7 @@ nodes['home.kodi-wohnzimmer'] = { 'hostname': '172.19.138.24', 'bundles': { 'kodi', + 'nfs-client', }, 'groups': set(), 'metadata': { @@ -15,11 +16,16 @@ nodes['home.kodi-wohnzimmer'] = { 'mac': '94:C6:91:1E:B8:1F', }, }, - 'apt': { - 'packages': { - # This node mounts the NAS via NFS. Configured manually, - # because i'm lazy. - 'nfs-common': {}, + 'nfs-client': { + 'mounts': { + 'nas-storage': { + 'mountpoint': '/mnt/nas', + 'serverpath': '172.19.138.20:/storage/nas', + 'mount_options': { + 'retry=0', + 'ro', + }, + }, }, }, 'vm': {