Cisco Vendor Code for Neutron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cisco_router 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Cisco router service plugin
  2. # ---------------------------
  3. # Save trace setting
  4. MY_XTRACE=$(set +o | grep xtrace)
  5. set +o xtrace
  6. Q_CISCO_DEFAULT_ROUTER_TYPE=${Q_CISCO_DEFAULT_ROUTER_TYPE:-ASR1k_router}
  7. CISCO_ROUTER_PLUGIN=networking_cisco.plugins.cisco.service_plugins.cisco_router_plugin.CiscoRouterPlugin
  8. CISCO_DEVMGR_PLUGIN=networking_cisco.plugins.cisco.service_plugins.cisco_device_manager_plugin.CiscoDeviceManagerPlugin
  9. CISCO_ROUTER_PLUGIN_CONF_FILE=cisco_router_plugin.ini
  10. CISCO_DEVMGR_PLUGIN_CONF_FILE=cisco_device_manager_plugin.ini
  11. PLUGIN_CONFIG_DIR=$NEUTRON_CONF_DIR/plugins/cisco
  12. NET_CISCO_CONF_DIR=$DIR_CISCO/etc/neutron/plugins/cisco
  13. function neutron_cisco_router_configure_common() {
  14. Q_L3_ENABLED=True
  15. Q_L3_ROUTER_PER_TENANT=True
  16. _clear_L3_plugin
  17. _neutron_service_plugin_class_add $CISCO_DEVMGR_PLUGIN
  18. _neutron_service_plugin_class_add $CISCO_ROUTER_PLUGIN
  19. mkdir -p $PLUGIN_CONFIG_DIR
  20. cp $NET_CISCO_CONF_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE $PLUGIN_CONFIG_DIR/
  21. cp $NET_CISCO_CONF_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE $PLUGIN_CONFIG_DIR/
  22. Q_CISCO_ROUTER_PLUGIN_CONF_FILE=$PLUGIN_CONFIG_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE
  23. Q_CISCO_DEVMGR_PLUGIN_CONF_FILE=$PLUGIN_CONFIG_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE
  24. Q_PLUGIN_EXTRA_CONF_FILES=(${Q_PLUGIN_EXTRA_CONF_FILES[@]} $Q_CISCO_ROUTER_PLUGIN_CONF_FILE)
  25. Q_PLUGIN_EXTRA_CONF_FILES=(${Q_PLUGIN_EXTRA_CONF_FILES[@]} $Q_CISCO_DEVMGR_PLUGIN_CONF_FILE)
  26. # Copy policy.json from networking-cisco/etc to the neutron/etc folder
  27. echo "Copying policy.json from ${DIR_CISCO}/etc/ to ${NEUTRON_CONF_DIR}"
  28. cp $DIR_CISCO/etc/policy.json $Q_POLICY_FILE
  29. _inject_deployer_config
  30. _patch_neutron_legacy
  31. iniset $Q_CISCO_ROUTER_PLUGIN_CONF_FILE routing default_router_type $Q_CISCO_DEFAULT_ROUTER_TYPE
  32. }
  33. function neutron_cisco_router_configure_driver() {
  34. :
  35. }
  36. function neutron_cisco_router_stop() {
  37. :
  38. }
  39. # inject any deployer provided configurations
  40. function _inject_deployer_config() {
  41. ROUTER_INJECT_FILE=$TOP_DIR/cisco_router_plugin.inject
  42. # inject any deployer provided configurations
  43. if [[ -f $ROUTER_INJECT_FILE ]]; then
  44. cat $ROUTER_INJECT_FILE >> $Q_CISCO_ROUTER_PLUGIN_CONF_FILE
  45. fi
  46. # Inject device manager configs
  47. DEVMGR_INJECT_FILE=$TOP_DIR/cisco_device_manager_plugin.inject
  48. if [[ -f $DEVMGR_INJECT_FILE ]]; then
  49. cat $DEVMGR_INJECT_FILE >> $Q_CISCO_DEVMGR_PLUGIN_CONF_FILE
  50. fi
  51. }
  52. function _clear_L3_plugin() {
  53. if [[ ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${ML2_L3_PLUGIN}, ]]; then
  54. echo "Found L3 plugin configured..Proceeding to delete it"
  55. Q_SERVICE_PLUGIN_CLASSES=${Q_SERVICE_PLUGIN_CLASSES##$ML2_L3_PLUGIN}
  56. echo "service plugins="$Q_SERVICE_PLUGIN_CLASSES
  57. fi
  58. }
  59. # lines in neutron-legacy that need to be changed to be compatible with cisco router plugin
  60. TO_REPLACE[0]=$(cat <<'EOF'
  61. 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; }'`;
  62. EOF
  63. )
  64. TO_REPLACE[1]=$(cat <<'EOF'
  65. 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; }'`;
  66. EOF
  67. )
  68. REPLACE_WITH[0]=$(cat <<'EOF'
  69. 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]; } }'`;
  70. EOF
  71. )
  72. REPLACE_WITH[1]=$(cat <<'EOF'
  73. 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]; } }'`;
  74. EOF
  75. )
  76. function _patch_neutron_legacy() {
  77. # Redefine functions in neutron-legacy that configure v4 and v6 routers so gateway ip is determined in a way compatible with our plugin
  78. original_definition=$(declare -f _neutron_configure_router_v4)
  79. 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; }')
  80. eval "$new_definition"
  81. original_definition=$(declare -f _neutron_configure_router_v6)
  82. 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; }')
  83. eval "$new_definition"
  84. }
  85. # Restore xtrace
  86. $MY_XTRACE