#!/bin/bash

set -eux

### --start_docs

## Deploying a baremetal overcloud from a virtual machine undercloud
## =================================================================

## * The following set up steps are run *on the virthost machine* to allow the undercloud VM
## * to PXE boot the overcloud nodes:

## Set up the virthost machine for PXE forwarding
## ----------------------------------------------

## * Add a static IPADDR to the NIC on provisioning network
## ::

sudo cat > /etc/sysconfig/network-scripts/ifcfg-{{ virthost_provisioning_interface }} << EOF
NAME={{ virthost_provisioning_interface }}
IPADDR={{ virthost_provisioning_ip }}
NETMASK={{ virthost_provisioning_netmask }}
NM_CONTROLLED=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
ONBOOT=yes
HWADDR={{ virthost_provisioning_hwaddr }}
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
EOF

## * Bring the NIC down first
## ::

sudo ifdown {{ virthost_provisioning_interface }}

## * Bring the NIC up again
## ::

sudo ifup {{ virthost_provisioning_interface }}

## * Add the NIC on the provisioning interface to the "brovc" bridge
## ::

if ! sudo brctl show brovc | grep {{ virthost_provisioning_interface }}; then
    sudo brctl addif brovc {{ virthost_provisioning_interface }}
fi

### --stop_docs
