changed to parse yaml for network
This commit is contained in:
parent
a0bc0eecf3
commit
68248df359
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
||||
network.env
|
||||
salt/pillars/local.sls
|
||||
|
@ -1,3 +0,0 @@
|
||||
INTERNAL_IF="eth0"
|
||||
INTERNAL_ADDRESS="192.168.0.1/24"
|
||||
EXTERNAL_IF="eth0.1000"
|
@ -1,7 +1,8 @@
|
||||
network:
|
||||
domain: suse.lan
|
||||
address: 192.168.0.0
|
||||
netaddress: 192.168.0.0
|
||||
netmask: 24
|
||||
ip: 192.168.0.1
|
||||
|
||||
interface:
|
||||
internal: eth0
|
||||
|
43
update.sh
43
update.sh
@ -40,6 +40,24 @@ function log(){
|
||||
printf "%s\n" "$*"
|
||||
}
|
||||
|
||||
function parse_yaml {
|
||||
local prefix=$2
|
||||
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
|
||||
sed -ne "s|^\($s\):|\1|" \
|
||||
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
||||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||
awk -F$fs '{
|
||||
indent = length($1)/2;
|
||||
vname[indent] = $2;
|
||||
for (i in vname) {if (i > indent) {delete vname[i]}}
|
||||
if (length($3) > 0) {
|
||||
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
||||
|
||||
function check_prerequisites(){
|
||||
set +e
|
||||
local answer
|
||||
@ -70,17 +88,20 @@ function configure_network(){
|
||||
if asktobreak; then
|
||||
return
|
||||
fi
|
||||
source network.env
|
||||
sudo nmcli connection show
|
||||
sudo nmcli connection modify "$INTERNAL_IF" ipv4.addresses "$INTERNAL_ADDRESS"
|
||||
sudo nmcli connection modify "$INTERNAL_IF" ipv4.dns "127.0.0.1, 1.1.1.1, 1.1.1.2"
|
||||
sudo nmcli connection modify "$INTERNAL_IF" ipv4.method manual
|
||||
sudo nmcli connection down "$INTERNAL_IF"
|
||||
sudo nmcli connection up "$INTERNAL_IF"
|
||||
|
||||
sudo nmcli connection add type vlan con-name "$EXTERNAL_IF" ifname "$EXTERNAL_IF" dev "$INTERNAL_IF" id "${EXTERNAL_IF#*.}"
|
||||
sudo nmcli connection modify "$EXTERNAL_IF" ipv4.method auto
|
||||
sudo nmcli connection up "$EXTERNAL_IF"
|
||||
eval $(parse_yaml salt/pillars/network.sls "SALT_")
|
||||
if [[ -f salt/pillars/local.sls ]];then
|
||||
eval $(parse_yaml salt/pillars/local.sls "SALT_")
|
||||
fi
|
||||
sudo nmcli connection modify "$SALT_network_interface_internal" ipv4.addresses "$SALT_network_ip"
|
||||
sudo nmcli connection modify "$SALT_network_interface_internal" ipv4.dns "127.0.0.1, 1.1.1.1, 1.1.1.2"
|
||||
sudo nmcli connection modify "$SALT_network_interface_internal" ipv4.method manual
|
||||
sudo nmcli connection down "$SALT_network_interface_internal"
|
||||
sudo nmcli connection up "$SALT_network_interface_internal"
|
||||
if [[ $(nmcli connection show | grep -i $SALT_network_interface_external | wc -l) == 0 ]]; then
|
||||
sudo nmcli connection add type vlan con-name "$SALT_network_interface_external" ifname "$SALT_network_interface_external" dev "$SALT_network_interface_internal" id "${SALT_network_interface_external#*.}"
|
||||
fi
|
||||
sudo nmcli connection modify "$SALT_network_interface_external" ipv4.method auto
|
||||
sudo nmcli connection up "$SALT_network_interface_external"
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user