[type/__interface] Draft ifcfg backend
This commit is contained in:
parent
95b5fcbdc4
commit
63b5800d9f
3 changed files with 107 additions and 24 deletions
105
cdist/conf/type/__interface/files/backends/ifcfg/manifest
Executable file
105
cdist/conf/type/__interface/files/backends/ifcfg/manifest
Executable file
|
@ -0,0 +1,105 @@
|
|||
#!/bin/sh -e
|
||||
# -*- mode: sh; indent-tabs-mode: t -*-
|
||||
#
|
||||
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
opt_format() {
|
||||
printf '%s="%s"\n' "${1:?'option name missing'}" "${2:?'option value missing'}"
|
||||
}
|
||||
|
||||
opt_from_param() {
|
||||
# Only first line will be read.
|
||||
opt_format \
|
||||
"${1:?'option name missing'}" \
|
||||
"$(head -n 1 "${__object}/parameter/${2:?'parameter name missing'}")"
|
||||
}
|
||||
|
||||
|
||||
set -- --state "$(cat "${__object}/parameter/state")" --family inet
|
||||
|
||||
# Boolean flags
|
||||
if test -f "${__object}/parameter/onboot"
|
||||
then
|
||||
set -- "$@" --onboot
|
||||
fi
|
||||
if test -f "${__object}/parameter/hotplug"
|
||||
then
|
||||
set -- "$@" --hotplug
|
||||
fi
|
||||
|
||||
|
||||
if test -f "${__object}/parameter/name"
|
||||
then
|
||||
set -- "$@" --name "$(cat "${__object}/parameter/name")"
|
||||
fi
|
||||
|
||||
|
||||
# Generate appropriate parameters based on bootproto
|
||||
bootproto=$(cat "${__object}/parameter/bootproto")
|
||||
case $bootproto
|
||||
in
|
||||
(dhcp)
|
||||
set -- "$@" --bootproto dhcp
|
||||
;;
|
||||
(static)
|
||||
set -- "$@" --bootproto static
|
||||
|
||||
if test -s "${__object}/parameter/address"
|
||||
then
|
||||
while read -r _addr
|
||||
do
|
||||
set -- "$@" --address "${_addr}"
|
||||
done <"${__object}/parameter/address"
|
||||
unset _addr
|
||||
fi
|
||||
|
||||
if test -s "${__object}/parameter/gateway"
|
||||
then
|
||||
set -- "$@" --option "$(opt_from_param GATEWAY gateway)"
|
||||
fi
|
||||
;;
|
||||
(manual)
|
||||
set -- "$@" --bootproto none
|
||||
;;
|
||||
(*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -s "${__object}/parameter/comment"
|
||||
then
|
||||
set -- "$@" --comment "$(cat "${__object}/parameter/comment")"
|
||||
fi
|
||||
|
||||
if test -s "${__object}/parameter/onchange"
|
||||
then
|
||||
set -- "$@" --onchange "$(cat "${__object}/parameter/onchange")"
|
||||
fi
|
||||
|
||||
if test -s "${__object}/parameter/extra-config"
|
||||
then
|
||||
while read -r _opt
|
||||
do
|
||||
set -- "$@" --option "${_opt}"
|
||||
done <"${__object}/parameter/extra-config"
|
||||
unset _opt
|
||||
fi
|
||||
|
||||
# Instantiate backend type
|
||||
__interface_ifcfg "${__object_id}" "$@"
|
|
@ -1,22 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
# -*- mode: sh; indent-tabs-mode: t -*-
|
||||
#
|
||||
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# TODO
|
|
@ -69,8 +69,8 @@ else
|
|||
(devuan)
|
||||
impl_type=ifupdown.d
|
||||
;;
|
||||
(centos|redhat)
|
||||
impl_type=redhat
|
||||
(centos|redhat|scientific|suse)
|
||||
impl_type=ifcfg
|
||||
;;
|
||||
(openwrt)
|
||||
impl_type=uci
|
||||
|
|
Loading…
Reference in a new issue