nuageinit: implement ntp support
Add support for the 'ntp' cloud-config key which configures NTP by writing /etc/ntp.conf with server and pool entries.
This commit is contained in:
@@ -532,6 +532,42 @@ local function ssh_authkey_fingerprints(obj)
|
||||
end
|
||||
end
|
||||
|
||||
local function ntp(obj)
|
||||
if obj.ntp == nil then return end
|
||||
if type(obj.ntp) == "table" and obj.ntp.enabled == false then
|
||||
return
|
||||
end
|
||||
local servers = {}
|
||||
if type(obj.ntp) == "table" then
|
||||
if obj.ntp[1] then
|
||||
servers = obj.ntp
|
||||
else
|
||||
for _, s in ipairs(obj.ntp.servers or {}) do
|
||||
table.insert(servers, "server " .. s .. " iburst")
|
||||
end
|
||||
for _, p in ipairs(obj.ntp.pools or {}) do
|
||||
table.insert(servers, "pool " .. p .. " iburst")
|
||||
end
|
||||
end
|
||||
elseif type(obj.ntp) == "string" then
|
||||
table.insert(servers, "server " .. obj.ntp .. " iburst")
|
||||
end
|
||||
if #servers == 0 then return end
|
||||
local path = root .. "/etc/ntp.conf"
|
||||
local f = io.open(path, "w")
|
||||
if not f then
|
||||
warnmsg("unable to open " .. path .. " for writing")
|
||||
return
|
||||
end
|
||||
for _, line in ipairs(servers) do
|
||||
f:write(line .. "\n")
|
||||
end
|
||||
f:write("leapfile /var/db/ntpd.leap-seconds.list\n")
|
||||
f:write("restrict default limited kod nomodify notrap nopeer noquery\n")
|
||||
f:write("restrict source limited kod nomodify notrap noquery\n")
|
||||
f:close()
|
||||
end
|
||||
|
||||
local function ssh_deletekeys(obj)
|
||||
if obj.ssh_deletekeys == nil then return end
|
||||
if obj.ssh_deletekeys then
|
||||
@@ -931,6 +967,7 @@ elseif line == "#cloud-config" then
|
||||
}
|
||||
|
||||
local post_network_calls = {
|
||||
ntp,
|
||||
packages,
|
||||
users,
|
||||
chpasswd,
|
||||
|
||||
@@ -237,6 +237,27 @@ Boolean which determines whether fingerprints of SSH host keys
|
||||
should be logged to the console.
|
||||
Defaults to
|
||||
.Ar false .
|
||||
.It Ic ntp
|
||||
An object configuring the NTP daemon by writing
|
||||
.Pa /etc/ntp.conf .
|
||||
.Pp
|
||||
The following keys are recognized:
|
||||
.Bl -tag -width "enabled"
|
||||
.It servers
|
||||
A list of NTP server addresses.
|
||||
.It pools
|
||||
A list of NTP pool addresses.
|
||||
.It enabled
|
||||
Boolean, defaults to
|
||||
.Ar true .
|
||||
Set to
|
||||
.Ar false
|
||||
to skip NTP configuration.
|
||||
.El
|
||||
.Pp
|
||||
Alternatively,
|
||||
.Ic ntp
|
||||
can be a list of server addresses (legacy format).
|
||||
.It Ic timezone
|
||||
Sets the system timezone based on the value provided.
|
||||
.Pp
|
||||
|
||||
@@ -38,6 +38,7 @@ atf_test_case config2_userdata_mounts
|
||||
atf_test_case config2_userdata_resolv_conf
|
||||
atf_test_case config2_userdata_keyboard
|
||||
atf_test_case config2_userdata_ssh_authkey_fingerprints
|
||||
atf_test_case config2_userdata_ntp
|
||||
atf_test_case config2_userdata_fqdn_and_hostname
|
||||
atf_test_case config2_userdata_write_files
|
||||
|
||||
@@ -1218,6 +1219,32 @@ EOF
|
||||
true
|
||||
}
|
||||
|
||||
config2_userdata_ntp_head()
|
||||
{
|
||||
atf_set "require.user" root
|
||||
}
|
||||
config2_userdata_ntp_body()
|
||||
{
|
||||
mkdir -p media/nuageinit
|
||||
setup_test_adduser
|
||||
printf "{}" > media/nuageinit/meta_data.json
|
||||
cat > media/nuageinit/user_data <<EOF
|
||||
#cloud-config
|
||||
ntp:
|
||||
servers:
|
||||
- 192.168.1.1
|
||||
- 10.0.0.1
|
||||
pools:
|
||||
- 0.pool.ntp.org
|
||||
EOF
|
||||
atf_check -o empty /usr/libexec/nuageinit "${PWD}"/media/nuageinit postnet
|
||||
atf_check -o match:"server 192.168.1.1 iburst" cat etc/ntp.conf
|
||||
atf_check -o match:"server 10.0.0.1 iburst" cat etc/ntp.conf
|
||||
atf_check -o match:"pool 0.pool.ntp.org iburst" cat etc/ntp.conf
|
||||
atf_check -o match:"leapfile /var/db/ntpd.leap-seconds.list" cat etc/ntp.conf
|
||||
true
|
||||
}
|
||||
|
||||
config2_userdata_fqdn_and_hostname_body()
|
||||
{
|
||||
mkdir -p media/nuageinit
|
||||
@@ -1271,6 +1298,7 @@ atf_init_test_cases()
|
||||
atf_add_test_case config2_userdata_resolv_conf
|
||||
atf_add_test_case config2_userdata_keyboard
|
||||
atf_add_test_case config2_userdata_ssh_authkey_fingerprints
|
||||
atf_add_test_case config2_userdata_ntp
|
||||
atf_add_test_case config2_userdata_fqdn_and_hostname
|
||||
atf_add_test_case config2_userdata_write_files
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user