diff --git a/ansible/filter_plugins/switches.py b/ansible/filter_plugins/switches.py new file mode 100644 index 000000000..1f64f5cba --- /dev/null +++ b/ansible/filter_plugins/switches.py @@ -0,0 +1,40 @@ +# Copyright (c) 2017 StackHPC Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import six + + +def switch_interface_config_select_description(switch_interface_config, descriptions): + """Select and return all switch interfaces matching requested descriptions. + + :param switch_interface_config: Switch interface configuration dict + :param descriptions: String or list of strings - descriptions to match + """ + if isinstance(descriptions, six.string_types): + descriptions = [descriptions] + + return { + name: config + for name, config in switch_interface_config.items() + if config.get('description') in descriptions + } + + +class FilterModule(object): + """Switch filters.""" + + def filters(self): + return { + 'switch_interface_config_select_description': switch_interface_config_select_description, + } diff --git a/ansible/group_vars/all/neutron b/ansible/group_vars/all/neutron index a1820be77..4bf60fb46 100644 --- a/ansible/group_vars/all/neutron +++ b/ansible/group_vars/all/neutron @@ -46,3 +46,10 @@ kolla_neutron_ml2_generic_switches: [] # key_file: not currently supported # secret: not currently supported kolla_neutron_ml2_generic_switch_hosts: [] + +# List of Ansible hosts whose switch interfaces are to be configured as tagged +# members of all networks managed by the genericswitch ML2 mechanism driver. +# These hosts will be matched against the description fields in the +# switch_interface_config variable for each switch to determine which +# interfaces should be configured. +kolla_neutron_ml2_generic_switch_trunk_port_hosts: "{{ groups['controllers'] }}" diff --git a/ansible/kolla-openstack.yml b/ansible/kolla-openstack.yml index ebb0986b8..a340d3dbe 100644 --- a/ansible/kolla-openstack.yml +++ b/ansible/kolla-openstack.yml @@ -54,12 +54,19 @@ - name: Update a fact containing switches for use by Neutron ML2 genericswitch driver set_fact: kolla_neutron_ml2_generic_switches: > - {{ kolla_neutron_ml2_generic_switches + - [{'name': item, - 'device_type': switch_type_to_device_type[hostvars[item].switch_type], - 'ip': hostvars[item].ansible_host, - 'username': hostvars[item].ansible_user, - 'password': hostvars[item].ansible_ssh_pass}] }} + {{ + kolla_neutron_ml2_generic_switches + + [{ + 'name': item, + 'device_type': switch_type_to_device_type[hostvars[item].switch_type], + 'ip': hostvars[item].ansible_host, + 'username': hostvars[item].ansible_user, + 'password': hostvars[item].ansible_ssh_pass, + 'ngs_trunk_ports': ( + hostvars[item].switch_interface_config | + switch_interface_config_select_description(kolla_neutron_ml2_generic_switch_trunk_port_hosts)).keys() | join(',') + }] + }} with_items: "{{ kolla_neutron_ml2_generic_switch_hosts }}" tags: - config diff --git a/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2 b/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2 index 89abe6032..c4a01b1fc 100644 --- a/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2 +++ b/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2 @@ -32,6 +32,9 @@ key_file = {{ switch.key_file }} {% if switch.secret is defined %} secret = {{ switch.secret }} {% endif %} +{% if switch.ngs_trunk_ports is defined %} +ngs_trunk_ports = {{ switch.ngs_trunk_ports }} +{% endif %} {% endfor %}