| #!/bin/sh -e |
| # |
| # rc.local |
| # |
| # This script is executed at the end of each multiuser runlevel. |
| # Make sure that the script will "exit 0" on success or any other |
| # value on error. |
| # |
| # In order to enable or disable this script just change the execution |
| # bits. |
| # |
| # By default this script does nothing. |
| |
| update_from_metadata_fields() { |
| local metadataIp="169.254.169.254" |
| local metadataFiels=$(curl -s --connect-timeout 5 169.254.169.254/openstack/latest/meta_data.json | jq -r .meta) |
| if [ -n "${metadataFiels}" ]; then |
| local dmz=$(echo ${metadataFiels} | jq -r .dmz) |
| if [ "${dmz}" == "true" ] |
| local dmzGateway=$(echo ${metadataFiels} | jq -r .dmz_gateway) |
| if [ -n "${dmzGateway}" ]; then |
| local curDefault=$(ip r | grep 'default via' | cut -f 3 -d ' ') |
| if [ "${curDefault}" != "${dmzGateway}" ]; then |
| ip r del default |
| ip r add default via ${dmzGateway} |
| fi |
| fi |
| fi |
| fi |
| } |
| |
| if [ ! -f /tmp/bootstrap_interfaces ] && [ -d /srv/salt/reclass/nodes/_generated ]; then |
| sed -i "s/single_address:.*/single_address: $(hostname -I | cut -d ' ' -f 1)/g" /srv/salt/reclass/nodes/cfg01.* |
| touch /tmp/bootstrap_interfaces |
| fi |
| |
| update_from_metadata_fields || echo "Can't update settings from metadata fields" |
| |
| exit 0 |