From a2d8d6f2d7c3c44cadcb1856c2b0f03f9b4ddb18 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 31 Aug 2020 16:03:29 +0200 Subject: [PATCH] [type/__bridge] Draft ifcfg backend --- .../__bridge/files/backends/ifcfg/manifest | 109 ++++++++++++++++++ cdist/conf/type/__bridge/manifest | 3 + 2 files changed, 112 insertions(+) create mode 100755 cdist/conf/type/__bridge/files/backends/ifcfg/manifest diff --git a/cdist/conf/type/__bridge/files/backends/ifcfg/manifest b/cdist/conf/type/__bridge/files/backends/ifcfg/manifest new file mode 100755 index 00000000..68e3e76d --- /dev/null +++ b/cdist/conf/type/__bridge/files/backends/ifcfg/manifest @@ -0,0 +1,109 @@ +#!/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 . +# + +os=$(cat "${__global:?}/explorer/os") + +case $os +in + (centos|redhat|scientific) + systype=redhat + ;; + (suse) + systype=suse + set -- "$@" --extra-config BRIDGE=yes + ;; + (*) + printf "Your operating system (%s) is currently not supported by %s's ifcfg backend.\n" "${os}" "${__type##*/}" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac + + +bridge_stp='off' + +cd "${__object:?}/parameter" +for param in * +do + case $param + in + (bootproto) + bootproto=$(cat "${__object:?}/parameter/bootproto") + set -- "$@" --bootproto "${bootproto}" + ;; + (hotplug) + echo '--hotplug is not (yet) supported by the ifcfg backend.' >&2 + exit 1 + ;; + (port) + case $systype + in + (redhat) + # TOOD + ;; + (suse) + bridge_ports=$( + while read -r _port + do + test -z "$(echo "${_port}" | tr -d 'A-Za-z0-9')" || { + printf 'Invalid bridge port name: %s\n' "${_port}" >&2 + exit 1 + } + set -- "$@" "${_port}" + done <"${__object:?}/parameter/port" + echo "$*" + ) + + set -- "$@" --extra-config "BRIDGE_PORTS='${bridge_ports}'" + unset bridge_ports + ;; + esac + ;; + (stp) + bridge_stp='on' + ;; + (onboot) + # boolean parameters + set -- "$@" --"${param}" + ;; + (*) + set -- "$@" --"${param}" "$(cat "${__object:?}/parameter/${param}")" + ;; + esac +done + + +# Set boolean options +case $systype +in + (redhat) + set -- "$@" --extra-config "STP=${bridge_stp}" + test "${bridge_stp}" = 'on' || set -- "$@" --extra-config DELAY=0 + ;; + (suse) + set -- "$@" --extra-config "BRIDGE_STP=${bridge_stp}" + test "${bridge_stp}" = 'on' \ + || set -- "$@" --extra-config BRIDGE_FORWARDDELAY=0 + ;; +esac + +# Instantiate backend type +__interface_ifcfg "${__object_id:?}" --type Bridge "$@" diff --git a/cdist/conf/type/__bridge/manifest b/cdist/conf/type/__bridge/manifest index 1b9ae14b..755a09bc 100755 --- a/cdist/conf/type/__bridge/manifest +++ b/cdist/conf/type/__bridge/manifest @@ -33,6 +33,9 @@ in (devuan) impl_type=ifupdown.d ;; + (centos|redhat|scientific|suse) + impl_type=ifcfg + ;; (*) 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