nuageinit: implement resolv_conf support
Add support for the 'resolv_conf' cloud-config key which writes directly to /etc/resolv.conf.
This commit is contained in:
@@ -837,6 +837,37 @@ local function add_fstab_entry(root, device, mount_point, fstype, options, dump_
|
||||
return true
|
||||
end
|
||||
|
||||
local function write_resolv_conf(root, config)
|
||||
local path = root .. "/etc/resolv.conf"
|
||||
local f = io.open(path, "w")
|
||||
if not f then
|
||||
warnmsg("unable to open " .. path .. " for writing")
|
||||
return
|
||||
end
|
||||
if config.domain then
|
||||
f:write("domain " .. config.domain .. "\n")
|
||||
end
|
||||
if config.searchdomains then
|
||||
f:write("search " .. table.concat(config.searchdomains, " ") .. "\n")
|
||||
end
|
||||
if config.sortlist then
|
||||
f:write("sortlist " .. table.concat(config.sortlist, " ") .. "\n")
|
||||
end
|
||||
if config.options then
|
||||
local opts = {}
|
||||
for k, v in pairs(config.options) do
|
||||
table.insert(opts, k .. ":" .. v)
|
||||
end
|
||||
f:write("options " .. table.concat(opts, " ") .. "\n")
|
||||
end
|
||||
if config.nameservers then
|
||||
for _, ns in ipairs(config.nameservers) do
|
||||
f:write("nameserver " .. ns .. "\n")
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
|
||||
local function remove_fstab_entry(root, mount_point)
|
||||
local fstab_path = root .. "/etc/fstab"
|
||||
local f = io.open(fstab_path, "r")
|
||||
@@ -891,6 +922,7 @@ local n = {
|
||||
addfile = addfile,
|
||||
add_fstab_entry = add_fstab_entry,
|
||||
remove_fstab_entry = remove_fstab_entry,
|
||||
write_resolv_conf = write_resolv_conf,
|
||||
}
|
||||
|
||||
return n
|
||||
|
||||
@@ -531,6 +531,11 @@ local function disable_root(obj)
|
||||
end
|
||||
end
|
||||
|
||||
local function resolv_conf(obj)
|
||||
if obj.resolv_conf == nil then return end
|
||||
nuage.write_resolv_conf(root, obj.resolv_conf)
|
||||
end
|
||||
|
||||
local function mounts(obj)
|
||||
if obj.mounts == nil then return end
|
||||
for _, m in ipairs(obj.mounts) do
|
||||
@@ -870,6 +875,7 @@ elseif line == "#cloud-config" then
|
||||
ssh_deletekeys,
|
||||
ssh_keys,
|
||||
network_config,
|
||||
resolv_conf,
|
||||
disable_root,
|
||||
ssh_pwauth,
|
||||
runcmd,
|
||||
|
||||
@@ -195,6 +195,23 @@ The pass number for
|
||||
.Xr fsck 8 ,
|
||||
defaults to 0.
|
||||
.El
|
||||
.It Ic resolv_conf
|
||||
An object configuring the content of
|
||||
.Pa /etc/resolv.conf .
|
||||
.Pp
|
||||
The following keys are recognized:
|
||||
.Bl -tag -width "nameservers"
|
||||
.It nameservers
|
||||
A list of IP addresses for DNS name servers.
|
||||
.It searchdomains
|
||||
A list of search domains.
|
||||
.It domain
|
||||
A single domain name.
|
||||
.It sortlist
|
||||
A list of IP/netmask sortlist entries.
|
||||
.It options
|
||||
A dictionary of resolver options.
|
||||
.El
|
||||
.It Ic timezone
|
||||
Sets the system timezone based on the value provided.
|
||||
.Pp
|
||||
|
||||
@@ -35,6 +35,7 @@ atf_test_case config2_userdata_disable_root
|
||||
atf_test_case config2_userdata_bootcmd
|
||||
atf_test_case config2_userdata_manage_etc_hosts
|
||||
atf_test_case config2_userdata_mounts
|
||||
atf_test_case config2_userdata_resolv_conf
|
||||
atf_test_case config2_userdata_fqdn_and_hostname
|
||||
atf_test_case config2_userdata_write_files
|
||||
|
||||
@@ -1140,6 +1141,36 @@ EOF
|
||||
true
|
||||
}
|
||||
|
||||
config2_userdata_resolv_conf_head()
|
||||
{
|
||||
atf_set "require.user" root
|
||||
}
|
||||
config2_userdata_resolv_conf_body()
|
||||
{
|
||||
mkdir -p media/nuageinit
|
||||
setup_test_adduser
|
||||
printf "{}" > media/nuageinit/meta_data.json
|
||||
cat > media/nuageinit/user_data <<EOF
|
||||
#cloud-config
|
||||
resolv_conf:
|
||||
nameservers:
|
||||
- 9.9.9.9
|
||||
- 149.112.112.112
|
||||
searchdomains:
|
||||
- example.com
|
||||
- test.local
|
||||
domain: mydomain.local
|
||||
options:
|
||||
timeout: "1"
|
||||
attempts: "2"
|
||||
sortlist:
|
||||
- 192.168.1.0/255.255.255.0
|
||||
EOF
|
||||
atf_check -o empty /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2
|
||||
atf_check -o inline:"domain mydomain.local\nsearch example.com test.local\nsortlist 192.168.1.0/255.255.255.0\noptions timeout:1 attempts:2\nnameserver 9.9.9.9\nnameserver 149.112.112.112\n" cat etc/resolv.conf
|
||||
true
|
||||
}
|
||||
|
||||
config2_userdata_fqdn_and_hostname_body()
|
||||
{
|
||||
mkdir -p media/nuageinit
|
||||
@@ -1190,6 +1221,7 @@ atf_init_test_cases()
|
||||
atf_add_test_case config2_userdata_bootcmd
|
||||
atf_add_test_case config2_userdata_manage_etc_hosts
|
||||
atf_add_test_case config2_userdata_mounts
|
||||
atf_add_test_case config2_userdata_resolv_conf
|
||||
atf_add_test_case config2_userdata_fqdn_and_hostname
|
||||
atf_add_test_case config2_userdata_write_files
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user