From 6dc74ac0e69d4bdd4da826189b6d6c2d2bc8e6a9 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 11 Sep 2015 03:12:55 +0000 Subject: [PATCH] Remove use of template based config from cisco ml2 nexus plugin. Change to modify the cisco ml2 nexus section to remove the use of the erb template for configuring the per-nexus switch ML2 config sections. The change adds 2 new defined types which wrap neutron_plugin_ml2 resource usage. Change-Id: I401371c9e5176de7ce19d4d4e878e9f2e69aab80 Closes-bug: #1495537 --- examples/cisco_ml2.pp | 18 ++- manifests/plugins/ml2/cisco/nexus.pp | 12 +- manifests/plugins/ml2/cisco/nexus_switch.pp | 105 ++++++++++++++++++ .../plugins/ml2/cisco/nexus_switch_server.pp | 33 ++++++ .../neutron_plugins_ml2_cisco_nexus_spec.rb | 7 +- templates/ml2_mech_cisco_nexus_conf.erb | 59 ---------- 6 files changed, 156 insertions(+), 78 deletions(-) create mode 100644 manifests/plugins/ml2/cisco/nexus_switch.pp create mode 100644 manifests/plugins/ml2/cisco/nexus_switch_server.pp delete mode 100644 templates/ml2_mech_cisco_nexus_conf.erb diff --git a/examples/cisco_ml2.pp b/examples/cisco_ml2.pp index 9d2efe623..0a3c5a63c 100644 --- a/examples/cisco_ml2.pp +++ b/examples/cisco_ml2.pp @@ -38,20 +38,28 @@ class {'::neutron::plugins::ml2::cisco::nexus': 'nve_src_intf' => 1, 'physnet' => 'physnet', 'servers' => { - 'control1' => 'ethernet:1/1', - 'control2' => 'ethernet:1/2' + 'control1' => { + 'ports' => 'ethernet:1/1', + }, + 'control2' => { + 'ports' => 'ethernet:1/2', + }, } }, 'n9372-2' => { 'username' => 'admin', 'password' => 'password', 'ssh_port' => 22, - 'ip_address' => '127.0.0.1', + 'ip_address' => '127.0.0.2', 'nve_src_intf' => 1, 'physnet' => 'physnet', 'servers' => { - 'compute1' => 'ethernet:1/1', - 'compute2' => 'ethernet:1/2' + 'compute1' => { + 'ports' => 'ethernet:1/1', + }, + 'compute2' => { + 'ports' => 'ethernet:1/2', + }, } } }, diff --git a/manifests/plugins/ml2/cisco/nexus.pp b/manifests/plugins/ml2/cisco/nexus.pp index c5f9cf38e..bbd42e7c3 100644 --- a/manifests/plugins/ml2/cisco/nexus.pp +++ b/manifests/plugins/ml2/cisco/nexus.pp @@ -16,8 +16,8 @@ # 'nve_src_intf' => 1, # 'physnet' => "physnet1", # 'servers' => { -# 'control01' => "portchannel:20", -# 'control02' => "portchannel:10" +# 'control01' => {"ports" => "portchannel:20"}, +# 'control02' => {"ports" => "portchannel:10"} # }}} # # [*managed_physical_network*] @@ -124,13 +124,7 @@ class neutron::plugins::ml2::cisco::nexus ( 'ml2_cisco/host_key_checks' : value => $host_key_checks; } - file { 'nexus_config': - path => $::neutron::params::cisco_ml2_mech_cisco_nexus_config_file, - owner => 'root', - group => 'neutron', - mode => '0644', - content => template('neutron/ml2_mech_cisco_nexus_conf.erb'), - } ~> Service['neutron-server'] + create_resources(neutron::plugins::ml2::cisco::nexus_switch, $nexus_config) create_resources(neutron::plugins::ml2::cisco::nexus_creds, $nexus_config) diff --git a/manifests/plugins/ml2/cisco/nexus_switch.pp b/manifests/plugins/ml2/cisco/nexus_switch.pp new file mode 100644 index 000000000..e18fe5a3c --- /dev/null +++ b/manifests/plugins/ml2/cisco/nexus_switch.pp @@ -0,0 +1,105 @@ +# == Define: neutron::plugins::ml2::cisco::nexus_switch +# +# Defined type to configure the Cisco Nexus Switch parameters +# for use by the ML2 Mech Driver for Cisco Nexus Switches. +# +# More info available here: +# https://wiki.openstack.org/wiki/Neutron/ML2/MechCiscoNexus +# +# +# neutron::plugins::ml2::cisco::nexus_switch used by +# neutron::plugins::ml2::cisco::nexus +# +# === Parameters: +# [*username*] +# (required) The username for logging into the switch to manage it. +# +# [*password*] +# (required) The password for logging into the switch to manage it. +# +# [*ip_address*] +# (required) The IP address of the switch. +# +# [*ssh_port*] +# (required) The SSH port to use when connecting to the switch. +# +# [*servers*] +# (required) A hash of server names (key) mapped to the switch's +# interfaces (value). For each host connected to a port on the +# switch, specify the hostname and the Nexus physical port/s +# (interface/s) it is connected to. The values in the hash can +# be a comma separated list of interfaces mapped to the server. +# +# Hash Format: +# +# { +# => {"ports" => ",, ..."}, +# => {"ports" => ",, ..."}, +# } +# +# Interface ID format options: +# ":" +# Valid intf_type's are 'ethernet' and 'port-channel'. +# The default setting for is 'ethernet' and need not be +# added to this setting. +# +# Example: +# { +# 'control1' => {"ports" => 'ethernet:1/1'}, +# 'control2' => {"ports" => 'ethernet:1/2'}, +# 'compute1' => {"ports" => '1/3,1/4'} +# } +# +# [*switchname*] +# (required) An identifier for the switch--ie. hostname or IP +# address of the switch. +# +# [*nve_src_intf*] +# (optional) Only valid if VXLAN overlay is configured and +# vxlan_global_config is set to True. +# +# The NVE source interface is a loopback interface that is configured on +# the switch with valid /32 IP address. This /32 IP address must be known +# by the transient devices in the transport network and the remote VTEPs. +# This is accomplished by advertising it through a dynamic routing protocol +# in the transport network. (NB: If no nve_src_intf is defined then a +# default setting of 0 (creates "loopback0") will be used.) +# +# Defaults to undef. +# +# [*physnet*] +# (optional) Only valid if VXLAN overlay is configured. +# The physical network name defined in the network_vlan_ranges variable +# (defined under the ml2_type_vlan section) that this switch is controlling. +# The configured 'physnet' is the physical network domain that is connected +# to this switch. The vlan ranges defined in network_vlan_ranges for a +# a physical network are allocated dynamically and are unique per physical +# network. These dynamic vlans may be reused across physical networks. +# +# Defaults to undef. +# +define neutron::plugins::ml2::cisco::nexus_switch( + $username, + $password, + $ip_address, + $ssh_port, + $servers, + $switchname = $title, + $nve_src_intf = undef, + $physnet = undef +) { + $section = "ML2_MECH_CISCO_NEXUS:${ip_address}" + neutron_plugin_ml2 { + "${section}/username": value => $username; + "${section}/password": value => $password; + "${section}/ssh_port": value => $ssh_port; + "${section}/nve_src_intf": value => $nve_src_intf; + "${section}/physnet": value => $physnet; + } + + $server_defaults = { + 'switch_ip_address' => $ip_address + } + create_resources(neutron::plugins::ml2::cisco::nexus_switch_server, + $servers, $server_defaults) +} diff --git a/manifests/plugins/ml2/cisco/nexus_switch_server.pp b/manifests/plugins/ml2/cisco/nexus_switch_server.pp new file mode 100644 index 000000000..5c63dff1c --- /dev/null +++ b/manifests/plugins/ml2/cisco/nexus_switch_server.pp @@ -0,0 +1,33 @@ +# == Define: neutron::plugins::ml2::cisco::nexus_switch +# +# Defined type to configure the Cisco Nexus Switch parameters +# for servers connected to the switch for use by the ML2 Mech +# Driver for Cisco Nexus Switches. +# +# More info available here: +# https://wiki.openstack.org/wiki/Neutron/ML2/MechCiscoNexus +# +# +# neutron::plugins::ml2::cisco::nexus_switch_server used by +# neutron::plugins::ml2::cisco::nexus_switch +# +# === Parameters: +# [*switch_ip_address*] +# (required) The IP address for the switch. +# +# [*ports*] +# (required) The switch ports connected to this server. +# +# [*hostname*] +# (required) The hostname of a host connected to the switch. +# +define neutron::plugins::ml2::cisco::nexus_switch_server( + $switch_ip_address, + $ports, + $hostname = $title, +) { + $section = "ML2_MECH_CISCO_NEXUS:${switch_ip_address}" + neutron_plugin_ml2 { + "${section}/${hostname}": value => $ports; + } +} diff --git a/spec/classes/neutron_plugins_ml2_cisco_nexus_spec.rb b/spec/classes/neutron_plugins_ml2_cisco_nexus_spec.rb index 41fc98ca7..7bbd167e5 100644 --- a/spec/classes/neutron_plugins_ml2_cisco_nexus_spec.rb +++ b/spec/classes/neutron_plugins_ml2_cisco_nexus_spec.rb @@ -24,8 +24,8 @@ describe 'neutron::plugins::ml2::cisco::nexus' do "nve_src_intf" => 1, "physnet" => "physnet1", "servers" => { - "control02" => "portchannel:20", - "control01" => "portchannel:10" + "control02" => {"ports" => "portchannel:20"}, + "control01" => {"ports" => "portchannel:10"} } } }, @@ -76,9 +76,6 @@ describe 'neutron::plugins::ml2::cisco::nexus' do is_expected.to contain_neutron_plugin_ml2('ml2_cisco/host_key_checks').with_value(params[:host_key_checks]) end - it { is_expected.to contain_file('nexus_config').with({ - :path => platform_params[:cisco_ml2_config_file]}) } - it { # Stored as an array of arrays with the first element consisting of the name and # the second element consisting of the config hash diff --git a/templates/ml2_mech_cisco_nexus_conf.erb b/templates/ml2_mech_cisco_nexus_conf.erb deleted file mode 100644 index b9209274b..000000000 --- a/templates/ml2_mech_cisco_nexus_conf.erb +++ /dev/null @@ -1,59 +0,0 @@ -# Cisco Nexus Switch configurations. -# Each switch to be managed by Openstack Neutron must be configured here. -# -# Cisco Nexus Switch Format. -# [ml2_mech_cisco_nexus:] -# = (1) -# ssh_port= (2) -# username= (3) -# password= (4) -# nve_src_intf= (5) -# physnet= (6) -# -# (1) For each host connected to a port on the switch, specify the hostname -# and the Nexus physical port (interface) it is connected to. -# Valid intf_type's are 'ethernet' and 'port-channel'. -# The default setting for is 'ethernet' and need not be -# added to this setting. -# (2) The TCP port for connecting via SSH to manage the switch. This is -# port number 22 unless the switch has been configured otherwise. -# (3) The username for logging into the switch to manage it. -# (4) The password for logging into the switch to manage it. -# (5) Only valid if VXLAN overlay is configured and vxlan_global_config is -# set to True. -# The NVE source interface is a loopback interface that is configured on -# the switch with valid /32 IP address. This /32 IP address must be known -# by the transient devices in the transport network and the remote VTEPs. -# This is accomplished by advertising it through a dynamic routing protocol -# in the transport network. (NB: If no nve_src_intf is defined then a -# default setting of 0 (creates "loopback0") will be used.) -# (6) Only valid if VXLAN overlay is configured. -# The physical network name defined in the network_vlan_ranges variable -# (defined under the ml2_type_vlan section) that this switch is controlling. -# The configured 'physnet' is the physical network domain that is connected -# to this switch. The vlan ranges defined in network_vlan_ranges for a -# a physical network are allocated dynamically and are unique per physical -# network. These dynamic vlans may be reused across physical networks. -# -# Example: -# [ml2_mech_cisco_nexus:1.1.1.1] -# compute1=1/1 -# compute2=ethernet:1/2 -# compute3=port-channel:1 -# ssh_port=22 -# username=admin -# password=mySecretPassword -# nve_src_intf=1 -# physnet=physnet1 - -<% @nexus_config.each do |switch_hostname, switch_data| %> -[ML2_MECH_CISCO_NEXUS:<%= switch_data['ip_address'] %>] -<%- switch_data['servers'].each do |host_name, port| -%> -<%=host_name-%>=<%= port %> -<%- end -%> -ssh_port=<%= switch_data['ssh_port'] %> -username=<%= switch_data['username'] %> -password=<%= switch_data['password'] %> -nve_src_intf=<%= switch_data['nve_src_intf'] %> -physnet=<%= switch_data['physnet'] %> -<% end %>