| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,327 @@ |
| 0 |
+# Quantum Cisco plugin |
|
| 1 |
+# --------------------------- |
|
| 2 |
+ |
|
| 3 |
+# Save trace setting |
|
| 4 |
+MY_XTRACE=$(set +o | grep xtrace) |
|
| 5 |
+set +o xtrace |
|
| 6 |
+ |
|
| 7 |
+# Scecify the VSM parameters |
|
| 8 |
+Q_CISCO_PLUGIN_VSM_IP=${Q_CISCO_PLUGIN_VSM_IP:-}
|
|
| 9 |
+# Specify the VSM username |
|
| 10 |
+Q_CISCO_PLUGIN_VSM_USERNAME=${Q_CISCO_PLUGIN_VSM_USERNAME:-admin}
|
|
| 11 |
+# Specify the VSM passward for above username |
|
| 12 |
+Q_CISCO_PLUGIN_VSM_PASSWORD=${Q_CISCO_PLUGIN_VSM_PASSWORD:-}
|
|
| 13 |
+# Specify the uVEM integration bridge name |
|
| 14 |
+Q_CISCO_PLUGIN_INTEGRATION_BRIDGE=${Q_CISCO_PLUGIN_INTEGRATION_BRIDGE:-br-int}
|
|
| 15 |
+# Specify if tunneling is enabled |
|
| 16 |
+Q_CISCO_PLUGIN_ENABLE_TUNNELING=${Q_CISCO_PLUGIN_ENABLE_TUNNELING:-True}
|
|
| 17 |
+# Specify the VXLAN range |
|
| 18 |
+Q_CISCO_PLUGIN_VXLAN_ID_RANGES=${Q_CISCO_PLUGIN_VXLAN_ID_RANGES:-5000:10000}
|
|
| 19 |
+# Specify the VLAN range |
|
| 20 |
+Q_CISCO_PLUGIN_VLAN_RANGES=${Q_CISCO_PLUGIN_VLAN_RANGES:-vlan:1:4094}
|
|
| 21 |
+ |
|
| 22 |
+# Specify ncclient package information |
|
| 23 |
+NCCLIENT_DIR=$DEST/ncclient |
|
| 24 |
+NCCLIENT_VERSION=${NCCLIENT_VERSION:-0.3.1}
|
|
| 25 |
+NCCLIENT_REPO=${NCCLIENT_REPO:-${GIT_BASE}/CiscoSystems/ncclient.git}
|
|
| 26 |
+NCCLIENT_BRANCH=${NCCLIENT_BRANCH:-master}
|
|
| 27 |
+ |
|
| 28 |
+# This routine put a prefix on an existing function name |
|
| 29 |
+function _prefix_function() {
|
|
| 30 |
+ declare -F $1 > /dev/null || die "$1 doesn't exist" |
|
| 31 |
+ eval "$(echo "${2}_${1}()"; declare -f ${1} | tail -n +2)"
|
|
| 32 |
+} |
|
| 33 |
+ |
|
| 34 |
+function _has_ovs_subplugin() {
|
|
| 35 |
+ local subplugin |
|
| 36 |
+ for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
|
|
| 37 |
+ if [[ "$subplugin" == "openvswitch" ]]; then |
|
| 38 |
+ return 0 |
|
| 39 |
+ fi |
|
| 40 |
+ done |
|
| 41 |
+ return 1 |
|
| 42 |
+} |
|
| 43 |
+ |
|
| 44 |
+function _has_nexus_subplugin() {
|
|
| 45 |
+ local subplugin |
|
| 46 |
+ for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
|
|
| 47 |
+ if [[ "$subplugin" == "nexus" ]]; then |
|
| 48 |
+ return 0 |
|
| 49 |
+ fi |
|
| 50 |
+ done |
|
| 51 |
+ return 1 |
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+function _has_n1kv_subplugin() {
|
|
| 55 |
+ local subplugin |
|
| 56 |
+ for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
|
|
| 57 |
+ if [[ "$subplugin" == "n1kv" ]]; then |
|
| 58 |
+ return 0 |
|
| 59 |
+ fi |
|
| 60 |
+ done |
|
| 61 |
+ return 1 |
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+# This routine populates the cisco config file with the information for |
|
| 65 |
+# a particular nexus switch |
|
| 66 |
+function _config_switch() {
|
|
| 67 |
+ local cisco_cfg_file=$1 |
|
| 68 |
+ local switch_ip=$2 |
|
| 69 |
+ local username=$3 |
|
| 70 |
+ local password=$4 |
|
| 71 |
+ local ssh_port=$5 |
|
| 72 |
+ shift 5 |
|
| 73 |
+ |
|
| 74 |
+ local section="NEXUS_SWITCH:$switch_ip" |
|
| 75 |
+ iniset $cisco_cfg_file $section username $username |
|
| 76 |
+ iniset $cisco_cfg_file $section password $password |
|
| 77 |
+ iniset $cisco_cfg_file $section ssh_port $ssh_port |
|
| 78 |
+ |
|
| 79 |
+ while [[ ${#@} != 0 ]]; do
|
|
| 80 |
+ iniset $cisco_cfg_file $section $1 $2 |
|
| 81 |
+ shift 2 |
|
| 82 |
+ done |
|
| 83 |
+} |
|
| 84 |
+ |
|
| 85 |
+# Prefix openvswitch plugin routines with "ovs" in order to differentiate from |
|
| 86 |
+# cisco plugin routines. This means, ovs plugin routines will coexist with cisco |
|
| 87 |
+# plugin routines in this script. |
|
| 88 |
+source $TOP_DIR/lib/quantum_plugins/openvswitch |
|
| 89 |
+_prefix_function quantum_plugin_create_nova_conf ovs |
|
| 90 |
+_prefix_function quantum_plugin_install_agent_packages ovs |
|
| 91 |
+_prefix_function quantum_plugin_configure_common ovs |
|
| 92 |
+_prefix_function quantum_plugin_configure_debug_command ovs |
|
| 93 |
+_prefix_function quantum_plugin_configure_dhcp_agent ovs |
|
| 94 |
+_prefix_function quantum_plugin_configure_l3_agent ovs |
|
| 95 |
+_prefix_function quantum_plugin_configure_plugin_agent ovs |
|
| 96 |
+_prefix_function quantum_plugin_configure_service ovs |
|
| 97 |
+_prefix_function quantum_plugin_setup_interface_driver ovs |
|
| 98 |
+_prefix_function has_quantum_plugin_security_group ovs |
|
| 99 |
+ |
|
| 100 |
+# Check the version of the installed ncclient package |
|
| 101 |
+function check_ncclient_version() {
|
|
| 102 |
+python << EOF |
|
| 103 |
+version = '$NCCLIENT_VERSION' |
|
| 104 |
+import sys |
|
| 105 |
+try: |
|
| 106 |
+ import pkg_resources |
|
| 107 |
+ import ncclient |
|
| 108 |
+ module_version = pkg_resources.get_distribution('ncclient').version
|
|
| 109 |
+ if version != module_version: |
|
| 110 |
+ sys.exit(1) |
|
| 111 |
+except: |
|
| 112 |
+ sys.exit(1) |
|
| 113 |
+EOF |
|
| 114 |
+} |
|
| 115 |
+ |
|
| 116 |
+# Install the ncclient package |
|
| 117 |
+function install_ncclient() {
|
|
| 118 |
+ git_clone $NCCLIENT_REPO $NCCLIENT_DIR $NCCLIENT_BRANCH |
|
| 119 |
+ (cd $NCCLIENT_DIR; sudo python setup.py install) |
|
| 120 |
+} |
|
| 121 |
+ |
|
| 122 |
+# Check if the required version of ncclient has been installed |
|
| 123 |
+function is_ncclient_installed() {
|
|
| 124 |
+ # Check if the Cisco ncclient repository exists |
|
| 125 |
+ if [[ -d $NCCLIENT_DIR ]]; then |
|
| 126 |
+ remotes=$(cd $NCCLIENT_DIR; git remote -v | grep fetch | awk '{ print $2}')
|
|
| 127 |
+ for remote in $remotes; do |
|
| 128 |
+ if [[ $remote == $NCCLIENT_REPO ]]; then |
|
| 129 |
+ break; |
|
| 130 |
+ fi |
|
| 131 |
+ done |
|
| 132 |
+ if [[ $remote != $NCCLIENT_REPO ]]; then |
|
| 133 |
+ return 1 |
|
| 134 |
+ fi |
|
| 135 |
+ else |
|
| 136 |
+ return 1 |
|
| 137 |
+ fi |
|
| 138 |
+ |
|
| 139 |
+ # Check if the ncclient is installed with the right version |
|
| 140 |
+ if ! check_ncclient_version; then |
|
| 141 |
+ return 1 |
|
| 142 |
+ fi |
|
| 143 |
+ return 0 |
|
| 144 |
+} |
|
| 145 |
+ |
|
| 146 |
+function has_quantum_plugin_security_group() {
|
|
| 147 |
+ if _has_ovs_subplugin; then |
|
| 148 |
+ ovs_has_quantum_plugin_security_group |
|
| 149 |
+ else |
|
| 150 |
+ return 1 |
|
| 151 |
+ fi |
|
| 152 |
+} |
|
| 153 |
+ |
|
| 154 |
+function is_quantum_ovs_base_plugin() {
|
|
| 155 |
+ # Cisco uses OVS if openvswitch subplugin is deployed |
|
| 156 |
+ _has_ovs_subplugin |
|
| 157 |
+ return |
|
| 158 |
+} |
|
| 159 |
+ |
|
| 160 |
+# populate required nova configuration parameters |
|
| 161 |
+function quantum_plugin_create_nova_conf() {
|
|
| 162 |
+ if _has_ovs_subplugin; then |
|
| 163 |
+ ovs_quantum_plugin_create_nova_conf |
|
| 164 |
+ else |
|
| 165 |
+ _quantum_ovs_base_configure_nova_vif_driver |
|
| 166 |
+ fi |
|
| 167 |
+} |
|
| 168 |
+ |
|
| 169 |
+function quantum_plugin_install_agent_packages() {
|
|
| 170 |
+ # Cisco plugin uses openvswitch to operate in one of its configurations |
|
| 171 |
+ ovs_quantum_plugin_install_agent_packages |
|
| 172 |
+} |
|
| 173 |
+ |
|
| 174 |
+# Configure common parameters |
|
| 175 |
+function quantum_plugin_configure_common() {
|
|
| 176 |
+ # setup default subplugins |
|
| 177 |
+ if [ ! -v Q_CISCO_PLUGIN_SUBPLUGINS ]; then |
|
| 178 |
+ declare -ga Q_CISCO_PLUGIN_SUBPLUGINS |
|
| 179 |
+ Q_CISCO_PLUGIN_SUBPLUGINS=(openvswitch nexus) |
|
| 180 |
+ fi |
|
| 181 |
+ if _has_ovs_subplugin; then |
|
| 182 |
+ ovs_quantum_plugin_configure_common |
|
| 183 |
+ Q_PLUGIN_EXTRA_CONF_PATH=etc/quantum/plugins/cisco |
|
| 184 |
+ Q_PLUGIN_EXTRA_CONF_FILES=(cisco_plugins.ini) |
|
| 185 |
+ else |
|
| 186 |
+ Q_PLUGIN_CONF_PATH=etc/quantum/plugins/cisco |
|
| 187 |
+ Q_PLUGIN_CONF_FILENAME=cisco_plugins.ini |
|
| 188 |
+ fi |
|
| 189 |
+ Q_PLUGIN_CLASS="quantum.plugins.cisco.network_plugin.PluginV2" |
|
| 190 |
+ Q_DB_NAME=cisco_quantum |
|
| 191 |
+} |
|
| 192 |
+ |
|
| 193 |
+function quantum_plugin_configure_debug_command() {
|
|
| 194 |
+ if _has_ovs_subplugin; then |
|
| 195 |
+ ovs_quantum_plugin_configure_debug_command |
|
| 196 |
+ fi |
|
| 197 |
+} |
|
| 198 |
+ |
|
| 199 |
+function quantum_plugin_configure_dhcp_agent() {
|
|
| 200 |
+ iniset $Q_DHCP_CONF_FILE DEFAULT dhcp_agent_manager quantum.agent.dhcp_agent.DhcpAgentWithStateReport |
|
| 201 |
+} |
|
| 202 |
+ |
|
| 203 |
+function quantum_plugin_configure_l3_agent() {
|
|
| 204 |
+ if _has_ovs_subplugin; then |
|
| 205 |
+ ovs_quantum_plugin_configure_l3_agent |
|
| 206 |
+ fi |
|
| 207 |
+} |
|
| 208 |
+ |
|
| 209 |
+function _configure_nexus_subplugin() {
|
|
| 210 |
+ local cisco_cfg_file=$1 |
|
| 211 |
+ |
|
| 212 |
+ # Install a known compatible ncclient from the Cisco repository if necessary |
|
| 213 |
+ if ! is_ncclient_installed; then |
|
| 214 |
+ # Preserve the two global variables |
|
| 215 |
+ local offline=$OFFLINE |
|
| 216 |
+ local reclone=$RECLONE |
|
| 217 |
+ # Change their values to allow installation |
|
| 218 |
+ OFFLINE=False |
|
| 219 |
+ RECLONE=yes |
|
| 220 |
+ install_ncclient |
|
| 221 |
+ # Restore their values |
|
| 222 |
+ OFFLINE=$offline |
|
| 223 |
+ RECLONE=$reclone |
|
| 224 |
+ fi |
|
| 225 |
+ |
|
| 226 |
+ # Setup default nexus switch information |
|
| 227 |
+ if [ ! -v Q_CISCO_PLUGIN_SWITCH_INFO ]; then |
|
| 228 |
+ declare -A Q_CISCO_PLUGIN_SWITCH_INFO |
|
| 229 |
+ HOST_NAME=$(hostname) |
|
| 230 |
+ Q_CISCO_PLUGIN_SWITCH_INFO=([1.1.1.1]=stack:stack:22:${HOST_NAME}:1/10)
|
|
| 231 |
+ else |
|
| 232 |
+ iniset $cisco_cfg_file CISCO nexus_driver quantum.plugins.cisco.nexus.cisco_nexus_network_driver_v2.CiscoNEXUSDriver |
|
| 233 |
+ fi |
|
| 234 |
+ |
|
| 235 |
+ # Setup the switch configurations |
|
| 236 |
+ local nswitch |
|
| 237 |
+ local sw_info |
|
| 238 |
+ local segment |
|
| 239 |
+ local sw_info_array |
|
| 240 |
+ declare -i count=0 |
|
| 241 |
+ for nswitch in ${!Q_CISCO_PLUGIN_SWITCH_INFO[@]}; do
|
|
| 242 |
+ sw_info=${Q_CISCO_PLUGIN_SWITCH_INFO[$nswitch]}
|
|
| 243 |
+ sw_info_array=${sw_info//:/ }
|
|
| 244 |
+ sw_info_array=( $sw_info_array ) |
|
| 245 |
+ count=${#sw_info_array[@]}
|
|
| 246 |
+ if [[ $count < 5 || $(( ($count-3) % 2 )) != 0 ]]; then |
|
| 247 |
+ die $LINENO "Incorrect switch configuration: ${Q_CISCO_PLUGIN_SWITCH_INFO[$nswitch]}"
|
|
| 248 |
+ fi |
|
| 249 |
+ _config_switch $cisco_cfg_file $nswitch ${sw_info_array[@]}
|
|
| 250 |
+ done |
|
| 251 |
+} |
|
| 252 |
+ |
|
| 253 |
+# Configure n1kv plugin |
|
| 254 |
+function _configure_n1kv_subplugin() {
|
|
| 255 |
+ local cisco_cfg_file=$1 |
|
| 256 |
+ |
|
| 257 |
+ # populate the cisco plugin cfg file with the VSM information |
|
| 258 |
+ echo "Configuring n1kv in $cisco_cfg_file-- $Q_CISCO_PLUGIN_VSM_IP $Q_CISCO_PLUGIN_VSM_USERNAME $Q_CISCO_PLUGIN_VSM_PASSWORD" |
|
| 259 |
+ iniset $cisco_cfg_file N1KV:$Q_CISCO_PLUGIN_VSM_IP username $Q_CISCO_PLUGIN_VSM_USERNAME |
|
| 260 |
+ iniset $cisco_cfg_file N1KV:$Q_CISCO_PLUGIN_VSM_IP password $Q_CISCO_PLUGIN_VSM_PASSWORD |
|
| 261 |
+ |
|
| 262 |
+ iniset $cisco_cfg_file CISCO_N1K integration_bridge $Q_CISCO_PLUGIN_INTEGRATION_BRIDGE |
|
| 263 |
+ iniset $cisco_cfg_file CISCO_N1K enable_tunneling $Q_CISCO_PLUGIN_ENABLE_TUNNELING |
|
| 264 |
+ iniset $cisco_cfg_file CISCO_N1K vxlan_id_ranges $Q_CISCO_PLUGIN_VXLAN_ID_RANGES |
|
| 265 |
+ iniset $cisco_cfg_file CISCO_N1K network_vlan_ranges $Q_CISCO_PLUGIN_VLAN_RANGES |
|
| 266 |
+ |
|
| 267 |
+ # Setup the integration bridge by calling the ovs_base |
|
| 268 |
+ OVS_BRIDGE=$Q_CISCO_PLUGIN_INTEGRATION_BRIDGE |
|
| 269 |
+ _quantum_ovs_base_setup_bridge $OVS_BRIDGE |
|
| 270 |
+} |
|
| 271 |
+ |
|
| 272 |
+function quantum_plugin_configure_plugin_agent() {
|
|
| 273 |
+ if _has_ovs_subplugin; then |
|
| 274 |
+ ovs_quantum_plugin_configure_plugin_agent |
|
| 275 |
+ fi |
|
| 276 |
+} |
|
| 277 |
+ |
|
| 278 |
+function quantum_plugin_configure_service() {
|
|
| 279 |
+ local subplugin |
|
| 280 |
+ local cisco_cfg_file |
|
| 281 |
+ |
|
| 282 |
+ if _has_ovs_subplugin; then |
|
| 283 |
+ ovs_quantum_plugin_configure_service |
|
| 284 |
+ cisco_cfg_file=/${Q_PLUGIN_EXTRA_CONF_FILES[0]}
|
|
| 285 |
+ else |
|
| 286 |
+ cisco_cfg_file=/$Q_PLUGIN_CONF_FILE |
|
| 287 |
+ fi |
|
| 288 |
+ |
|
| 289 |
+ # Setup the [CISCO_PLUGINS] section |
|
| 290 |
+ if [[ ${#Q_CISCO_PLUGIN_SUBPLUGINS[@]} > 2 ]]; then
|
|
| 291 |
+ die $LINENO "At most two subplugins are supported." |
|
| 292 |
+ fi |
|
| 293 |
+ |
|
| 294 |
+ if _has_ovs_subplugin && _has_n1kv_subplugin; then |
|
| 295 |
+ die $LINENO "OVS subplugin and n1kv subplugin cannot coexist" |
|
| 296 |
+ fi |
|
| 297 |
+ |
|
| 298 |
+ # Setup the subplugins |
|
| 299 |
+ inicomment $cisco_cfg_file CISCO_PLUGINS nexus_plugin |
|
| 300 |
+ inicomment $cisco_cfg_file CISCO_PLUGINS vswitch_plugin |
|
| 301 |
+ inicomment $cisco_cfg_file CISCO_TEST host |
|
| 302 |
+ for subplugin in ${Q_CISCO_PLUGIN_SUBPLUGINS[@]}; do
|
|
| 303 |
+ case $subplugin in |
|
| 304 |
+ nexus) iniset $cisco_cfg_file CISCO_PLUGINS nexus_plugin quantum.plugins.cisco.nexus.cisco_nexus_plugin_v2.NexusPlugin;; |
|
| 305 |
+ openvswitch) iniset $cisco_cfg_file CISCO_PLUGINS vswitch_plugin quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2;; |
|
| 306 |
+ n1kv) iniset $cisco_cfg_file CISCO_PLUGINS vswitch_plugin quantum.plugins.cisco.n1kv.n1kv_quantum_plugin.N1kvQuantumPluginV2;; |
|
| 307 |
+ *) die $LINENO "Unsupported cisco subplugin: $subplugin";; |
|
| 308 |
+ esac |
|
| 309 |
+ done |
|
| 310 |
+ |
|
| 311 |
+ if _has_nexus_subplugin; then |
|
| 312 |
+ _configure_nexus_subplugin $cisco_cfg_file |
|
| 313 |
+ fi |
|
| 314 |
+ |
|
| 315 |
+ if _has_n1kv_subplugin; then |
|
| 316 |
+ _configure_n1kv_subplugin $cisco_cfg_file |
|
| 317 |
+ fi |
|
| 318 |
+} |
|
| 319 |
+ |
|
| 320 |
+function quantum_plugin_setup_interface_driver() {
|
|
| 321 |
+ local conf_file=$1 |
|
| 322 |
+ iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver |
|
| 323 |
+} |
|
| 324 |
+ |
|
| 325 |
+# Restore xtrace |
|
| 326 |
+$MY_XTRACE |