blob: da90ee32ad4f43611d5c6f16f095826101826243 [file] [log] [blame]
Mark McClainb05c8762013-07-06 23:29:39 -04001# Neutron Cisco plugin
Baodong (Robert) Li901419d2013-06-10 08:39:26 -07002# ---------------------------
3
4# Save trace setting
Dean Troyere3a91602014-03-28 12:40:56 -05005CISCO_XTRACE=$(set +o | grep xtrace)
Baodong (Robert) Li901419d2013-06-10 08:39:26 -07006set +o xtrace
7
8# Scecify the VSM parameters
9Q_CISCO_PLUGIN_VSM_IP=${Q_CISCO_PLUGIN_VSM_IP:-}
10# Specify the VSM username
11Q_CISCO_PLUGIN_VSM_USERNAME=${Q_CISCO_PLUGIN_VSM_USERNAME:-admin}
12# Specify the VSM passward for above username
13Q_CISCO_PLUGIN_VSM_PASSWORD=${Q_CISCO_PLUGIN_VSM_PASSWORD:-}
14# Specify the uVEM integration bridge name
15Q_CISCO_PLUGIN_INTEGRATION_BRIDGE=${Q_CISCO_PLUGIN_INTEGRATION_BRIDGE:-br-int}
16# Specify if tunneling is enabled
17Q_CISCO_PLUGIN_ENABLE_TUNNELING=${Q_CISCO_PLUGIN_ENABLE_TUNNELING:-True}
18# Specify the VXLAN range
19Q_CISCO_PLUGIN_VXLAN_ID_RANGES=${Q_CISCO_PLUGIN_VXLAN_ID_RANGES:-5000:10000}
20# Specify the VLAN range
21Q_CISCO_PLUGIN_VLAN_RANGES=${Q_CISCO_PLUGIN_VLAN_RANGES:-vlan:1:4094}
22
23# Specify ncclient package information
24NCCLIENT_DIR=$DEST/ncclient
25NCCLIENT_VERSION=${NCCLIENT_VERSION:-0.3.1}
Shweta Pde3b8202014-03-03 13:38:37 -050026NCCLIENT_REPO=${NCCLIENT_REPO:-git://github.com/CiscoSystems/ncclient.git}
Baodong (Robert) Li901419d2013-06-10 08:39:26 -070027NCCLIENT_BRANCH=${NCCLIENT_BRANCH:-master}
28
29# This routine put a prefix on an existing function name
Ian Wienandaee18c72014-02-21 15:35:08 +110030function _prefix_function {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -070031 declare -F $1 > /dev/null || die "$1 doesn't exist"
32 eval "$(echo "${2}_${1}()"; declare -f ${1} | tail -n +2)"
33}
34
Ian Wienandaee18c72014-02-21 15:35:08 +110035function _has_ovs_subplugin {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -070036 local subplugin
37 for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
38 if [[ "$subplugin" == "openvswitch" ]]; then
39 return 0
40 fi
41 done
42 return 1
43}
44
Ian Wienandaee18c72014-02-21 15:35:08 +110045function _has_nexus_subplugin {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -070046 local subplugin
47 for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
48 if [[ "$subplugin" == "nexus" ]]; then
49 return 0
50 fi
51 done
52 return 1
53}
54
Ian Wienandaee18c72014-02-21 15:35:08 +110055function _has_n1kv_subplugin {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -070056 local subplugin
57 for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
58 if [[ "$subplugin" == "n1kv" ]]; then
59 return 0
60 fi
61 done
62 return 1
63}
64
65# This routine populates the cisco config file with the information for
66# a particular nexus switch
Ian Wienandaee18c72014-02-21 15:35:08 +110067function _config_switch {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -070068 local cisco_cfg_file=$1
69 local switch_ip=$2
70 local username=$3
71 local password=$4
72 local ssh_port=$5
73 shift 5
74
75 local section="NEXUS_SWITCH:$switch_ip"
76 iniset $cisco_cfg_file $section username $username
77 iniset $cisco_cfg_file $section password $password
78 iniset $cisco_cfg_file $section ssh_port $ssh_port
79
80 while [[ ${#@} != 0 ]]; do
81 iniset $cisco_cfg_file $section $1 $2
82 shift 2
83 done
84}
85
86# Prefix openvswitch plugin routines with "ovs" in order to differentiate from
87# cisco plugin routines. This means, ovs plugin routines will coexist with cisco
88# plugin routines in this script.
Mark McClainb05c8762013-07-06 23:29:39 -040089source $TOP_DIR/lib/neutron_plugins/openvswitch
90_prefix_function neutron_plugin_create_nova_conf ovs
91_prefix_function neutron_plugin_install_agent_packages ovs
92_prefix_function neutron_plugin_configure_common ovs
93_prefix_function neutron_plugin_configure_debug_command ovs
94_prefix_function neutron_plugin_configure_dhcp_agent ovs
95_prefix_function neutron_plugin_configure_l3_agent ovs
96_prefix_function neutron_plugin_configure_plugin_agent ovs
97_prefix_function neutron_plugin_configure_service ovs
98_prefix_function neutron_plugin_setup_interface_driver ovs
99_prefix_function has_neutron_plugin_security_group ovs
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700100
101# Check the version of the installed ncclient package
Ian Wienandaee18c72014-02-21 15:35:08 +1100102function check_ncclient_version {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700103python << EOF
104version = '$NCCLIENT_VERSION'
105import sys
106try:
107 import pkg_resources
108 import ncclient
109 module_version = pkg_resources.get_distribution('ncclient').version
110 if version != module_version:
111 sys.exit(1)
112except:
113 sys.exit(1)
114EOF
115}
116
117# Install the ncclient package
Ian Wienandaee18c72014-02-21 15:35:08 +1100118function install_ncclient {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700119 git_clone $NCCLIENT_REPO $NCCLIENT_DIR $NCCLIENT_BRANCH
120 (cd $NCCLIENT_DIR; sudo python setup.py install)
121}
122
123# Check if the required version of ncclient has been installed
Ian Wienandaee18c72014-02-21 15:35:08 +1100124function is_ncclient_installed {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700125 # Check if the Cisco ncclient repository exists
126 if [[ -d $NCCLIENT_DIR ]]; then
127 remotes=$(cd $NCCLIENT_DIR; git remote -v | grep fetch | awk '{ print $2}')
128 for remote in $remotes; do
129 if [[ $remote == $NCCLIENT_REPO ]]; then
130 break;
131 fi
132 done
133 if [[ $remote != $NCCLIENT_REPO ]]; then
134 return 1
135 fi
136 else
137 return 1
138 fi
139
140 # Check if the ncclient is installed with the right version
141 if ! check_ncclient_version; then
142 return 1
143 fi
144 return 0
145}
146
Ian Wienandaee18c72014-02-21 15:35:08 +1100147function has_neutron_plugin_security_group {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700148 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400149 ovs_has_neutron_plugin_security_group
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700150 else
151 return 1
152 fi
153}
154
Ian Wienandaee18c72014-02-21 15:35:08 +1100155function is_neutron_ovs_base_plugin {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700156 # Cisco uses OVS if openvswitch subplugin is deployed
157 _has_ovs_subplugin
158 return
159}
160
161# populate required nova configuration parameters
Ian Wienandaee18c72014-02-21 15:35:08 +1100162function neutron_plugin_create_nova_conf {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700163 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400164 ovs_neutron_plugin_create_nova_conf
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700165 else
Mark McClainb05c8762013-07-06 23:29:39 -0400166 _neutron_ovs_base_configure_nova_vif_driver
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700167 fi
168}
169
Ian Wienandaee18c72014-02-21 15:35:08 +1100170function neutron_plugin_install_agent_packages {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700171 # Cisco plugin uses openvswitch to operate in one of its configurations
Mark McClainb05c8762013-07-06 23:29:39 -0400172 ovs_neutron_plugin_install_agent_packages
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700173}
174
175# Configure common parameters
Ian Wienandaee18c72014-02-21 15:35:08 +1100176function neutron_plugin_configure_common {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700177 # setup default subplugins
178 if [ ! -v Q_CISCO_PLUGIN_SUBPLUGINS ]; then
179 declare -ga Q_CISCO_PLUGIN_SUBPLUGINS
180 Q_CISCO_PLUGIN_SUBPLUGINS=(openvswitch nexus)
181 fi
182 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400183 ovs_neutron_plugin_configure_common
184 Q_PLUGIN_EXTRA_CONF_PATH=etc/neutron/plugins/cisco
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700185 Q_PLUGIN_EXTRA_CONF_FILES=(cisco_plugins.ini)
Dane LeBlancc68a8f62014-03-20 19:10:08 -0400186 # Copy extra config files to /etc so that they can be modified
187 # later according to Cisco-specific localrc settings.
188 mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
189 local f
190 local extra_conf_file
191 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
192 extra_conf_file=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
193 cp $NEUTRON_DIR/$extra_conf_file /$extra_conf_file
194 done
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700195 else
Mark McClainb05c8762013-07-06 23:29:39 -0400196 Q_PLUGIN_CONF_PATH=etc/neutron/plugins/cisco
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700197 Q_PLUGIN_CONF_FILENAME=cisco_plugins.ini
198 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400199 Q_PLUGIN_CLASS="neutron.plugins.cisco.network_plugin.PluginV2"
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700200}
201
Ian Wienandaee18c72014-02-21 15:35:08 +1100202function neutron_plugin_configure_debug_command {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700203 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400204 ovs_neutron_plugin_configure_debug_command
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700205 fi
206}
207
Ian Wienandaee18c72014-02-21 15:35:08 +1100208function neutron_plugin_configure_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400209 iniset $Q_DHCP_CONF_FILE DEFAULT dhcp_agent_manager neutron.agent.dhcp_agent.DhcpAgentWithStateReport
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700210}
211
Ian Wienandaee18c72014-02-21 15:35:08 +1100212function neutron_plugin_configure_l3_agent {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700213 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400214 ovs_neutron_plugin_configure_l3_agent
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700215 fi
216}
217
Ian Wienandaee18c72014-02-21 15:35:08 +1100218function _configure_nexus_subplugin {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700219 local cisco_cfg_file=$1
220
221 # Install a known compatible ncclient from the Cisco repository if necessary
222 if ! is_ncclient_installed; then
223 # Preserve the two global variables
224 local offline=$OFFLINE
225 local reclone=$RECLONE
226 # Change their values to allow installation
227 OFFLINE=False
228 RECLONE=yes
229 install_ncclient
230 # Restore their values
231 OFFLINE=$offline
232 RECLONE=$reclone
233 fi
234
235 # Setup default nexus switch information
236 if [ ! -v Q_CISCO_PLUGIN_SWITCH_INFO ]; then
237 declare -A Q_CISCO_PLUGIN_SWITCH_INFO
238 HOST_NAME=$(hostname)
239 Q_CISCO_PLUGIN_SWITCH_INFO=([1.1.1.1]=stack:stack:22:${HOST_NAME}:1/10)
240 else
Mark McClainb05c8762013-07-06 23:29:39 -0400241 iniset $cisco_cfg_file CISCO nexus_driver neutron.plugins.cisco.nexus.cisco_nexus_network_driver_v2.CiscoNEXUSDriver
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700242 fi
243
244 # Setup the switch configurations
245 local nswitch
246 local sw_info
247 local segment
248 local sw_info_array
249 declare -i count=0
250 for nswitch in ${!Q_CISCO_PLUGIN_SWITCH_INFO[@]}; do
251 sw_info=${Q_CISCO_PLUGIN_SWITCH_INFO[$nswitch]}
252 sw_info_array=${sw_info//:/ }
253 sw_info_array=( $sw_info_array )
254 count=${#sw_info_array[@]}
255 if [[ $count < 5 || $(( ($count-3) % 2 )) != 0 ]]; then
256 die $LINENO "Incorrect switch configuration: ${Q_CISCO_PLUGIN_SWITCH_INFO[$nswitch]}"
257 fi
258 _config_switch $cisco_cfg_file $nswitch ${sw_info_array[@]}
259 done
260}
261
262# Configure n1kv plugin
Ian Wienandaee18c72014-02-21 15:35:08 +1100263function _configure_n1kv_subplugin {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700264 local cisco_cfg_file=$1
265
266 # populate the cisco plugin cfg file with the VSM information
267 echo "Configuring n1kv in $cisco_cfg_file-- $Q_CISCO_PLUGIN_VSM_IP $Q_CISCO_PLUGIN_VSM_USERNAME $Q_CISCO_PLUGIN_VSM_PASSWORD"
268 iniset $cisco_cfg_file N1KV:$Q_CISCO_PLUGIN_VSM_IP username $Q_CISCO_PLUGIN_VSM_USERNAME
269 iniset $cisco_cfg_file N1KV:$Q_CISCO_PLUGIN_VSM_IP password $Q_CISCO_PLUGIN_VSM_PASSWORD
270
271 iniset $cisco_cfg_file CISCO_N1K integration_bridge $Q_CISCO_PLUGIN_INTEGRATION_BRIDGE
272 iniset $cisco_cfg_file CISCO_N1K enable_tunneling $Q_CISCO_PLUGIN_ENABLE_TUNNELING
273 iniset $cisco_cfg_file CISCO_N1K vxlan_id_ranges $Q_CISCO_PLUGIN_VXLAN_ID_RANGES
274 iniset $cisco_cfg_file CISCO_N1K network_vlan_ranges $Q_CISCO_PLUGIN_VLAN_RANGES
275
276 # Setup the integration bridge by calling the ovs_base
277 OVS_BRIDGE=$Q_CISCO_PLUGIN_INTEGRATION_BRIDGE
Mark McClainb05c8762013-07-06 23:29:39 -0400278 _neutron_ovs_base_setup_bridge $OVS_BRIDGE
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700279}
280
Ian Wienandaee18c72014-02-21 15:35:08 +1100281function neutron_plugin_configure_plugin_agent {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700282 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400283 ovs_neutron_plugin_configure_plugin_agent
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700284 fi
285}
286
Ian Wienandaee18c72014-02-21 15:35:08 +1100287function neutron_plugin_configure_service {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700288 local subplugin
289 local cisco_cfg_file
290
291 if _has_ovs_subplugin; then
Mark McClainb05c8762013-07-06 23:29:39 -0400292 ovs_neutron_plugin_configure_service
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700293 cisco_cfg_file=/${Q_PLUGIN_EXTRA_CONF_FILES[0]}
294 else
295 cisco_cfg_file=/$Q_PLUGIN_CONF_FILE
296 fi
297
298 # Setup the [CISCO_PLUGINS] section
299 if [[ ${#Q_CISCO_PLUGIN_SUBPLUGINS[@]} > 2 ]]; then
300 die $LINENO "At most two subplugins are supported."
301 fi
302
303 if _has_ovs_subplugin && _has_n1kv_subplugin; then
304 die $LINENO "OVS subplugin and n1kv subplugin cannot coexist"
305 fi
306
307 # Setup the subplugins
308 inicomment $cisco_cfg_file CISCO_PLUGINS nexus_plugin
309 inicomment $cisco_cfg_file CISCO_PLUGINS vswitch_plugin
310 inicomment $cisco_cfg_file CISCO_TEST host
311 for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
312 case $subplugin in
Mark McClainb05c8762013-07-06 23:29:39 -0400313 nexus) iniset $cisco_cfg_file CISCO_PLUGINS nexus_plugin neutron.plugins.cisco.nexus.cisco_nexus_plugin_v2.NexusPlugin;;
314 openvswitch) iniset $cisco_cfg_file CISCO_PLUGINS vswitch_plugin neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2;;
315 n1kv) iniset $cisco_cfg_file CISCO_PLUGINS vswitch_plugin neutron.plugins.cisco.n1kv.n1kv_neutron_plugin.N1kvNeutronPluginV2;;
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700316 *) die $LINENO "Unsupported cisco subplugin: $subplugin";;
317 esac
318 done
319
320 if _has_nexus_subplugin; then
321 _configure_nexus_subplugin $cisco_cfg_file
322 fi
323
324 if _has_n1kv_subplugin; then
325 _configure_n1kv_subplugin $cisco_cfg_file
326 fi
327}
328
Ian Wienandaee18c72014-02-21 15:35:08 +1100329function neutron_plugin_setup_interface_driver {
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700330 local conf_file=$1
Mark McClainb05c8762013-07-06 23:29:39 -0400331 iniset $conf_file DEFAULT interface_driver neutron.agent.linux.interface.OVSInterfaceDriver
Baodong (Robert) Li901419d2013-06-10 08:39:26 -0700332}
333
334# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -0500335$CISCO_XTRACE