#!/bin/bash

set -eux

# Inspired by/based on glean-early.sh
# https://opendev.org/opendev/glean/src/branch/master/glean/init/glean-early.sh

# NOTE(TheJulia): We care about iso images, and would expect lower case as a
# result. In the case of VFAT partitions, they would be upper case.

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NETWORK_DATA_FILE="/mnt/ipa/openstack/latest/network_data.json"


if [ ! -f "${NETWORK_DATA_FILE}" ]; then
	echo "No network_data.json found, skipping network configuration"
	exit 1
fi

mkdir -p /tmp/nmc/{desired,generated}
cp ${NETWORK_DATA_FILE} /tmp/nmc/desired/_all.yaml

nmc generate --config-dir /tmp/nmc/desired --output-dir /tmp/nmc/generated
nmc apply --config-dir /tmp/nmc/generated
