Add function for host interfaces

Moved from alterator-net-bond.
This commit is contained in:
Mikhail Efremov 2016-03-21 19:11:21 +03:00
parent 2ccff10451
commit aafe8a4b11

View File

@ -807,6 +807,73 @@ init_slave_eth_iface_cache()
write_iface_option "$cachedir/$name" CONFIG_IPV6 no
}
# slaves list must be separated with ';', spaces or new lines
host_add_slaves_with_cache()
{
local cachedir="$1"; shift
local host_iface="$1"; shift
local slaves="$1"; shift
local ifacedir="$cachedir/$host_iface"
local h= i= new_slaves=
[ -n "$cachedir" -a -n "$host_iface" -a "$slaves" -a -d "$ifacedir" ] || return 1
h="$(read_iface_host_var "$ifacedir")"
local IFS=' ;
'
for i in $slaves; do
new_slaves="$new_slaves${new_slaves:+ }$i"
init_slave_eth_iface_cache "$cachedir" "$i"
done
if [ -n "$h" ]; then
h="$h $new_slaves"
else
h="$new_slaves"
fi
write_iface_option "$ifacedir" HOST "\"$h\""
}
# slaves list must be separated with ';', spaces or new lines
host_del_slaves_with_cache()
{
local cachedir="$1"; shift
local host_iface="$1"; shift
local slaves="$1"; shift
local ifacedir="$cachedir/$host_iface"
local i=
[ -n "$cachedir" -a -n "$host_iface" -a "$slaves" -a -f "$ifacedir/options" ] || return 1
local IFS=' ;
'
for i in $slaves; do
sed -i -r "/^HOST=/{s/$i//; s/ +/ /; s/=([\"'])? /=\1/; s/ ([\"'])?$/\1/}" "$ifacedir/options"
if [ ! -d "$cachedir/$i" ]; then
cp -a "$etcnet_iface_dir/$i" "$cachedir/"
fi
write_iface_option "$cachedir/$i" CONFIG_IPV4 yes
done
}
remove_host_iface_with_cache()
{
local cachedir="$1"; shift
local host_iface="$1"; shift
local ifacedir="$cachedir/$host_iface"
local h=
[ -n "$cachedir" -a -n "$host_iface" ] || return 1
[ -d "$ifacedir" ] && ! iface_will_removed "$cachedir" "$host_iface" || return 0
h="$(read_iface_host_var "$ifacedir")"
host_del_slaves_with_cache "$cachedir" "$host_iface" "$h"
remove_iface_with_cache "$cachedir" "$host_iface"
}
next_iface_with_cache()
{
local cachedir="$1"; shift