| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
 | 2 | # | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 3 | # Neutron Cisco plugin | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 4 | # --------------------------- | 
 | 5 |  | 
 | 6 | # Save trace setting | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 7 | _XTRACE_NEUTRON_CISCO=$(set +o | grep xtrace) | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 8 | set +o xtrace | 
 | 9 |  | 
 | 10 | # Scecify the VSM parameters | 
 | 11 | Q_CISCO_PLUGIN_VSM_IP=${Q_CISCO_PLUGIN_VSM_IP:-} | 
 | 12 | # Specify the VSM username | 
 | 13 | Q_CISCO_PLUGIN_VSM_USERNAME=${Q_CISCO_PLUGIN_VSM_USERNAME:-admin} | 
 | 14 | # Specify the VSM passward for above username | 
 | 15 | Q_CISCO_PLUGIN_VSM_PASSWORD=${Q_CISCO_PLUGIN_VSM_PASSWORD:-} | 
 | 16 | # Specify the uVEM integration bridge name | 
 | 17 | Q_CISCO_PLUGIN_INTEGRATION_BRIDGE=${Q_CISCO_PLUGIN_INTEGRATION_BRIDGE:-br-int} | 
 | 18 | # Specify if tunneling is enabled | 
 | 19 | Q_CISCO_PLUGIN_ENABLE_TUNNELING=${Q_CISCO_PLUGIN_ENABLE_TUNNELING:-True} | 
 | 20 | # Specify the VXLAN range | 
 | 21 | Q_CISCO_PLUGIN_VXLAN_ID_RANGES=${Q_CISCO_PLUGIN_VXLAN_ID_RANGES:-5000:10000} | 
 | 22 | # Specify the VLAN range | 
 | 23 | Q_CISCO_PLUGIN_VLAN_RANGES=${Q_CISCO_PLUGIN_VLAN_RANGES:-vlan:1:4094} | 
 | 24 |  | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 25 | # This routine put a prefix on an existing function name | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 26 | function _prefix_function { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 27 |     declare -F $1 > /dev/null || die "$1 doesn't exist" | 
 | 28 |     eval "$(echo "${2}_${1}()"; declare -f ${1} | tail -n +2)" | 
 | 29 | } | 
 | 30 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 31 | function _has_n1kv_subplugin { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 32 |     local subplugin | 
 | 33 |     for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do | 
 | 34 |         if [[ "$subplugin" == "n1kv" ]]; then | 
 | 35 |             return 0 | 
 | 36 |         fi | 
 | 37 |     done | 
 | 38 |     return 1 | 
 | 39 | } | 
 | 40 |  | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 41 | # Prefix openvswitch plugin routines with "ovs" in order to differentiate from | 
 | 42 | # cisco plugin routines. This means, ovs plugin routines will coexist with cisco | 
 | 43 | # plugin routines in this script. | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 44 | source $TOP_DIR/lib/neutron_plugins/openvswitch | 
 | 45 | _prefix_function neutron_plugin_create_nova_conf ovs | 
 | 46 | _prefix_function neutron_plugin_install_agent_packages ovs | 
 | 47 | _prefix_function neutron_plugin_configure_common ovs | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 48 | _prefix_function neutron_plugin_configure_dhcp_agent ovs | 
 | 49 | _prefix_function neutron_plugin_configure_l3_agent ovs | 
 | 50 | _prefix_function neutron_plugin_configure_plugin_agent ovs | 
 | 51 | _prefix_function neutron_plugin_configure_service ovs | 
 | 52 | _prefix_function neutron_plugin_setup_interface_driver ovs | 
 | 53 | _prefix_function has_neutron_plugin_security_group ovs | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 54 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 55 | function has_neutron_plugin_security_group { | 
| Pritesh Kothari | 107278f | 2014-09-15 09:29:55 -0700 | [diff] [blame] | 56 |     return 1 | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 57 | } | 
 | 58 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 59 | function is_neutron_ovs_base_plugin { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 60 |     return | 
 | 61 | } | 
 | 62 |  | 
 | 63 | # populate required nova configuration parameters | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 64 | function neutron_plugin_create_nova_conf { | 
