stages: add org.osbuild.resolv-conf
Add new stage that can be used to configure the resolver(3) via the /etc/resolv.conf(5) configuration file.
This commit is contained in:
parent
99160ad369
commit
a44a9ab04c
1 changed files with 68 additions and 0 deletions
68
stages/org.osbuild.resolv-conf
Executable file
68
stages/org.osbuild.resolv-conf
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Configure the resolver
|
||||
|
||||
This stage configures the resolver(3) via the resolv.conf(5)
|
||||
configure file. See the man page for more details. Currently
|
||||
only a subset of options are supported. If no options are
|
||||
specified but the stage is included it will create an empty
|
||||
`/etc/resolv.conf` file.
|
||||
"""
|
||||
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
import osbuild.api
|
||||
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"nameserver": {
|
||||
"description": "Array of IP addresses the resolver should query",
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"search": {
|
||||
"description": "Array of ",
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def main(tree, options):
|
||||
nameserver = options.get("nameserver", [])
|
||||
search = options.get("search", [])
|
||||
|
||||
filepath = "etc/resolv.conf"
|
||||
fullpath = os.path.join(tree, filepath)
|
||||
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.remove(fullpath)
|
||||
print(f"Replacing existing file: /{filepath}")
|
||||
|
||||
data = ["# This file was created by osbuild"]
|
||||
|
||||
if search:
|
||||
data += [
|
||||
"search " + " ".join(search)
|
||||
]
|
||||
|
||||
for ns in nameserver:
|
||||
data += ["nameserver " + str(ns)]
|
||||
|
||||
os.makedirs(os.path.join(tree, "etc"), exist_ok=True)
|
||||
with open(fullpath, "w") as f:
|
||||
f.write("\n".join(data) + "\n")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = osbuild.api.arguments()
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
Loading…
Add table
Add a link
Reference in a new issue