Skip to content

Commit 4d48cf6

Browse files
authored
facts+operations/server: add mount support for FreeBSD
1 parent bfae135 commit 4d48cf6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pyinfra/facts/server.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

3+
import json
34
import os
5+
import platform
46
import re
57
import shutil
68
from datetime import datetime
@@ -206,7 +208,10 @@ class Mounts(FactBase[Dict[str, MountsDict]]):
206208

207209
@override
208210
def command(self):
209-
return "cat /proc/self/mountinfo"
211+
if platform.system() == "FreeBSD":
212+
return "mount -p --libxo json"
213+
else:
214+
return "cat /proc/self/mountinfo"
210215

211216
@override
212217
def process(self, output) -> dict[str, MountsDict]:
@@ -222,6 +227,21 @@ def replace_octal(s: str) -> str:
222227
"""
223228
return re.sub(r"\\[0-7]{3}", unescape_octal, s)
224229

230+
if platform.system() == "FreeBSD":
231+
full_output = "\n".join(output)
232+
json_output = json.loads(full_output)
233+
mount_fstab = json_output["mount"]["fstab"]
234+
235+
for entry in mount_fstab:
236+
path = entry["mntpoint"]
237+
type_ = entry["fstype"]
238+
device = entry["device"]
239+
options = [option.strip() for option in entry["opts"].split(",")]
240+
241+
devices[path] = {"device": device, "type": type_, "options": options}
242+
243+
return devices
244+
225245
for line in output:
226246
# ignore mount ID, parent ID, major:minor, root
227247
_, _, _, _, mount_point, mount_options, line = line.split(sep=" ", maxsplit=6)

pyinfra/operations/server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import platform
89
from io import StringIO
910
from itertools import filterfalse, tee
1011
from os import path
@@ -335,7 +336,15 @@ def mount(
335336
mounted_options = mounts[path]["options"]
336337
needed_options = set(options) - set(mounted_options)
337338
if needed_options:
338-
yield "mount -o remount,{0} {1}".format(options_string, path)
339+
if platform.system() == "FreeBSD":
340+
fs_type = mounts[path]["type"]
341+
device = mounts[path]["device"]
342+
343+
yield "mount -o update,{options} -t {fs_type} {device} {path}".format(
344+
options=options_string, fs_type=fs_type, device=device, path=path
345+
)
346+
else:
347+
yield "mount -o remount,{0} {1}".format(options_string, path)
339348

340349
else:
341350
host.noop(

0 commit comments

Comments
 (0)