| Pritesh Kothari | 107278f | 2014-09-15 09:29:55 -0700 | [diff] [blame] | 65 |     _neutron_ovs_base_configure_nova_vif_driver | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 66 | } | 
 | 67 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 68 | function neutron_plugin_install_agent_packages { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 69 |     # Cisco plugin uses openvswitch to operate in one of its configurations | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 70 |     ovs_neutron_plugin_install_agent_packages | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 71 | } | 
 | 72 |  | 
 | 73 | # Configure common parameters | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 74 | function neutron_plugin_configure_common { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 75 |     # setup default subplugins | 
 | 76 |     if [ ! -v Q_CISCO_PLUGIN_SUBPLUGINS ]; then | 
 | 77 |         declare -ga Q_CISCO_PLUGIN_SUBPLUGINS | 
| Pritesh Kothari | 107278f | 2014-09-15 09:29:55 -0700 | [diff] [blame] | 78 |         Q_CISCO_PLUGIN_SUBPLUGINS=(n1kv) | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 79 |     fi | 
| Pritesh Kothari | 107278f | 2014-09-15 09:29:55 -0700 | [diff] [blame] | 80 |     Q_PLUGIN_CONF_PATH=etc/neutron/plugins/cisco | 
 | 81 |     Q_PLUGIN_CONF_FILENAME=cisco_plugins.ini | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 82 |     Q_PLUGIN_CLASS="neutron.plugins.cisco.network_plugin.PluginV2" | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 83 | } | 
 | 84 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 85 | function neutron_plugin_configure_dhcp_agent { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 86 |     iniset $Q_DHCP_CONF_FILE DEFAULT dhcp_agent_manager neutron.agent.dhcp_agent.DhcpAgentWithStateReport | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 87 | } | 
 | 88 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 89 | function neutron_plugin_configure_l3_agent { | 
| Rob | 2a6215d | 2014-10-20 13:28:47 +0100 | [diff] [blame] | 90 |     : | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 91 | } | 
 | 92 |  | 
 | 93 | # Configure n1kv plugin | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 94 | function _configure_n1kv_subplugin { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 95 |     local cisco_cfg_file=$1 | 
 | 96 |  | 
 | 97 |     # populate the cisco plugin cfg file with the VSM information | 
 | 98 |     echo "Configuring n1kv in $cisco_cfg_file-- $Q_CISCO_PLUGIN_VSM_IP $Q_CISCO_PLUGIN_VSM_USERNAME $Q_CISCO_PLUGIN_VSM_PASSWORD" | 
 | 99 |     iniset $cisco_cfg_file N1KV:$Q_CISCO_PLUGIN_VSM_IP username $Q_CISCO_PLUGIN_VSM_USERNAME | 
 | 100 |     iniset $cisco_cfg_file N1KV:$Q_CISCO_PLUGIN_VSM_IP password $Q_CISCO_PLUGIN_VSM_PASSWORD | 
 | 101 |  | 
 | 102 |     iniset $cisco_cfg_file CISCO_N1K integration_bridge $Q_CISCO_PLUGIN_INTEGRATION_BRIDGE | 
 | 103 |     iniset $cisco_cfg_file CISCO_N1K enable_tunneling $Q_CISCO_PLUGIN_ENABLE_TUNNELING | 
 | 104 |     iniset $cisco_cfg_file CISCO_N1K vxlan_id_ranges $Q_CISCO_PLUGIN_VXLAN_ID_RANGES | 
 | 105 |     iniset $cisco_cfg_file CISCO_N1K network_vlan_ranges $Q_CISCO_PLUGIN_VLAN_RANGES | 
 | 106 |  | 
 | 107 |     # Setup the integration bridge by calling the ovs_base | 
 | 108 |     OVS_BRIDGE=$Q_CISCO_PLUGIN_INTEGRATION_BRIDGE | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 109 |     _neutron_ovs_base_setup_bridge $OVS_BRIDGE | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 110 | } | 
 | 111 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 112 | function neutron_plugin_configure_plugin_agent { | 
| Rob | 2a6215d | 2014-10-20 13:28:47 +0100 | [diff] [blame] | 113 |     : | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 114 | } | 
 | 115 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 116 | function neutron_plugin_configure_service { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 117 |     local subplugin | 
 | 118 |     local cisco_cfg_file | 
 | 119 |  | 
| Pritesh Kothari | 107278f | 2014-09-15 09:29:55 -0700 | [diff] [blame] | 120 |     cisco_cfg_file=/$Q_PLUGIN_CONF_FILE | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 121 |  | 
 | 122 |     # Setup the [CISCO_PLUGINS] section | 
 | 123 |     if [[ ${#Q_CISCO_PLUGIN_SUBPLUGINS[@]} > 2 ]]; then | 
 | 124 |         die $LINENO "At most two subplugins are supported." | 
 | 125 |     fi | 
 | 126 |  | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 127 |     # Setup the subplugins | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 128 |     inicomment $cisco_cfg_file CISCO_PLUGINS vswitch_plugin | 
 | 129 |     inicomment $cisco_cfg_file CISCO_TEST host | 
 | 130 |     for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do | 
 | 131 |         case $subplugin in | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 132 |             n1kv) iniset $cisco_cfg_file CISCO_PLUGINS vswitch_plugin neutron.plugins.cisco.n1kv.n1kv_neutron_plugin.N1kvNeutronPluginV2;; | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 133 |             *) die $LINENO "Unsupported cisco subplugin: $subplugin";; | 
 | 134 |         esac | 
 | 135 |     done | 
 | 136 |  | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 137 |     if _has_n1kv_subplugin; then | 
 | 138 |         _configure_n1kv_subplugin $cisco_cfg_file | 
 | 139 |     fi | 
 | 140 | } | 
 | 141 |  | 
| Rob | d06a6d9 | 2014-12-04 20:32:22 +0000 | [diff] [blame] | 142 | function neutron_plugin_create_initial_network_profile { | 
 | 143 |     neutron cisco-network-profile-create default_network_profile vlan --segment_range 1-3000 --physical_network "$1" | 
 | 144 | } | 
 | 145 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 146 | function neutron_plugin_setup_interface_driver { | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 147 |     local conf_file=$1 | 
| Martin Hickey | dca49de | 2015-10-20 12:13:19 +0100 | [diff] [blame] | 148 |     iniset $conf_file DEFAULT interface_driver openvswitch | 
| Baodong (Robert) Li | 901419d | 2013-06-10 08:39:26 -0700 | [diff] [blame] | 149 | } | 
 | 150 |  | 
 | 151 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 152 | $_XTRACE_NEUTRON_CISCO |