[type/__interface_ifcfg] Add type with basic support for RedHat
This commit is contained in:
parent
f62bf38449
commit
95b5fcbdc4
7 changed files with 261 additions and 0 deletions
68
cdist/conf/type/__interface_ifcfg/man.rst
Normal file
68
cdist/conf/type/__interface_ifcfg/man.rst
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
cdist-type__interface_ifcfg(7)
|
||||||
|
===============================
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
cdist-type__interface_ifcfg - Manage network interfaces using ifcfg network
|
||||||
|
scripts.
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
This type allows to configure network interfaces using the ifcfg network scripts
|
||||||
|
on RedHat and SuSE distributions.
|
||||||
|
|
||||||
|
|
||||||
|
REQUIRED PARAMETERS
|
||||||
|
-------------------
|
||||||
|
bootproto
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
OPTIONAL PARAMETERS
|
||||||
|
-------------------
|
||||||
|
address
|
||||||
|
|
||||||
|
comment
|
||||||
|
If supplied, the value will be inserted at the top of the configuration file
|
||||||
|
as a comment.
|
||||||
|
option
|
||||||
|
...
|
||||||
|
Can be used multiple times.
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN PARAMETERS
|
||||||
|
------------------
|
||||||
|
onboot
|
||||||
|
|
||||||
|
hotplug
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
__interface_ifcfg ...
|
||||||
|
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
:strong:`cdist-type__interface`\ (7)
|
||||||
|
|
||||||
|
|
||||||
|
AUTHORS
|
||||||
|
-------
|
||||||
|
Steven Armstrong <steven-cdist at armstrong.cc>
|
||||||
|
Dennis Camera <dennis.camera at ssrq-sds-fds.ch>
|
||||||
|
|
||||||
|
|
||||||
|
COPYING
|
||||||
|
-------
|
||||||
|
Copyright \(C) 2014--2020 Steven Armstrong and Dennis Camera.
|
||||||
|
|
||||||
|
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.
|
184
cdist/conf/type/__interface_ifcfg/manifest
Executable file
184
cdist/conf/type/__interface_ifcfg/manifest
Executable file
|
@ -0,0 +1,184 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
yesno() { test $? -eq 0 && echo yes || echo no; }
|
||||||
|
opt_format() {
|
||||||
|
printf '%s="%s"\n' "${1:?'option name missing'}" "${2:?'option value missing'}"
|
||||||
|
}
|
||||||
|
prefix2subnet() {
|
||||||
|
python3 -c 'for addr in __import__("sys").argv[1:]: print(__import__("ipaddress").ip_network(addr, strict=False).netmask)' "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
os=$(cat "${__global}/explorer/os")
|
||||||
|
|
||||||
|
case $os
|
||||||
|
in
|
||||||
|
(centos|redhat|scientific)
|
||||||
|
NETWORK_SCRIPTS_DIR='/etc/sysconfig/network-scripts'
|
||||||
|
;;
|
||||||
|
(suse)
|
||||||
|
NETWORK_SCRIPTS_DIR='/etc/sysconfig/network'
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "${os}" "${__type##*/}" >&2
|
||||||
|
printf "Please contribute an implementation for it if you can.\n" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -s "${__object}/parameter/name"
|
||||||
|
then
|
||||||
|
name=$(cat "${__object}/parameter/name")
|
||||||
|
else
|
||||||
|
name=$__object_id
|
||||||
|
fi
|
||||||
|
state_should=$(cat "${__object}/parameter/state")
|
||||||
|
bootproto=$(cat "${__object}/parameter/bootproto")
|
||||||
|
onchange=$(cat "${__object}/parameter/onchange")
|
||||||
|
|
||||||
|
ifcfg_file="${NETWORK_SCRIPTS_DIR:?}/ifcfg-${__object_id}"
|
||||||
|
|
||||||
|
|
||||||
|
onchange_action() {
|
||||||
|
case $onchange
|
||||||
|
in
|
||||||
|
(refresh)
|
||||||
|
printf "ifdown '%s' || true ; ifup '%s'\n" "${name}" "${name}"
|
||||||
|
;;
|
||||||
|
(up)
|
||||||
|
printf "ifup '%s'\n" "${name}"
|
||||||
|
;;
|
||||||
|
(down)
|
||||||
|
printf "ifdown '%s' || true\n" "${name}"
|
||||||
|
;;
|
||||||
|
(leave)
|
||||||
|
# ignore
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
printf 'Invalid --onchange: %s\n' "${onchange}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
cat <<-EOF
|
||||||
|
# Created by cdist ${__type##*/}
|
||||||
|
# Do not change. Changes will be overwritten.
|
||||||
|
#
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if test -f "$__object/parameter/comment"
|
||||||
|
then
|
||||||
|
awk '{ print "# " $0 }' <"$__object/parameter/comment"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
opt_format DEVICE "${name}"
|
||||||
|
opt_format NM_CONTROLLED no
|
||||||
|
|
||||||
|
ignored_parameters=
|
||||||
|
|
||||||
|
# manually_handled_parameters are handled in their own code block, not by
|
||||||
|
# the generic accumulator
|
||||||
|
manually_handled_parameters='bootproto comment name extra-config state onboot onchange hotplug'
|
||||||
|
|
||||||
|
case $bootproto
|
||||||
|
in
|
||||||
|
(dhcp)
|
||||||
|
opt_format BOOTPROTO dhcp
|
||||||
|
ignored_parameters='address broadcast gateway'
|
||||||
|
;;
|
||||||
|
(static|manual)
|
||||||
|
opt_format BOOTPROTO none
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
printf 'Invalid --bootproto: %s\n' "${bootproto}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
_bonding_opts=
|
||||||
|
|
||||||
|
for _param in "${__object}"/parameter/*
|
||||||
|
do
|
||||||
|
_key=$(echo "${_param}" | tr '[:lower:]' '[:upper:]' | tr '-' '_')
|
||||||
|
|
||||||
|
echo "${ignored_parameters}" | grep -q -w "${_param}" && continue
|
||||||
|
echo "${manually_handled_parameters}" | grep -q -w "${_param}" && continue
|
||||||
|
|
||||||
|
case $_param
|
||||||
|
in
|
||||||
|
(onboot|hotplug)
|
||||||
|
# boolean options
|
||||||
|
opt_format "${_key}" "$(test -f "${__object}/parameter/${_param}" | yesno)"
|
||||||
|
;;
|
||||||
|
(bond-master)
|
||||||
|
opt_format SLAVE yes
|
||||||
|
opt_format MASTER "$(cat "${__object}/parameter/${_param}")"
|
||||||
|
;;
|
||||||
|
(bond-*)
|
||||||
|
_key=$(echo "${_param#bond-}" | tr '-' '_')
|
||||||
|
_value=$(cat "${__object}/parameter/${_param}")
|
||||||
|
|
||||||
|
if test "${_key}" = 'arp_ip_target'
|
||||||
|
then
|
||||||
|
_value=$(echo "${_value}" | awk -v RS= -v FS='\n' -v OFS=',' '$1=$1')
|
||||||
|
fi
|
||||||
|
|
||||||
|
_bonding_opts="${_bonding_opts} $(opt_format "${_key}" "${_value}")"
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
case $_param
|
||||||
|
in
|
||||||
|
(address)
|
||||||
|
n=0
|
||||||
|
while read -r _addr
|
||||||
|
do
|
||||||
|
opt_format "IPADDR${n}" "${_addr%%/*}"
|
||||||
|
opt_format "NETMASK${n}" "$(prefix2subnet "${_addr##*/}")"
|
||||||
|
: $((n+=1))
|
||||||
|
done <"${__object}/parameter/address"
|
||||||
|
unset n _addr
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
opt_format "${_key}" "$(cat "${__object}/parameter/${_param}")"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -n "${_bonding_opts}"
|
||||||
|
then
|
||||||
|
# strip leading space
|
||||||
|
opt_format BONDING_OPTS "${_bonding_opts# }"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -f "${__object}/parameter/extra-config"
|
||||||
|
then
|
||||||
|
cat "${__object}/parameter/extra-config"
|
||||||
|
fi
|
||||||
|
} | __file "${ifcfg_file}" \
|
||||||
|
--state "${state_should}" --owner root --group root --mode 0644 \
|
||||||
|
--onchange "$(onchange_action)" --source -
|
2
cdist/conf/type/__interface_ifcfg/parameter/boolean
Normal file
2
cdist/conf/type/__interface_ifcfg/parameter/boolean
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
onboot
|
||||||
|
hotplug
|
|
@ -0,0 +1 @@
|
||||||
|
leave
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
4
cdist/conf/type/__interface_ifcfg/parameter/optional
Normal file
4
cdist/conf/type/__interface_ifcfg/parameter/optional
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
comment
|
||||||
|
name
|
||||||
|
onchange
|
||||||
|
state
|
1
cdist/conf/type/__interface_ifcfg/parameter/required
Normal file
1
cdist/conf/type/__interface_ifcfg/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bootproto
|
Loading…
Reference in a new issue