#!/bin/bash

NETWORKING_MIDONET_DIR=${NETWORKING_MIDONET_DIR:=$DEST/networking-midonet}

# lib/neutron vs lib/neutron-legacy compat
Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}

# Use MidoNet binary packages
MIDONET_USE_PACKAGE=${MIDONET_USE_PACKAGE:-True}
MIDONET_DEB_URI=${MIDONET_DEB_URI:-http://builds.midonet.org/midonet-5.4}
MIDONET_DEB_SUITE=${MIDONET_DEB_SUITE:-unstable}
MIDONET_DEB_COMPONENT=${MIDONET_DEB_COMPONENT:-main}
MIDONET_YUM_URI=${MIDONET_YUM_URI:-https://builds.midonet.org/midonet-5.4/unstable/el7}

# MidoNet repo
# Ignored if MIDONET_USE_PACKAGE=True
MIDONET_REPO=${MIDONET_REPO:-http://github.com/midonet/midonet.git}
MIDONET_BRANCH=${MIDONET_BRANCH:-staging/v5.4}
MIDONET_DIR=${MIDONET_DIR:-$DEST/midonet}

# Set up cassndra (for flow state etc)
MIDONET_USE_CASSANDRA=${MIDONET_USE_CASSANDRA:-False}

# Configure NAT for public network.
# You need to configure PUBLIC_INTERFACE properly.
MIDONET_USE_UPLINK_NAT=${MIDONET_USE_UPLINK_NAT:-False}

# MidoNet service endpoint configuration
MIDONET_SERVICE_API_PORT=${MIDONET_SERVICE_API_PORT:-8181}
MIDONET_SERVICE_PROTOCOL=${MIDONET_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
MIDONET_SERVICE_HOST=${MIDONET_SERVICE_HOST:-$SERVICE_HOST}
MIDONET_API_URL="${MIDONET_SERVICE_PROTOCOL}://${MIDONET_SERVICE_HOST}:${MIDONET_SERVICE_API_PORT}/midonet-api"

# MidoNet Plugin and Client
MIDONET_PLUGIN=${MIDONET_PLUGIN:-midonet_v2}
MIDONET_CLIENT=${MIDONET_CLIENT:-midonet.neutron.client.api.MidonetApiClient}

# Midonet metadata service
MIDONET_USE_METADATA=${MIDONET_USE_METADATA:-False}
MIDONET_NOVA_METADATA_URL=${MIDONET_NOVA_METADATA_URL:-http://${Q_META_DATA_IP}:8775}
MIDONET_METADATA_SHARED_SECRET=${MIDONET_METADATA_SHARED_SECRET:-}

# Use Keystone for MidoNet API auth.  If False, use a mock.
MIDONET_USE_KEYSTONE=${MIDONET_USE_KEYSTONE:-True}

# create the fake uplink by default
MIDONET_CREATE_FAKE_UPLINK=${MIDONET_CREATE_FAKE_UPLINK:-True}

# Cluster Topology API
TOPOLOGY_API_PORT=${TOPOLOGY_API_PORT:-8088}

#
# Set all the devstack ENV VARS needed to run midonet in a full OpenStack
# deployment setting
#

# Routers should be per tenant
Q_L3_ROUTER_PER_TENANT=True

# Enable L3
Q_L3_ENABLED=True

# Use IPv4
IP_VERSION=4

# Tempest options
IPV6_ENABLED=False

NETWORK_API_EXTENSIONS=agent,binding,dhcp_agent_scheduler,external-net
NETWORK_API_EXTENSIONS+=,ext-gw-mode,extra_dhcp_opt,quotas,router
NETWORK_API_EXTENSIONS+=,security-group,subnet_allocation
NETWORK_API_EXTENSIONS+=,network-ip-availability,auto-allocated-topology
NETWORK_API_EXTENSIONS+=,timestamp_core,tag,service-type,rbac-policies
NETWORK_API_EXTENSIONS+=,standard-attr-description
NETWORK_API_EXTENSIONS+=,standard-attr-revisions
NETWORK_API_EXTENSIONS+=,standard-attr-timestamp
NETWORK_API_EXTENSIONS+=,pagination
NETWORK_API_EXTENSIONS+=,sorting
NETWORK_API_EXTENSIONS+=,project-id
NETWORK_API_EXTENSIONS+=,flavors
NETWORK_API_EXTENSIONS+=,allowed-address-pairs,extraroute,port-security
NETWORK_API_EXTENSIONS+=,router-interface-fip
NETWORK_API_EXTENSIONS+=,provider
NETWORK_API_EXTENSIONS+=,fip64
if is_service_enabled q-fwaas neutron-fwaas-v1; then
    NETWORK_API_EXTENSIONS+=,fwaas,fwaasrouterinsertion
fi
if is_service_enabled neutron-vpnaas; then
    NETWORK_API_EXTENSIONS+=,vpnaas
    NETWORK_API_EXTENSIONS+=,vpn-endpoint-groups
fi
if is_service_enabled taas; then
    NETWORK_API_EXTENSIONS+=,taas
fi
if is_service_enabled q-qos neutron-qos; then
    NETWORK_API_EXTENSIONS+=,qos
fi
if is_service_enabled q-lbaasv2 neutron-lbaasv2; then
    NETWORK_API_EXTENSIONS+=,lbaasv2
fi
# REVISIT(yamamoto): This relies on the order of plugins unless q-dr
# is explicitly enabled in local.conf because neutron-dynamic-routing
# uses their devstack/settings to enable services.
if is_service_enabled q-dr; then
    NETWORK_API_EXTENSIONS+=,bgp
    NETWORK_API_EXTENSIONS+=,bgp-speaker-router-insertion
fi

# Don't let mido.sh configure the logging
CONFIGURE_LOGGING=False

# NOTE(yamamoto): Grenade assumes some of functions are available early.
ABSOLUTE_PATH=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
Q_PLUGIN=${Q_PLUGIN:-$NEUTRON_CORE_PLUGIN}
source $ABSOLUTE_PATH/functions
source $ABSOLUTE_PATH/$Q_PLUGIN/functions
