#!/bin/bash
#
# lib/networking-baremetal
# # Functions to control the configuration and operation of the **Networking Baremetal**

# Dependencies:
# (none)

# Save trace setting
_XTRACE_NETWORKING_BAREMETAL=$(set +o | grep xtrace)
set +o xtrace

# Defaults
# --------

# networking-baremetal service
NETWORKING_BAREMETAL_REPO=${NETWORKING_BAREMETAL_REPO:-${GIT_BASE}/openstack/networking-baremetal.git}
NETWORKING_BAREMETAL_BRANCH=${NETWORKING_BAREMETAL_BRANCH:-master}

NETWORKING_BAREMETAL_DIR=${NETWORKING_BAREMETAL_DIR:-$DEST/networking-baremetal}
NETWORKING_BAREMETAL_DATA_DIR=""$DATA_DIR/networking-baremetal""

# Support entry points installation of console scripts
NETWORKING_BAREMETAL_BIN_DIR=$(get_python_exec_prefix)


# Functions
# ---------

function install_networking_baremetal {
    setup_develop $NETWORKING_BAREMETAL_DIR
}


function configure_networking_baremetal {
    if [[ -z "$Q_ML2_PLUGIN_MECHANISM_DRIVERS" ]]; then
        Q_ML2_PLUGIN_MECHANISM_DRIVERS='baremetal'
    else
        if [[ ! $Q_ML2_PLUGIN_MECHANISM_DRIVERS =~ $(echo '\<baremetal\>') ]]; then
            Q_ML2_PLUGIN_MECHANISM_DRIVERS+=',baremetal'
        fi
    fi
    populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 mechanism_drivers=$Q_ML2_PLUGIN_MECHANISM_DRIVERS
}

function configure_networking_baremetal_neutron_agent {
    configure_keystone_authtoken_middleware $NEUTRON_CONF ironic ironic
    configure_placement_nova_compute $NEUTRON_CONF
}

function start_networking_baremetal_neutron_agent {
    run_process ir-neutronagt "$NETWORKING_BAREMETAL_BIN_DIR/ironic-neutron-agent"
}

function stop_networking_baremetal_neutron_agent {
    stop_process ir-neutronagt
}

function cleanup_networking_baremetal {
    rm -rf $NETWORKING_BAREMETAL_DATA_DIR
}
