Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 66 additions & 12 deletions scripts/ironic-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ get_provisioning_interface()

local interface="provisioning"

if [[ -n "${PROVISIONING_IP}" ]]; then
if ip -br addr show | grep -i " ${PROVISIONING_IP}/" &>/dev/null; then
interface="$(ip -br addr show | grep -i " ${PROVISIONING_IP}/" | cut -f 1 -d ' ' | cut -f 1 -d '@')"
fi
fi

for mac in ${PROVISIONING_MACS//,/ }; do
if ip -br link show up | grep -i "$mac" &>/dev/null; then
interface="$(ip -br link show up | grep -i "$mac" | cut -f 1 -d ' ' | cut -f 1 -d '@')"
Expand All @@ -69,21 +63,81 @@ export PROVISIONING_INTERFACE

export LISTEN_ALL_INTERFACES="${LISTEN_ALL_INTERFACES:-true}"

get_interface_of_ip()
{
local IP_VERS
local IP_ADDR

if [[ $# -gt 2 ]]; then
echo "ERROR: ${FUNCNAME[0]}: too many parameters" >&2
exit 1
fi

if [[ $# -eq 2 ]]; then
case "$2" in
4|6)
IP_VERS="-$2"
;;
*)
echo "ERROR: ${FUNCNAME[0]}: the second parameter should be [4|6] (or missing for both)" >&2
exit 1
;;
esac
fi

IP_ADDR="$1"

if ip "${IP_VERS[@]}" -br addr show | grep -F " ${IP_ADDR}/" &>/dev/null; then
ip "${IP_VERS[@]}" -br addr show | grep -F " ${IP_ADDR}/" | cut -f 1 -d ' ' | cut -f 1 -d '@'
fi
}

parse_ip_address()
{
local IP_ADDR

if [[ $# -ne 1 ]]; then
echo "ERROR: ${FUNCNAME[0]}: please provide a single IP address as input" >&2
exit 1
fi

IP_ADDR="$1"

if ipcalc "${IP_ADDR}" | grep ^INVALID &>/dev/null; then
echo "ERROR: ${FUNCNAME[0]}: Failed to parse ${IP_ADDR}" >&2
return 1
fi

# Convert the address using ipcalc which strips out the subnet.
# For IPv6 addresses, this will give the short-form address
ipcalc "${IP_ADDR}" | grep "^Address:" | awk '{print $2}'
}

# Wait for the interface or IP to be up, sets $IRONIC_IP
wait_for_interface_or_ip()
{
# If $PROVISIONING_IP is specified, then we wait for that to become
# available on an interface, otherwise we look at $PROVISIONING_INTERFACE
# for an IP
if [[ -n "${PROVISIONING_IP}" ]]; then
# Convert the address using ipcalc which strips out the subnet.
# For IPv6 addresses, this will give the short-form address
IRONIC_IP="$(ipcalc "${PROVISIONING_IP}" | grep "^Address:" | awk '{print $2}')"
export IRONIC_IP
until grep -F " ${IRONIC_IP}/" <(ip -br addr show); do
echo "Waiting for ${IRONIC_IP} to be configured on an interface"
local PARSED_IP
PARSED_IP="$(parse_ip_address "${PROVISIONING_IP}")"
if [[ -z "${PARSED_IP}" ]]; then
echo "ERROR: PROVISIONING_IP contains an invalid IP address, failed to start ironic"
exit 1
fi

local IFACE_OF_IP=""
until [[ -n "${IFACE_OF_IP}" ]]; do
echo "Waiting for ${PROVISIONING_IP} to be configured on an interface..."
IFACE_OF_IP="$(get_interface_of_ip "${PARSED_IP}")"
Comment thread
mchiappero marked this conversation as resolved.
sleep 1
done

echo "Found ${PROVISIONING_IP} on interface \"${IFACE_OF_IP}\"!"

export PROVISIONING_INTERFACE="${IFACE_OF_IP}"
export IRONIC_IP="${PARSED_IP}"
else
until [[ -n "$IRONIC_IP" ]]; do
echo "Waiting for ${PROVISIONING_INTERFACE} interface to be configured"
Expand Down
Loading