nuageinit: Lua check and lint files
Mostly white space, style, and luacheck compliance. Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
This commit is contained in:
committed by
Baptiste Daroussin
parent
99adbd1b3f
commit
504981357a
+30
-26
@@ -1,15 +1,17 @@
|
|||||||
|
---
|
||||||
-- SPDX-License-Identifier: BSD-2-Clause
|
-- SPDX-License-Identifier: BSD-2-Clause
|
||||||
--
|
--
|
||||||
-- Copyright(c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
-- Copyright(c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
||||||
|
|
||||||
|
local lfs = require("lfs")
|
||||||
local pu = require("posix.unistd")
|
local pu = require("posix.unistd")
|
||||||
|
|
||||||
local function warnmsg(str)
|
local function warnmsg(str)
|
||||||
io.stderr:write(str.."\n")
|
io.stderr:write(str .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function errmsg(str)
|
local function errmsg(str)
|
||||||
io.stderr:write(str.."\n")
|
io.stderr:write(str .. "\n")
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -28,15 +30,17 @@ local function mkdir_p(path)
|
|||||||
if lfs.attributes(path, "mode") ~= nil then
|
if lfs.attributes(path, "mode") ~= nil then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local r,err = mkdir_p(dirname(path))
|
local r, err = mkdir_p(dirname(path))
|
||||||
if not r then
|
if not r then
|
||||||
return nil,err.." (creating "..path..")"
|
return nil, err .. " (creating " .. path .. ")"
|
||||||
end
|
end
|
||||||
return lfs.mkdir(path)
|
return lfs.mkdir(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function sethostname(hostname)
|
local function sethostname(hostname)
|
||||||
if hostname == nil then return end
|
if hostname == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
local root = os.getenv("NUAGE_FAKE_ROOTDIR")
|
local root = os.getenv("NUAGE_FAKE_ROOTDIR")
|
||||||
if not root then
|
if not root then
|
||||||
root = ""
|
root = ""
|
||||||
@@ -44,12 +48,12 @@ local function sethostname(hostname)
|
|||||||
local hostnamepath = root .. "/etc/rc.conf.d/hostname"
|
local hostnamepath = root .. "/etc/rc.conf.d/hostname"
|
||||||
|
|
||||||
mkdir_p(dirname(hostnamepath))
|
mkdir_p(dirname(hostnamepath))
|
||||||
local f,err = io.open(hostnamepath, "w")
|
local f, err = io.open(hostnamepath, "w")
|
||||||
if not f then
|
if not f then
|
||||||
warnmsg("Impossible to open "..hostnamepath .. ":" ..err)
|
warnmsg("Impossible to open " .. hostnamepath .. ":" .. err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
f:write("hostname=\""..hostname.."\"\n")
|
f:write('hostname="' .. hostname .. '"\n')
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -62,7 +66,7 @@ local function splitlist(list)
|
|||||||
elseif type(list) == "table" then
|
elseif type(list) == "table" then
|
||||||
ret = list
|
ret = list
|
||||||
else
|
else
|
||||||
warnmsg("Invalid type ".. type(list) ..", expecting table or string")
|
warnmsg("Invalid type " .. type(list) .. ", expecting table or string")
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
@@ -77,7 +81,7 @@ local function adduser(pwd)
|
|||||||
if root then
|
if root then
|
||||||
cmd = cmd .. "-R " .. root .. " "
|
cmd = cmd .. "-R " .. root .. " "
|
||||||
end
|
end
|
||||||
local f = io.popen(cmd .. " usershow " ..pwd.name .. " -7 2>/dev/null")
|
local f = io.popen(cmd .. " usershow " .. pwd.name .. " -7 2> /dev/null")
|
||||||
local pwdstr = f:read("*a")
|
local pwdstr = f:read("*a")
|
||||||
f:close()
|
f:close()
|
||||||
if pwdstr:len() ~= 0 then
|
if pwdstr:len() ~= 0 then
|
||||||
@@ -89,10 +93,10 @@ local function adduser(pwd)
|
|||||||
if not pwd.homedir then
|
if not pwd.homedir then
|
||||||
pwd.homedir = "/home/" .. pwd.name
|
pwd.homedir = "/home/" .. pwd.name
|
||||||
end
|
end
|
||||||
local extraargs=""
|
local extraargs = ""
|
||||||
if pwd.groups then
|
if pwd.groups then
|
||||||
local list = splitlist(pwd.groups)
|
local list = splitlist(pwd.groups)
|
||||||
extraargs = " -G ".. table.concat(list, ',')
|
extraargs = " -G " .. table.concat(list, ",")
|
||||||
end
|
end
|
||||||
-- pw will automatically create a group named after the username
|
-- pw will automatically create a group named after the username
|
||||||
-- do not add a -g option in this case
|
-- do not add a -g option in this case
|
||||||
@@ -108,23 +112,23 @@ local function adduser(pwd)
|
|||||||
local precmd = ""
|
local precmd = ""
|
||||||
local postcmd = ""
|
local postcmd = ""
|
||||||
if pwd.passwd then
|
if pwd.passwd then
|
||||||
precmd = "echo "..pwd.passwd .. "| "
|
precmd = "echo " .. pwd.passwd .. "| "
|
||||||
postcmd = " -H 0 "
|
postcmd = " -H 0 "
|
||||||
elseif pwd.plain_text_passwd then
|
elseif pwd.plain_text_passwd then
|
||||||
precmd = "echo "..pwd.plain_text_passwd .. "| "
|
precmd = "echo " .. pwd.plain_text_passwd .. "| "
|
||||||
postcmd = " -h 0 "
|
postcmd = " -h 0 "
|
||||||
end
|
end
|
||||||
cmd = precmd .. "pw "
|
cmd = precmd .. "pw "
|
||||||
if root then
|
if root then
|
||||||
cmd = cmd .. "-R " .. root .. " "
|
cmd = cmd .. "-R " .. root .. " "
|
||||||
end
|
end
|
||||||
cmd = cmd .. "useradd -n ".. pwd.name .. " -M 0755 -w none "
|
cmd = cmd .. "useradd -n " .. pwd.name .. " -M 0755 -w none "
|
||||||
cmd = cmd .. extraargs .. " -c '".. pwd.gecos
|
cmd = cmd .. extraargs .. " -c '" .. pwd.gecos
|
||||||
cmd = cmd .. "' -d '" .. pwd.homedir .. "' -s "..pwd.shell .. postcmd
|
cmd = cmd .. "' -d '" .. pwd.homedir .. "' -s " .. pwd.shell .. postcmd
|
||||||
|
|
||||||
local r = os.execute(cmd)
|
local r = os.execute(cmd)
|
||||||
if not r then
|
if not r then
|
||||||
warnmsg("nuageinit: fail to add user "..pwd.name);
|
warnmsg("nuageinit: fail to add user " .. pwd.name)
|
||||||
warnmsg(cmd)
|
warnmsg(cmd)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -149,7 +153,7 @@ local function addgroup(grp)
|
|||||||
if root then
|
if root then
|
||||||
cmd = cmd .. "-R " .. root .. " "
|
cmd = cmd .. "-R " .. root .. " "
|
||||||
end
|
end
|
||||||
local f = io.popen(cmd .. " groupshow " ..grp.name .. " 2>/dev/null")
|
local f = io.popen(cmd .. " groupshow " .. grp.name .. " 2> /dev/null")
|
||||||
local grpstr = f:read("*a")
|
local grpstr = f:read("*a")
|
||||||
f:close()
|
f:close()
|
||||||
if grpstr:len() ~= 0 then
|
if grpstr:len() ~= 0 then
|
||||||
@@ -158,16 +162,16 @@ local function addgroup(grp)
|
|||||||
local extraargs = ""
|
local extraargs = ""
|
||||||
if grp.members then
|
if grp.members then
|
||||||
local list = splitlist(grp.members)
|
local list = splitlist(grp.members)
|
||||||
extraargs = " -M " .. table.concat(list, ',')
|
extraargs = " -M " .. table.concat(list, ",")
|
||||||
end
|
end
|
||||||
cmd = "pw "
|
cmd = "pw "
|
||||||
if root then
|
if root then
|
||||||
cmd = cmd .. "-R " .. root .. " "
|
cmd = cmd .. "-R " .. root .. " "
|
||||||
end
|
end
|
||||||
cmd = cmd .. "groupadd -n ".. grp.name .. extraargs
|
cmd = cmd .. "groupadd -n " .. grp.name .. extraargs
|
||||||
local r = os.execute(cmd)
|
local r = os.execute(cmd)
|
||||||
if not r then
|
if not r then
|
||||||
warnmsg("nuageinit: fail to add group ".. grp.name);
|
warnmsg("nuageinit: fail to add group " .. grp.name)
|
||||||
warnmsg(cmd)
|
warnmsg(cmd)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -196,7 +200,7 @@ local function addsshkey(homedir, key)
|
|||||||
|
|
||||||
local f = io.open(ak_path, "a")
|
local f = io.open(ak_path, "a")
|
||||||
if not f then
|
if not f then
|
||||||
warnmsg("nuageinit: impossible to open "..ak_path)
|
warnmsg("nuageinit: impossible to open " .. ak_path)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
f:write(key .. "\n")
|
f:write(key .. "\n")
|
||||||
@@ -214,12 +218,12 @@ end
|
|||||||
local n = {
|
local n = {
|
||||||
warn = warnmsg,
|
warn = warnmsg,
|
||||||
err = errmsg,
|
err = errmsg,
|
||||||
|
dirname = dirname,
|
||||||
|
mkdir_p = mkdir_p,
|
||||||
sethostname = sethostname,
|
sethostname = sethostname,
|
||||||
adduser = adduser,
|
adduser = adduser,
|
||||||
addgroup = addgroup,
|
addgroup = addgroup,
|
||||||
addsshkey = addsshkey,
|
addsshkey = addsshkey
|
||||||
dirname = dirname,
|
|
||||||
mkdir_p = mkdir_p,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return n
|
return n
|
||||||
|
|||||||
+85
-75
@@ -1,18 +1,18 @@
|
|||||||
#!/usr/libexec/flua
|
#!/usr/libexec/flua
|
||||||
|
---
|
||||||
-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||||
--
|
--
|
||||||
-- Copyright(c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
-- Copyright(c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
||||||
|
|
||||||
local nuage = require("nuage")
|
local nuage = require("nuage")
|
||||||
|
local ucl = require("ucl")
|
||||||
local yaml = require("yaml")
|
local yaml = require("yaml")
|
||||||
|
|
||||||
if #arg ~= 2 then
|
if #arg ~= 2 then
|
||||||
nuage.err("Usage ".. arg[0] .." <cloud-init directory> [config-2|nocloud]")
|
nuage.err("Usage " .. arg[0] .. " <cloud-init directory> [config-2|nocloud]")
|
||||||
end
|
end
|
||||||
local path = arg[1]
|
local path = arg[1]
|
||||||
local citype = arg[2]
|
local citype = arg[2]
|
||||||
local ucl = require("ucl")
|
|
||||||
|
|
||||||
local default_user = {
|
local default_user = {
|
||||||
name = "freebsd",
|
name = "freebsd",
|
||||||
@@ -30,9 +30,9 @@ end
|
|||||||
|
|
||||||
local function open_config(name)
|
local function open_config(name)
|
||||||
nuage.mkdir_p(root .. "/etc/rc.conf.d")
|
nuage.mkdir_p(root .. "/etc/rc.conf.d")
|
||||||
local f,err = io.open(root .. "/etc/rc.conf.d/" .. name, "w")
|
local f, err = io.open(root .. "/etc/rc.conf.d/" .. name, "w")
|
||||||
if not f then
|
if not f then
|
||||||
nuage.err("nuageinit: unable to open "..name.." config: " .. err)
|
nuage.err("nuageinit: unable to open " .. name .. " config: " .. err)
|
||||||
end
|
end
|
||||||
return f
|
return f
|
||||||
end
|
end
|
||||||
@@ -40,17 +40,17 @@ end
|
|||||||
local function get_ifaces()
|
local function get_ifaces()
|
||||||
local parser = ucl.parser()
|
local parser = ucl.parser()
|
||||||
-- grab ifaces
|
-- grab ifaces
|
||||||
local ns = io.popen('netstat -i --libxo json')
|
local ns = io.popen("netstat -i --libxo json")
|
||||||
local netres = ns:read("*a")
|
local netres = ns:read("*a")
|
||||||
ns:close()
|
ns:close()
|
||||||
local res,err = parser:parse_string(netres)
|
local res, err = parser:parse_string(netres)
|
||||||
if not res then
|
if not res then
|
||||||
nuage.warn("Error parsing netstat -i --libxo json outout: " .. err)
|
nuage.warn("Error parsing netstat -i --libxo json outout: " .. err)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local ifaces = parser:get_object()
|
local ifaces = parser:get_object()
|
||||||
local myifaces = {}
|
local myifaces = {}
|
||||||
for _,iface in pairs(ifaces["statistics"]["interface"]) do
|
for _, iface in pairs(ifaces["statistics"]["interface"]) do
|
||||||
if iface["network"]:match("<Link#%d>") then
|
if iface["network"]:match("<Link#%d>") then
|
||||||
local s = iface["address"]
|
local s = iface["address"]
|
||||||
myifaces[s:lower()] = iface["name"]
|
myifaces[s:lower()] = iface["name"]
|
||||||
@@ -67,7 +67,7 @@ local function config2_network(p)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
f:close()
|
f:close()
|
||||||
local res,err = parser:parse_file(p .. "/network_data.json")
|
local res, err = parser:parse_file(p .. "/network_data.json")
|
||||||
if not res then
|
if not res then
|
||||||
nuage.warn("nuageinit: error parsing network_data.json: " .. err)
|
nuage.warn("nuageinit: error parsing network_data.json: " .. err)
|
||||||
return
|
return
|
||||||
@@ -80,7 +80,7 @@ local function config2_network(p)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local mylinks = {}
|
local mylinks = {}
|
||||||
for _,v in pairs(obj["links"]) do
|
for _, v in pairs(obj["links"]) do
|
||||||
local s = v["ethernet_mac_address"]:lower()
|
local s = v["ethernet_mac_address"]:lower()
|
||||||
mylinks[v["id"]] = ifaces[s]
|
mylinks[v["id"]] = ifaces[s]
|
||||||
end
|
end
|
||||||
@@ -91,66 +91,72 @@ local function config2_network(p)
|
|||||||
local ipv6 = {}
|
local ipv6 = {}
|
||||||
local ipv6_routes = {}
|
local ipv6_routes = {}
|
||||||
local ipv4 = {}
|
local ipv4 = {}
|
||||||
for _,v in pairs(obj["networks"]) do
|
for _, v in pairs(obj["networks"]) do
|
||||||
local interface = mylinks[v["link"]]
|
local interface = mylinks[v["link"]]
|
||||||
if v["type"] == "ipv4_dhcp" then
|
if v["type"] == "ipv4_dhcp" then
|
||||||
network:write("ifconfig_"..interface.."=\"DHCP\"\n")
|
network:write("ifconfig_" .. interface .. '="DHCP"\n')
|
||||||
end
|
end
|
||||||
if v["type"] == "ipv4" then
|
if v["type"] == "ipv4" then
|
||||||
network:write("ifconfig_"..interface.."=\"inet "..v["ip_address"].." netmask " .. v["netmask"] .. "\"\n")
|
network:write(
|
||||||
|
"ifconfig_" .. interface .. '="inet ' .. v["ip_address"] .. " netmask " .. v["netmask"] .. '"\n'
|
||||||
|
)
|
||||||
if v["gateway"] then
|
if v["gateway"] then
|
||||||
routing:write("defaultrouter=\""..v["gateway"].."\"\n")
|
routing:write('defaultrouter="' .. v["gateway"] .. '"\n')
|
||||||
end
|
end
|
||||||
if v["routes"] then
|
if v["routes"] then
|
||||||
for i,r in ipairs(v["routes"]) do
|
for i, r in ipairs(v["routes"]) do
|
||||||
local rname = "cloudinit" .. i .. "_" .. interface
|
local rname = "cloudinit" .. i .. "_" .. interface
|
||||||
if v["gateway"] and v["gateway"] == r["gateway"] then goto next end
|
if v["gateway"] and v["gateway"] == r["gateway"] then
|
||||||
if r["network"] == "0.0.0.0" then
|
|
||||||
routing:write("defaultrouter=\""..r["gateway"].."\"\n")
|
|
||||||
goto next
|
goto next
|
||||||
end
|
end
|
||||||
routing:write("route_".. rname .. "=\"-net ".. r["network"] .. " ")
|
if r["network"] == "0.0.0.0" then
|
||||||
routing:write(r["gateway"] .. " " .. r["netmask"] .. "\"\n")
|
routing:write('defaultrouter="' .. r["gateway"] .. '"\n')
|
||||||
|
goto next
|
||||||
|
end
|
||||||
|
routing:write("route_" .. rname .. '="-net ' .. r["network"] .. " ")
|
||||||
|
routing:write(r["gateway"] .. " " .. r["netmask"] .. '"\n')
|
||||||
ipv4[#ipv4 + 1] = rname
|
ipv4[#ipv4 + 1] = rname
|
||||||
::next::
|
::next::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if v["type"] == "ipv6" then
|
if v["type"] == "ipv6" then
|
||||||
ipv6[#ipv6+1] = interface
|
ipv6[#ipv6 + 1] = interface
|
||||||
ipv6_routes[#ipv6_routes+1] = interface
|
ipv6_routes[#ipv6_routes + 1] = interface
|
||||||
network:write("ifconfig_"..interface.."_ipv6=\"inet6 "..v["ip_address"].."\"\n")
|
network:write("ifconfig_" .. interface .. '_ipv6="inet6 ' .. v["ip_address"] .. '"\n')
|
||||||
if v["gateway"] then
|
if v["gateway"] then
|
||||||
routing:write("ipv6_defaultrouter=\""..v["gateway"].."\"\n")
|
routing:write('ipv6_defaultrouter="' .. v["gateway"] .. '"\n')
|
||||||
routing:write("ipv6_route_"..interface.."=\""..v["gateway"])
|
routing:write("ipv6_route_" .. interface .. '="' .. v["gateway"])
|
||||||
routing:write(" -prefixlen 128 -interface "..interface.."\"\n")
|
routing:write(" -prefixlen 128 -interface " .. interface .. '"\n')
|
||||||
end
|
end
|
||||||
-- TODO compute the prefixlen for the routes
|
-- TODO compute the prefixlen for the routes
|
||||||
--if v["routes"] then
|
--if v["routes"] then
|
||||||
-- for i,r in ipairs(v["routes"]) do
|
-- for i, r in ipairs(v["routes"]) do
|
||||||
-- local rname = "cloudinit" .. i .. "_" .. mylinks[v["link"]]
|
-- local rname = "cloudinit" .. i .. "_" .. mylinks[v["link"]]
|
||||||
-- -- skip all the routes which are already covered by the default gateway, some provider
|
-- -- skip all the routes which are already covered by the default gateway, some provider
|
||||||
-- -- still list plenty of them.
|
-- -- still list plenty of them.
|
||||||
-- if v["gateway"] == r["gateway"] then goto next end
|
-- if v["gateway"] == r["gateway"] then
|
||||||
-- routing:write("ipv6_route_" .. rname .. "\"\n")
|
-- goto next
|
||||||
-- ipv6_routes[#ipv6_routes+1] = rname
|
-- end
|
||||||
|
-- routing:write("ipv6_route_" .. rname .. '"\n')
|
||||||
|
-- ipv6_routes[#ipv6_routes + 1] = rname
|
||||||
-- ::next::
|
-- ::next::
|
||||||
-- end
|
-- end
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #ipv4 > 0 then
|
if #ipv4 > 0 then
|
||||||
routing:write("static_routes=\"")
|
routing:write('static_routes="')
|
||||||
routing:write(table.concat(ipv4, " ") .. "\"\n")
|
routing:write(table.concat(ipv4, " ") .. '"\n')
|
||||||
end
|
end
|
||||||
if #ipv6 > 0 then
|
if #ipv6 > 0 then
|
||||||
network:write("ipv6_network_interfaces=\"")
|
network:write('ipv6_network_interfaces="')
|
||||||
network:write(table.concat(ipv6, " ") .. "\"\n")
|
network:write(table.concat(ipv6, " ") .. '"\n')
|
||||||
network:write("ipv6_default_interface=\""..ipv6[1].."\"\n")
|
network:write('ipv6_default_interface="' .. ipv6[1] .. '"\n')
|
||||||
end
|
end
|
||||||
if #ipv6_routes > 0 then
|
if #ipv6_routes > 0 then
|
||||||
routing:write("ipv6_static_routes=\"")
|
routing:write('ipv6_static_routes="')
|
||||||
routing:write(table.concat(ipv6, " ") .. "\"\n")
|
routing:write(table.concat(ipv6, " ") .. '"\n')
|
||||||
end
|
end
|
||||||
network:close()
|
network:close()
|
||||||
routing:close()
|
routing:close()
|
||||||
@@ -158,7 +164,7 @@ end
|
|||||||
|
|
||||||
if citype == "config-2" then
|
if citype == "config-2" then
|
||||||
local parser = ucl.parser()
|
local parser = ucl.parser()
|
||||||
local res,err = parser:parse_file(path..'/meta_data.json')
|
local res, err = parser:parse_file(path .. "/meta_data.json")
|
||||||
|
|
||||||
if not res then
|
if not res then
|
||||||
nuage.err("nuageinit: error parsing config-2: meta_data.json: " .. err)
|
nuage.err("nuageinit: error parsing config-2: meta_data.json: " .. err)
|
||||||
@@ -175,32 +181,32 @@ if citype == "config-2" then
|
|||||||
-- network
|
-- network
|
||||||
config2_network(path)
|
config2_network(path)
|
||||||
elseif citype == "nocloud" then
|
elseif citype == "nocloud" then
|
||||||
local f,err = io.open(path.."/meta-data")
|
local f, err = io.open(path .. "/meta-data")
|
||||||
if err then
|
if err then
|
||||||
nuage.err("nuageinit: error parsing nocloud meta-data: ".. err)
|
nuage.err("nuageinit: error parsing nocloud meta-data: " .. err)
|
||||||
end
|
end
|
||||||
local obj = yaml.eval(f:read("*a"))
|
local obj = yaml.eval(f:read("*a"))
|
||||||
f:close()
|
f:close()
|
||||||
if not obj then
|
if not obj then
|
||||||
nuage.err("nuageinit: error parsing nocloud meta-data")
|
nuage.err("nuageinit: error parsing nocloud meta-data")
|
||||||
end
|
end
|
||||||
local hostname = obj['local-hostname']
|
local hostname = obj["local-hostname"]
|
||||||
if not hostname then
|
if not hostname then
|
||||||
hostname = obj['hostname']
|
hostname = obj["hostname"]
|
||||||
end
|
end
|
||||||
if hostname then
|
if hostname then
|
||||||
nuage.sethostname(hostname)
|
nuage.sethostname(hostname)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nuage.err("Unknown cloud init type: ".. citype)
|
nuage.err("Unknown cloud init type: " .. citype)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- deal with user-data
|
-- deal with user-data
|
||||||
local ud = nil
|
local ud = nil
|
||||||
local f = nil
|
local f = nil
|
||||||
userdatas = { "user-data", "user_data" }
|
userdatas = {"user-data", "user_data"}
|
||||||
for _,v in pairs(userdatas) do
|
for _, v in pairs(userdatas) do
|
||||||
f = io.open(path..'/' .. v, "r")
|
f = io.open(path .. "/" .. v, "r")
|
||||||
if f then
|
if f then
|
||||||
ud = v
|
ud = v
|
||||||
break
|
break
|
||||||
@@ -209,33 +215,33 @@ end
|
|||||||
if not f then
|
if not f then
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
end
|
end
|
||||||
local line = f:read('*l')
|
local line = f:read("*l")
|
||||||
f:close()
|
f:close()
|
||||||
if line == "#cloud-config" then
|
if line == "#cloud-config" then
|
||||||
f = io.open(path.."/" .. ud)
|
f = io.open(path .. "/" .. ud)
|
||||||
local obj = yaml.eval(f:read("*a"))
|
local obj = yaml.eval(f:read("*a"))
|
||||||
f:close()
|
f:close()
|
||||||
if not obj then
|
if not obj then
|
||||||
nuage.err("nuageinit: error parsing cloud-config file: " .. ud)
|
nuage.err("nuageinit: error parsing cloud-config file: " .. ud)
|
||||||
end
|
end
|
||||||
if obj.groups then
|
if obj.groups then
|
||||||
for n,g in pairs(obj.groups) do
|
for n, g in pairs(obj.groups) do
|
||||||
if (type(g) == "string") then
|
if (type(g) == "string") then
|
||||||
local r = nuage.addgroup({name = g})
|
local r = nuage.addgroup({name = g})
|
||||||
if not r then
|
if not r then
|
||||||
nuage.warn("nuageinit: failed to add group: ".. g)
|
nuage.warn("nuageinit: failed to add group: " .. g)
|
||||||
end
|
end
|
||||||
elseif type(g) == "table" then
|
elseif type(g) == "table" then
|
||||||
for k,v in pairs(g) do
|
for k, v in pairs(g) do
|
||||||
nuage.addgroup({name = k, members = v})
|
nuage.addgroup({name = k, members = v})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nuage.warn("nuageinit: invalid type : "..type(g).." for users entry number "..n);
|
nuage.warn("nuageinit: invalid type: " .. type(g) .. " for users entry number " .. n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if obj.users then
|
if obj.users then
|
||||||
for n,u in pairs(obj.users) do
|
for n, u in pairs(obj.users) do
|
||||||
if type(u) == "string" then
|
if type(u) == "string" then
|
||||||
if u == "default" then
|
if u == "default" then
|
||||||
nuage.adduser(default_user)
|
nuage.adduser(default_user)
|
||||||
@@ -249,12 +255,12 @@ if line == "#cloud-config" then
|
|||||||
end
|
end
|
||||||
local homedir = nuage.adduser(u)
|
local homedir = nuage.adduser(u)
|
||||||
if u.ssh_authorized_keys then
|
if u.ssh_authorized_keys then
|
||||||
for _,v in ipairs(u.ssh_authorized_keys) do
|
for _, v in ipairs(u.ssh_authorized_keys) do
|
||||||
nuage.addsshkey(homedir, v)
|
nuage.addsshkey(homedir, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nuage.warn("nuageinit: invalid type : "..type(u).." for users entry number "..n);
|
nuage.warn("nuageinit: invalid type : " .. type(u) .. " for users entry number " .. n)
|
||||||
end
|
end
|
||||||
::unext::
|
::unext::
|
||||||
end
|
end
|
||||||
@@ -264,7 +270,7 @@ if line == "#cloud-config" then
|
|||||||
end
|
end
|
||||||
if obj.ssh_authorized_keys then
|
if obj.ssh_authorized_keys then
|
||||||
local homedir = nuage.adduser(default_user)
|
local homedir = nuage.adduser(default_user)
|
||||||
for _,k in ipairs(obj.ssh_authorized_keys) do
|
for _, k in ipairs(obj.ssh_authorized_keys) do
|
||||||
nuage.addsshkey(homedir, k)
|
nuage.addsshkey(homedir, k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -273,48 +279,52 @@ if line == "#cloud-config" then
|
|||||||
nuage.mkdir_p(root .. "/etc/rc.conf.d")
|
nuage.mkdir_p(root .. "/etc/rc.conf.d")
|
||||||
local network = open_config("network")
|
local network = open_config("network")
|
||||||
local routing = open_config("routing")
|
local routing = open_config("routing")
|
||||||
local ipv6={}
|
local ipv6 = {}
|
||||||
for _,v in pairs(obj.network.ethernets) do
|
for _, v in pairs(obj.network.ethernets) do
|
||||||
if not v.match then goto next end
|
if not v.match then
|
||||||
if not v.match.macaddress then goto next end
|
goto next
|
||||||
|
end
|
||||||
|
if not v.match.macaddress then
|
||||||
|
goto next
|
||||||
|
end
|
||||||
if not ifaces[v.match.macaddress] then
|
if not ifaces[v.match.macaddress] then
|
||||||
nuage.warn("nuageinit: not interface matching: "..v.match.macaddress)
|
nuage.warn("nuageinit: not interface matching: " .. v.match.macaddress)
|
||||||
goto next
|
goto next
|
||||||
end
|
end
|
||||||
local interface = ifaces[v.match.macaddress]
|
local interface = ifaces[v.match.macaddress]
|
||||||
if v.dhcp4 then
|
if v.dhcp4 then
|
||||||
network:write("ifconfig_"..interface.."=\"DHCP\"\n")
|
network:write("ifconfig_" .. interface .. '="DHCP"\n')
|
||||||
elseif v.addresses then
|
elseif v.addresses then
|
||||||
for _,a in pairs(v.addresses) do
|
for _, a in pairs(v.addresses) do
|
||||||
if a:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)") then
|
if a:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)") then
|
||||||
network:write("ifconfig_"..interface.."=\"inet "..a.."\"\n")
|
network:write("ifconfig_" .. interface .. '="inet ' .. a .. '"\n')
|
||||||
else
|
else
|
||||||
network:write("ifconfig_"..interface.."_ipv6=\"inet6 "..a.."\"\n")
|
network:write("ifconfig_" .. interface .. '_ipv6="inet6 ' .. a .. '"\n')
|
||||||
ipv6[#ipv6 +1] = interface
|
ipv6[#ipv6 + 1] = interface
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if v.gateway4 then
|
if v.gateway4 then
|
||||||
routing:write("defaultrouter=\""..v.gateway4.."\"\n")
|
routing:write('defaultrouter="' .. v.gateway4 .. '"\n')
|
||||||
end
|
end
|
||||||
if v.gateway6 then
|
if v.gateway6 then
|
||||||
routing:write("ipv6_defaultrouter=\""..v.gateway6.."\"\n")
|
routing:write('ipv6_defaultrouter="' .. v.gateway6 .. '"\n')
|
||||||
routing:write("ipv6_route_"..interface.."=\""..v.gateway6)
|
routing:write("ipv6_route_" .. interface .. '="' .. v.gateway6)
|
||||||
routing:write(" -prefixlen 128 -interface "..interface.."\"\n")
|
routing:write(" -prefixlen 128 -interface " .. interface .. '"\n')
|
||||||
end
|
end
|
||||||
::next::
|
::next::
|
||||||
end
|
end
|
||||||
if #ipv6 > 0 then
|
if #ipv6 > 0 then
|
||||||
network:write("ipv6_network_interfaces=\"")
|
network:write('ipv6_network_interfaces="')
|
||||||
network:write(table.concat(ipv6, " ") .. "\"\n")
|
network:write(table.concat(ipv6, " ") .. '"\n')
|
||||||
network:write("ipv6_default_interface=\""..ipv6[1].."\"\n")
|
network:write('ipv6_default_interface="' .. ipv6[1] .. '"\n')
|
||||||
end
|
end
|
||||||
network:close()
|
network:close()
|
||||||
routing:close()
|
routing:close()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local res,err = os.execute(path..'/' .. ud)
|
local res, err = os.execute(path .. "/" .. ud)
|
||||||
if not res then
|
if not res then
|
||||||
nuage.err("nuageinit: error executing user-data script: ".. err)
|
nuage.err("nuageinit: error executing user-data script: " .. err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ PACKAGE= tests
|
|||||||
|
|
||||||
ATF_TESTS_SH= nuage utils nuageinit
|
ATF_TESTS_SH= nuage utils nuageinit
|
||||||
|
|
||||||
${PACKAGE}FILES+= warn.lua
|
${PACKAGE}FILES+= addgroup.lua
|
||||||
${PACKAGE}FILES+= err.lua
|
|
||||||
${PACKAGE}FILES+= dirname.lua
|
|
||||||
${PACKAGE}FILES+= sethostname.lua
|
|
||||||
${PACKAGE}FILES+= addsshkey.lua
|
${PACKAGE}FILES+= addsshkey.lua
|
||||||
${PACKAGE}FILES+= adduser.lua
|
${PACKAGE}FILES+= adduser.lua
|
||||||
${PACKAGE}FILES+= addgroup.lua
|
${PACKAGE}FILES+= dirname.lua
|
||||||
|
${PACKAGE}FILES+= err.lua
|
||||||
|
${PACKAGE}FILES+= sethostname.lua
|
||||||
|
${PACKAGE}FILES+= warn.lua
|
||||||
|
|
||||||
.include <bsd.test.mk>
|
.include <bsd.test.mk>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/libexec/flua
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
if n.addgroup() then
|
if n.addgroup() then
|
||||||
n.err("addgroup should not accept empty value")
|
n.err("addgroup should not accept empty value")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
n.addsshkey(".", "mykey")
|
n.addsshkey(".", "mykey")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/libexec/flua
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
if n.adduser() then
|
if n.adduser() then
|
||||||
n.err("adduser should not accept empty value")
|
n.err("adduser should not accept empty value")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
print(n.dirname("/my/path/path1"))
|
print(n.dirname("/my/path/path1"))
|
||||||
if n.dirname("path") then
|
if n.dirname("path") then
|
||||||
nuage.err("Expecting nil for n.dirname(\"path\")")
|
n.err('Expecting nil for n.dirname("path")')
|
||||||
end
|
end
|
||||||
if n.dirname() then
|
if n.dirname() then
|
||||||
nuage.err("Expecting nil for n.dirname")
|
n.err("Expecting nil for n.dirname")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/libexec/flua
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
n.err("plop")
|
n.err("plop")
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
|
#-
|
||||||
|
# Copyright (c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
#
|
||||||
|
|
||||||
atf_test_case sethostname
|
atf_test_case sethostname
|
||||||
atf_test_case addsshkey
|
atf_test_case addsshkey
|
||||||
atf_test_case adduser
|
atf_test_case adduser
|
||||||
atf_test_case addgroup
|
atf_test_case addgroup
|
||||||
|
|
||||||
sethostname_body() {
|
sethostname_body()
|
||||||
|
{
|
||||||
export NUAGE_FAKE_ROOTDIR="$(pwd)"
|
export NUAGE_FAKE_ROOTDIR="$(pwd)"
|
||||||
atf_check /usr/libexec/flua $(atf_get_srcdir)/sethostname.lua
|
atf_check /usr/libexec/flua $(atf_get_srcdir)/sethostname.lua
|
||||||
if [ ! -f etc/rc.conf.d/hostname ]; then
|
if [ ! -f etc/rc.conf.d/hostname ]; then
|
||||||
@@ -12,7 +19,8 @@ sethostname_body() {
|
|||||||
atf_check -o inline:"hostname=\"myhostname\"\n" cat etc/rc.conf.d/hostname
|
atf_check -o inline:"hostname=\"myhostname\"\n" cat etc/rc.conf.d/hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
addsshkey_body() {
|
addsshkey_body()
|
||||||
|
{
|
||||||
atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
|
atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
|
||||||
if [ ! -f .ssh/authorized_keys ]; then
|
if [ ! -f .ssh/authorized_keys ]; then
|
||||||
atf_fail "ssh key not added"
|
atf_fail "ssh key not added"
|
||||||
@@ -24,7 +32,8 @@ addsshkey_body() {
|
|||||||
atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys
|
atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
adduser_body() {
|
adduser_body()
|
||||||
|
{
|
||||||
export NUAGE_FAKE_ROOTDIR="$(pwd)"
|
export NUAGE_FAKE_ROOTDIR="$(pwd)"
|
||||||
if [ $(id -u) -ne 0 ]; then
|
if [ $(id -u) -ne 0 ]; then
|
||||||
atf_skip "root required"
|
atf_skip "root required"
|
||||||
@@ -38,7 +47,8 @@ adduser_body() {
|
|||||||
atf_check -o inline:"impossible_username::1001:1001::0:0:impossible_username User:/home/impossible_username:/bin/sh\n" grep impossible_username etc/master.passwd
|
atf_check -o inline:"impossible_username::1001:1001::0:0:impossible_username User:/home/impossible_username:/bin/sh\n" grep impossible_username etc/master.passwd
|
||||||
}
|
}
|
||||||
|
|
||||||
addgroup_body() {
|
addgroup_body()
|
||||||
|
{
|
||||||
export NUAGE_FAKE_ROOTDIR="$(pwd)"
|
export NUAGE_FAKE_ROOTDIR="$(pwd)"
|
||||||
mkdir etc
|
mkdir etc
|
||||||
printf "wheel:*:0:root\n" > etc/group
|
printf "wheel:*:0:root\n" > etc/group
|
||||||
@@ -46,7 +56,8 @@ addgroup_body() {
|
|||||||
atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group
|
atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group
|
||||||
}
|
}
|
||||||
|
|
||||||
atf_init_test_cases() {
|
atf_init_test_cases()
|
||||||
|
{
|
||||||
atf_add_test_case sethostname
|
atf_add_test_case sethostname
|
||||||
atf_add_test_case addsshkey
|
atf_add_test_case addsshkey
|
||||||
atf_add_test_case adduser
|
atf_add_test_case adduser
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
|
#-
|
||||||
|
# Copyright (c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
#
|
||||||
|
|
||||||
atf_test_case args
|
atf_test_case args
|
||||||
atf_test_case nocloud
|
atf_test_case nocloud
|
||||||
atf_test_case nocloud_userdata_script
|
atf_test_case nocloud_userdata_script
|
||||||
atf_test_case nocloud_user_data_script
|
atf_test_case nocloud_user_data_script
|
||||||
atf_test_case nocloud_userdata_cloudconfig
|
|
||||||
atf_test_case nocloud_userdata_cloudconfig_users
|
atf_test_case nocloud_userdata_cloudconfig_users
|
||||||
atf_test_case nocloud_network
|
atf_test_case nocloud_network
|
||||||
atf_test_case config2
|
atf_test_case config2
|
||||||
@@ -12,7 +17,6 @@ atf_test_case config2_pubkeys_meta_data
|
|||||||
atf_test_case config2_network
|
atf_test_case config2_network
|
||||||
atf_test_case config2_network_static_v4
|
atf_test_case config2_network_static_v4
|
||||||
|
|
||||||
|
|
||||||
args_body()
|
args_body()
|
||||||
{
|
{
|
||||||
atf_check -s exit:1 -e inline:"Usage /usr/libexec/nuageinit <cloud-init directory> [config-2|nocloud]\n" /usr/libexec/nuageinit
|
atf_check -s exit:1 -e inline:"Usage /usr/libexec/nuageinit <cloud-init directory> [config-2|nocloud]\n" /usr/libexec/nuageinit
|
||||||
@@ -43,7 +47,7 @@ nocloud_userdata_script_body()
|
|||||||
here=$(pwd)
|
here=$(pwd)
|
||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
||||||
printf "#!/bin/sh\necho "yeah"\n" > ${here}/media/nuageinit/user-data
|
printf "#!/bin/sh\necho yeah\n" > ${here}/media/nuageinit/user-data
|
||||||
chmod 755 ${here}/media/nuageinit/user-data
|
chmod 755 ${here}/media/nuageinit/user-data
|
||||||
atf_check -s exit:0 -o inline:"yeah\n" /usr/libexec/nuageinit ${here}/media/nuageinit nocloud
|
atf_check -s exit:0 -o inline:"yeah\n" /usr/libexec/nuageinit ${here}/media/nuageinit nocloud
|
||||||
}
|
}
|
||||||
@@ -53,7 +57,7 @@ nocloud_user_data_script_body()
|
|||||||
here=$(pwd)
|
here=$(pwd)
|
||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
||||||
printf "#!/bin/sh\necho "yeah"\n" > ${here}/media/nuageinit/user_data
|
printf "#!/bin/sh\necho yeah\n" > ${here}/media/nuageinit/user_data
|
||||||
chmod 755 ${here}/media/nuageinit/user_data
|
chmod 755 ${here}/media/nuageinit/user_data
|
||||||
atf_check -s exit:0 -o inline:"yeah\n" /usr/libexec/nuageinit ${here}/media/nuageinit nocloud
|
atf_check -s exit:0 -o inline:"yeah\n" /usr/libexec/nuageinit ${here}/media/nuageinit nocloud
|
||||||
}
|
}
|
||||||
@@ -68,16 +72,16 @@ nocloud_userdata_cloudconfig_users_body()
|
|||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
||||||
mkdir -p etc
|
mkdir -p etc
|
||||||
cat > etc/master.passwd <<EOF
|
cat > etc/master.passwd << EOF
|
||||||
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
||||||
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
||||||
EOF
|
EOF
|
||||||
pwd_mkdb -d etc ${here}/etc/master.passwd
|
pwd_mkdb -d etc ${here}/etc/master.passwd
|
||||||
cat > etc/group <<EOF
|
cat > etc/group << EOF
|
||||||
wheel:*:0:root
|
wheel:*:0:root
|
||||||
users:*:1:
|
users:*:1:
|
||||||
EOF
|
EOF
|
||||||
cat > media/nuageinit/user-data <<EOF
|
cat > media/nuageinit/user-data << EOF
|
||||||
#cloud-config
|
#cloud-config
|
||||||
groups:
|
groups:
|
||||||
- admingroup: [root,sys]
|
- admingroup: [root,sys]
|
||||||
@@ -115,12 +119,12 @@ nocloud_network_body()
|
|||||||
here=$(pwd)
|
here=$(pwd)
|
||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
mkdir -p etc
|
mkdir -p etc
|
||||||
cat > etc/master.passwd <<EOF
|
cat > etc/master.passwd << EOF
|
||||||
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
||||||
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
||||||
EOF
|
EOF
|
||||||
pwd_mkdb -d etc ${here}/etc/master.passwd
|
pwd_mkdb -d etc ${here}/etc/master.passwd
|
||||||
cat > etc/group <<EOF
|
cat > etc/group << EOF
|
||||||
wheel:*:0:root
|
wheel:*:0:root
|
||||||
users:*:1:
|
users:*:1:
|
||||||
EOF
|
EOF
|
||||||
@@ -135,16 +139,15 @@ EOF
|
|||||||
myiface=$1
|
myiface=$1
|
||||||
myaddr=$(ifconfig $myiface ether | awk '/ether/ { print $2 }')
|
myaddr=$(ifconfig $myiface ether | awk '/ether/ { print $2 }')
|
||||||
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
printf "instance-id: iid-local01\n" > ${here}/media/nuageinit/meta-data
|
||||||
cat > media/nuageinit/user-data <<EOF
|
cat > media/nuageinit/user-data << EOF
|
||||||
#cloud-config
|
#cloud-config
|
||||||
#
|
|
||||||
network:
|
network:
|
||||||
version: 2
|
version: 2
|
||||||
ethernets:
|
ethernets:
|
||||||
# opaque ID for physical interfaces, only referred to by other stanzas
|
# opaque ID for physical interfaces, only referred to by other stanzas
|
||||||
id0:
|
id0:
|
||||||
match:
|
match:
|
||||||
macaddress: '${myaddr}'
|
macaddress: "$myaddr"
|
||||||
addresses:
|
addresses:
|
||||||
- 192.168.14.2/24
|
- 192.168.14.2/24
|
||||||
- 2001:1::1/64
|
- 2001:1::1/64
|
||||||
@@ -153,13 +156,13 @@ network:
|
|||||||
EOF
|
EOF
|
||||||
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
||||||
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit nocloud
|
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit nocloud
|
||||||
cat > network <<EOF
|
cat > network << EOF
|
||||||
ifconfig_${myiface}="inet 192.168.14.2/24"
|
ifconfig_${myiface}="inet 192.168.14.2/24"
|
||||||
ifconfig_${myiface}_ipv6="inet6 2001:1::1/64"
|
ifconfig_${myiface}_ipv6="inet6 2001:1::1/64"
|
||||||
ipv6_network_interfaces="${myiface}"
|
ipv6_network_interfaces="${myiface}"
|
||||||
ipv6_default_interface="${myiface}"
|
ipv6_default_interface="${myiface}"
|
||||||
EOF
|
EOF
|
||||||
cat > routing <<EOF
|
cat > routing << EOF
|
||||||
defaultrouter="192.168.14.1"
|
defaultrouter="192.168.14.1"
|
||||||
ipv6_defaultrouter="2001:1::2"
|
ipv6_defaultrouter="2001:1::2"
|
||||||
ipv6_route_${myiface}="2001:1::2 -prefixlen 128 -interface ${myiface}"
|
ipv6_route_${myiface}="2001:1::2 -prefixlen 128 -interface ${myiface}"
|
||||||
@@ -176,7 +179,7 @@ config2_body()
|
|||||||
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
|
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
|
||||||
cat > media/nuageinit/meta_data.json << EOF
|
cat > media/nuageinit/meta_data.json << EOF
|
||||||
{
|
{
|
||||||
"hostname": "cloudimg",
|
"hostname": "cloudimg"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
||||||
@@ -195,17 +198,16 @@ config2_pubkeys_body()
|
|||||||
touch media/nuageinit/meta_data.json
|
touch media/nuageinit/meta_data.json
|
||||||
cat > media/nuageinit/user-data << EOF
|
cat > media/nuageinit/user-data << EOF
|
||||||
#cloud-config
|
#cloud-config
|
||||||
|
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- "ssh-rsa AAAAB3NzaC1y...== Generated by Nova"
|
- "ssh-rsa AAAAB3NzaC1y...== Generated by Nova"
|
||||||
EOF
|
EOF
|
||||||
mkdir -p etc
|
mkdir -p etc
|
||||||
cat > etc/master.passwd <<EOF
|
cat > etc/master.passwd << EOF
|
||||||
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
||||||
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
||||||
EOF
|
EOF
|
||||||
pwd_mkdb -d etc ${here}/etc/master.passwd
|
pwd_mkdb -d etc ${here}/etc/master.passwd
|
||||||
cat > etc/group <<EOF
|
cat > etc/group << EOF
|
||||||
wheel:*:0:root
|
wheel:*:0:root
|
||||||
users:*:1:
|
users:*:1:
|
||||||
EOF
|
EOF
|
||||||
@@ -225,17 +227,16 @@ config2_pubkeys_user_data_body()
|
|||||||
touch media/nuageinit/meta_data.json
|
touch media/nuageinit/meta_data.json
|
||||||
cat > media/nuageinit/user_data << EOF
|
cat > media/nuageinit/user_data << EOF
|
||||||
#cloud-config
|
#cloud-config
|
||||||
|
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- "ssh-rsa AAAAB3NzaC1y...== Generated by Nova"
|
- "ssh-rsa AAAAB3NzaC1y...== Generated by Nova"
|
||||||
EOF
|
EOF
|
||||||
mkdir -p etc
|
mkdir -p etc
|
||||||
cat > etc/master.passwd <<EOF
|
cat > etc/master.passwd << EOF
|
||||||
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
||||||
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
||||||
EOF
|
EOF
|
||||||
pwd_mkdb -d etc ${here}/etc/master.passwd
|
pwd_mkdb -d etc ${here}/etc/master.passwd
|
||||||
cat > etc/group <<EOF
|
cat > etc/group << EOF
|
||||||
wheel:*:0:root
|
wheel:*:0:root
|
||||||
users:*:1:
|
users:*:1:
|
||||||
EOF
|
EOF
|
||||||
@@ -251,7 +252,7 @@ config2_pubkeys_meta_data_body()
|
|||||||
atf_skip "root required"
|
atf_skip "root required"
|
||||||
fi
|
fi
|
||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
cat > media/nuageinit/meta_data.json <<EOF
|
cat > media/nuageinit/meta_data.json << EOF
|
||||||
{
|
{
|
||||||
"uuid": "uuid_for_this_instance",
|
"uuid": "uuid_for_this_instance",
|
||||||
"admin_pass": "a_generated_password",
|
"admin_pass": "a_generated_password",
|
||||||
@@ -276,12 +277,12 @@ config2_pubkeys_meta_data_body()
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
mkdir -p etc
|
mkdir -p etc
|
||||||
cat > etc/master.passwd <<EOF
|
cat > etc/master.passwd << EOF
|
||||||
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
root:*:0:0::0:0:Charlie &:/root:/bin/csh
|
||||||
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
sys:*:1:0::0:0:Sys:/home/sys:/bin/csh
|
||||||
EOF
|
EOF
|
||||||
pwd_mkdb -d etc ${here}/etc/master.passwd
|
pwd_mkdb -d etc ${here}/etc/master.passwd
|
||||||
cat > etc/group <<EOF
|
cat > etc/group << EOF
|
||||||
wheel:*:0:root
|
wheel:*:0:root
|
||||||
users:*:1:
|
users:*:1:
|
||||||
EOF
|
EOF
|
||||||
@@ -289,7 +290,8 @@ EOF
|
|||||||
atf_check -o inline:"ssh-ed25519 my_key_id tdb@host\n" cat home/freebsd/.ssh/authorized_keys
|
atf_check -o inline:"ssh-ed25519 my_key_id tdb@host\n" cat home/freebsd/.ssh/authorized_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
config2_network_body() {
|
config2_network_body()
|
||||||
|
{
|
||||||
here=$(pwd)
|
here=$(pwd)
|
||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
printf "{}" > media/nuageinit/meta_data.json
|
printf "{}" > media/nuageinit/meta_data.json
|
||||||
@@ -300,13 +302,13 @@ config2_network_body() {
|
|||||||
set -- $mynetworks
|
set -- $mynetworks
|
||||||
myiface=$1
|
myiface=$1
|
||||||
myaddr=$(ifconfig $myiface ether | awk '/ether/ { print $2 }')
|
myaddr=$(ifconfig $myiface ether | awk '/ether/ { print $2 }')
|
||||||
cat > media/nuageinit/network_data.json <<EOF
|
cat > media/nuageinit/network_data.json << EOF
|
||||||
{
|
{
|
||||||
"links": [
|
"links": [
|
||||||
{
|
{
|
||||||
"ethernet_mac_address": "$myaddr",
|
"ethernet_mac_address": "$myaddr",
|
||||||
"id": "iface0",
|
"id": "iface0",
|
||||||
"mtu": null,
|
"mtu": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"networks": [
|
"networks": [
|
||||||
@@ -321,7 +323,7 @@ cat > media/nuageinit/network_data.json <<EOF
|
|||||||
"link": "iface0",
|
"link": "iface0",
|
||||||
// supports condensed IPv6 with CIDR netmask
|
// supports condensed IPv6 with CIDR netmask
|
||||||
"ip_address": "2001:cdba::3257:9652/24",
|
"ip_address": "2001:cdba::3257:9652/24",
|
||||||
"gateway": "fd00::1"
|
"gateway": "fd00::1",
|
||||||
"routes": [
|
"routes": [
|
||||||
{
|
{
|
||||||
"network": "::",
|
"network": "::",
|
||||||
@@ -332,22 +334,22 @@ cat > media/nuageinit/network_data.json <<EOF
|
|||||||
"network": "::",
|
"network": "::",
|
||||||
"netmask": "ffff:ffff:ffff::",
|
"netmask": "ffff:ffff:ffff::",
|
||||||
"gateway": "fd00::1:1"
|
"gateway": "fd00::1:1"
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
"network_id": "da5bb487-5193-4a65-a3df-4a0055a8c0d8"
|
"network_id": "da5bb487-5193-4a65-a3df-4a0055a8c0d8"
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
||||||
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
|
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
|
||||||
cat > network <<EOF
|
cat > network << EOF
|
||||||
ifconfig_${myiface}="DHCP"
|
ifconfig_${myiface}="DHCP"
|
||||||
ifconfig_${myiface}_ipv6="inet6 2001:cdba::3257:9652/24"
|
ifconfig_${myiface}_ipv6="inet6 2001:cdba::3257:9652/24"
|
||||||
ipv6_network_interfaces="${myiface}"
|
ipv6_network_interfaces="${myiface}"
|
||||||
ipv6_default_interface="${myiface}"
|
ipv6_default_interface="${myiface}"
|
||||||
EOF
|
EOF
|
||||||
cat > routing <<EOF
|
cat > routing << EOF
|
||||||
ipv6_defaultrouter="fd00::1"
|
ipv6_defaultrouter="fd00::1"
|
||||||
ipv6_route_${myiface}="fd00::1 -prefixlen 128 -interface ${myiface}"
|
ipv6_route_${myiface}="fd00::1 -prefixlen 128 -interface ${myiface}"
|
||||||
ipv6_static_routes="${myiface}"
|
ipv6_static_routes="${myiface}"
|
||||||
@@ -356,7 +358,8 @@ EOF
|
|||||||
atf_check -o file:routing cat ${here}/etc/rc.conf.d/routing
|
atf_check -o file:routing cat ${here}/etc/rc.conf.d/routing
|
||||||
}
|
}
|
||||||
|
|
||||||
config2_network_static_v4_body() {
|
config2_network_static_v4_body()
|
||||||
|
{
|
||||||
here=$(pwd)
|
here=$(pwd)
|
||||||
mkdir -p media/nuageinit
|
mkdir -p media/nuageinit
|
||||||
printf "{}" > media/nuageinit/meta_data.json
|
printf "{}" > media/nuageinit/meta_data.json
|
||||||
@@ -367,20 +370,20 @@ config2_network_static_v4_body() {
|
|||||||
set -- $mynetworks
|
set -- $mynetworks
|
||||||
myiface=$1
|
myiface=$1
|
||||||
myaddr=$(ifconfig $myiface ether | awk '/ether/ { print $2 }')
|
myaddr=$(ifconfig $myiface ether | awk '/ether/ { print $2 }')
|
||||||
cat > media/nuageinit/network_data.json <<EOF
|
cat > media/nuageinit/network_data.json << EOF
|
||||||
{
|
{
|
||||||
"links": [
|
"links": [
|
||||||
{
|
{
|
||||||
"ethernet_mac_address": "$myaddr",
|
"ethernet_mac_address": "$myaddr",
|
||||||
"id": "iface0",
|
"id": "iface0",
|
||||||
"mtu": null,
|
"mtu": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"networks": [
|
"networks": [
|
||||||
{
|
{
|
||||||
"id": "network0",
|
"id": "network0",
|
||||||
"link": "iface0",
|
"link": "iface0",
|
||||||
"type": "ipv4"
|
"type": "ipv4",
|
||||||
"ip_address": "10.184.0.244",
|
"ip_address": "10.184.0.244",
|
||||||
"netmask": "255.255.240.0",
|
"netmask": "255.255.240.0",
|
||||||
"routes": [
|
"routes": [
|
||||||
@@ -396,16 +399,16 @@ cat > media/nuageinit/network_data.json <<EOF
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
export NUAGE_FAKE_ROOTDIR=$(pwd)
|
||||||
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
|
atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2
|
||||||
cat > network <<EOF
|
cat > network << EOF
|
||||||
ifconfig_${myiface}="inet 10.184.0.244 netmask 255.255.240.0"
|
ifconfig_${myiface}="inet 10.184.0.244 netmask 255.255.240.0"
|
||||||
EOF
|
EOF
|
||||||
cat > routing <<EOF
|
cat > routing << EOF
|
||||||
route_cloudinit1_${myiface}="-net 10.0.0.0 11.0.0.1 255.0.0.0"
|
route_cloudinit1_${myiface}="-net 10.0.0.0 11.0.0.1 255.0.0.0"
|
||||||
defaultrouter="23.253.157.1"
|
defaultrouter="23.253.157.1"
|
||||||
static_routes="cloudinit1_${myiface}"
|
static_routes="cloudinit1_${myiface}"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/libexec/flua
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
n.sethostname("myhostname")
|
n.sethostname("myhostname")
|
||||||
|
|||||||
@@ -1,20 +1,30 @@
|
|||||||
|
#-
|
||||||
|
# Copyright (c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
#
|
||||||
|
|
||||||
atf_test_case warn
|
atf_test_case warn
|
||||||
atf_test_case err
|
atf_test_case err
|
||||||
atf_test_case dirname
|
atf_test_case dirname
|
||||||
|
|
||||||
warn_body() {
|
warn_body()
|
||||||
|
{
|
||||||
atf_check -e "inline:plop\n" -s exit:0 /usr/libexec/flua $(atf_get_srcdir)/warn.lua
|
atf_check -e "inline:plop\n" -s exit:0 /usr/libexec/flua $(atf_get_srcdir)/warn.lua
|
||||||
}
|
}
|
||||||
|
|
||||||
err_body() {
|
err_body()
|
||||||
|
{
|
||||||
atf_check -e "inline:plop\n" -s exit:1 /usr/libexec/flua $(atf_get_srcdir)/err.lua
|
atf_check -e "inline:plop\n" -s exit:1 /usr/libexec/flua $(atf_get_srcdir)/err.lua
|
||||||
}
|
}
|
||||||
|
|
||||||
dirname_body() {
|
dirname_body()
|
||||||
|
{
|
||||||
atf_check -o "inline:/my/path/\n" -s exit:0 /usr/libexec/flua $(atf_get_srcdir)/dirname.lua
|
atf_check -o "inline:/my/path/\n" -s exit:0 /usr/libexec/flua $(atf_get_srcdir)/dirname.lua
|
||||||
}
|
}
|
||||||
|
|
||||||
atf_init_test_cases() {
|
atf_init_test_cases()
|
||||||
|
{
|
||||||
atf_add_test_case warn
|
atf_add_test_case warn
|
||||||
atf_add_test_case err
|
atf_add_test_case err
|
||||||
atf_add_test_case dirname
|
atf_add_test_case dirname
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/libexec/flua
|
#!/usr/libexec/flua
|
||||||
|
|
||||||
local n = require("nuage")
|
local n = require("nuage")
|
||||||
|
|
||||||
n.warn("plop")
|
n.warn("plop")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
-- SPDX-License-Identifier: MIT
|
-- SPDX-License-Identifier: MIT
|
||||||
--
|
--
|
||||||
-- Copyright (c) 2017 Dominic Letz dominicletz@exosite.com
|
-- Copyright (c) 2017 Dominic Letz dominicletz@exosite.com
|
||||||
|
|||||||
Reference in New Issue
Block a user