125 lines
5.1 KiB
Plaintext
125 lines
5.1 KiB
Plaintext
# Cisco router service plugin
|
|
# ---------------------------
|
|
|
|
# Save trace setting
|
|
MY_XTRACE=$(set +o | grep xtrace)
|
|
set +o xtrace
|
|
|
|
Q_CISCO_DEFAULT_ROUTER_TYPE=${Q_CISCO_DEFAULT_ROUTER_TYPE:-ASR1k_router}
|
|
|
|
CISCO_ROUTER_PLUGIN=networking_cisco.plugins.cisco.service_plugins.cisco_router_plugin.CiscoRouterPlugin
|
|
CISCO_DEVMGR_PLUGIN=networking_cisco.plugins.cisco.service_plugins.cisco_device_manager_plugin.CiscoDeviceManagerPlugin
|
|
|
|
CISCO_ROUTER_PLUGIN_CONF_FILE=cisco_router_plugin.ini
|
|
CISCO_DEVMGR_PLUGIN_CONF_FILE=cisco_device_manager_plugin.ini
|
|
|
|
NET_CISCO_SOURCE_CONF_DIR=etc/neutron/plugins/cisco
|
|
NET_CISCO_PLUGIN_DIR=/plugins/cisco
|
|
PLUGIN_CONFIG_DIR=$NEUTRON_CONF_DIR$NET_CISCO_PLUGIN_DIR
|
|
NET_CISCO_CONF_DIR=$DIR_CISCO$PLUGIN_CONFIG_DIR
|
|
|
|
|
|
function neutron_cisco_router_configure_common() {
|
|
Q_L3_ENABLED=True
|
|
Q_L3_ROUTER_PER_TENANT=True
|
|
|
|
_clear_L3_plugin
|
|
|
|
_neutron_service_plugin_class_add $CISCO_DEVMGR_PLUGIN
|
|
_neutron_service_plugin_class_add $CISCO_ROUTER_PLUGIN
|
|
|
|
mkdir -p $PLUGIN_CONFIG_DIR
|
|
|
|
cp $NET_CISCO_SOURCE_CONF_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE $PLUGIN_CONFIG_DIR/
|
|
cp $NET_CISCO_SOURCE_CONF_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE $PLUGIN_CONFIG_DIR/
|
|
|
|
NEUTRON_VERSION=$(pip show neutron | grep Version| egrep -o '[0-9]+' | head -1)
|
|
if [[ NEUTRON_VERSION -ge 10 ]]; then
|
|
Q_CISCO_ROUTER_PLUGIN_CONF_FILE=$NET_CISCO_PLUGIN_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE
|
|
Q_CISCO_DEVMGR_PLUGIN_CONF_FILE=$NET_CISCO_PLUGIN_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE
|
|
else
|
|
Q_CISCO_ROUTER_PLUGIN_CONF_FILE=$PLUGIN_CONFIG_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE
|
|
Q_CISCO_DEVMGR_PLUGIN_CONF_FILE=$PLUGIN_CONFIG_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE
|
|
fi
|
|
|
|
Q_PLUGIN_EXTRA_CONF_FILES=(${Q_PLUGIN_EXTRA_CONF_FILES[@]} $Q_CISCO_ROUTER_PLUGIN_CONF_FILE)
|
|
Q_PLUGIN_EXTRA_CONF_FILES=(${Q_PLUGIN_EXTRA_CONF_FILES[@]} $Q_CISCO_DEVMGR_PLUGIN_CONF_FILE)
|
|
|
|
# Copy policy.json from networking-cisco/etc to the neutron/etc folder
|
|
echo "Copying policy.json from ${DIR_CISCO}/etc/ to ${NEUTRON_CONF_DIR}"
|
|
cp $DIR_CISCO/etc/policy.json $Q_POLICY_FILE
|
|
|
|
_inject_deployer_config
|
|
|
|
_patch_neutron_legacy
|
|
|
|
iniset $NEUTRON_CONF_DIR$Q_CISCO_ROUTER_PLUGIN_CONF_FILE routing default_router_type $Q_CISCO_DEFAULT_ROUTER_TYPE
|
|
|
|
}
|
|
|
|
function neutron_cisco_router_configure_driver() {
|
|
:
|
|
}
|
|
|
|
function neutron_cisco_router_stop() {
|
|
:
|
|
}
|
|
|
|
# inject any deployer provided configurations
|
|
function _inject_deployer_config() {
|
|
ROUTER_INJECT_FILE=$TOP_DIR/cisco_router_plugin.inject
|
|
# inject any deployer provided configurations
|
|
if [[ -f $ROUTER_INJECT_FILE ]]; then
|
|
cat $ROUTER_INJECT_FILE >> $NEUTRON_CONF_DIR$Q_CISCO_ROUTER_PLUGIN_CONF_FILE
|
|
fi
|
|
|
|
# Inject device manager configs
|
|
DEVMGR_INJECT_FILE=$TOP_DIR/cisco_device_manager_plugin.inject
|
|
if [[ -f $DEVMGR_INJECT_FILE ]]; then
|
|
cat $DEVMGR_INJECT_FILE >> $NEUTRON_CONF_DIR$Q_CISCO_DEVMGR_PLUGIN_CONF_FILE
|
|
fi
|
|
}
|
|
|
|
|
|
function _clear_L3_plugin() {
|
|
if [[ ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${ML2_L3_PLUGIN}, ]]; then
|
|
echo "Found L3 plugin configured..Proceeding to delete it"
|
|
|
|
Q_SERVICE_PLUGIN_CLASSES=${Q_SERVICE_PLUGIN_CLASSES##$ML2_L3_PLUGIN}
|
|
echo "service plugins="$Q_SERVICE_PLUGIN_CLASSES
|
|
fi
|
|
}
|
|
|
|
|
|
# lines in neutron-legacy that need to be changed to be compatible with cisco router plugin
|
|
TO_REPLACE[0]=$(cat <<'EOF'
|
|
ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$PUB_SUBNET_ID '$4 == subnet_id { print $8; }'`;
|
|
EOF
|
|
)
|
|
TO_REPLACE[1]=$(cat <<'EOF'
|
|
IPV6_ROUTER_GW_IP=`neutron port-list -c fixed_ips | grep $ipv6_pub_subnet_id | awk -F '"' -v subnet_id=$ipv6_pub_subnet_id '$4 == subnet_id { print $8; }'`;
|
|
EOF
|
|
)
|
|
|
|
REPLACE_WITH[0]=$(cat <<'EOF'
|
|
ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner -c device_id | awk -F '|' -v router_id=$ROUTER_ID -v subnet_id=$PUB_SUBNET_ID '/gateway/ { gsub(" ", "", $4); if ($4 == router_id) { split($2, res, "\\\""); if (res[4] == subnet_id) print res[8]; } }'`;
|
|
EOF
|
|
)
|
|
REPLACE_WITH[1]=$(cat <<'EOF'
|
|
IPV6_ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_id | awk -F '|' -v router_id=$ROUTER_ID -v subnet_id=$ipv6_pub_subnet_id '{ gsub(" ", "", $3); if ($3 == router_id) { split($2, res, "\\\""); if (res[4] == subnet_id) print res[8]; } }'`;
|
|
EOF
|
|
)
|
|
|
|
function _patch_neutron_legacy() {
|
|
# Redefine functions in neutron-legacy that configure v4 and v6 routers so gateway ip is determined in a way compatible with our plugin
|
|
original_definition=$(declare -f _neutron_configure_router_v4)
|
|
new_definition=$(echo "$original_definition" | awk -v to_replace="${TO_REPLACE[0]}" -v replace_with="${REPLACE_WITH[0]}" '{ match($0, /^ */); if (substr($0, RLENGTH+1) == to_replace) print substr($0, 1, RLENGTH)replace_with; else print $0; }')
|
|
eval "$new_definition"
|
|
original_definition=$(declare -f _neutron_configure_router_v6)
|
|
new_definition=$(echo "$original_definition" | awk -v to_replace="${TO_REPLACE[1]}" -v replace_with="${REPLACE_WITH[1]}" '{ match($0, /^ */); if (substr($0, RLENGTH+1) == to_replace) print substr($0, 1, RLENGTH)replace_with; else print $0; }')
|
|
eval "$new_definition"
|
|
}
|
|
|
|
# Restore xtrace
|
|
$MY_XTRACE
|