From 30f75383e3cc217393c57dbc1f08ed33c667df61 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Sat, 1 Apr 2017 09:10:43 +0100
Subject: [PATCH] Add configuration of Neutron including genericswitch mech
 driver

---
 ansible/group_vars/all/kolla                  |  1 +
 ansible/group_vars/all/neutron                | 48 +++++++++++++
 ansible/kolla-openstack.yml                   | 72 ++++++++++++++-----
 .../roles/kolla-openstack/defaults/main.yml   | 65 +++++++++++++++--
 .../roles/kolla-openstack/tasks/config.yml    |  3 +
 .../kolla-openstack/templates/ml2_conf.ini.j2 | 44 ++++++++++++
 .../kolla-openstack/templates/neutron.conf.j2 |  9 +++
 etc/kayobe/neutron.yml                        | 41 +++++++++++
 8 files changed, 262 insertions(+), 21 deletions(-)
 create mode 100644 ansible/group_vars/all/neutron
 create mode 100644 ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2
 create mode 100644 ansible/roles/kolla-openstack/templates/neutron.conf.j2
 create mode 100644 etc/kayobe/neutron.yml

diff --git a/ansible/group_vars/all/kolla b/ansible/group_vars/all/kolla
index e17ecf49..76dfe68a 100644
--- a/ansible/group_vars/all/kolla
+++ b/ansible/group_vars/all/kolla
@@ -151,6 +151,7 @@ kolla_openstack_logging_debug: "False"
 
 kolla_enable_glance: "yes"
 kolla_enable_ironic: "yes"
+kolla_enable_neutron: "yes"
 kolla_enable_swift: "yes"
 
 ###############################################################################
diff --git a/ansible/group_vars/all/neutron b/ansible/group_vars/all/neutron
new file mode 100644
index 00000000..a1820be7
--- /dev/null
+++ b/ansible/group_vars/all/neutron
@@ -0,0 +1,48 @@
+---
+###############################################################################
+# Neutron configuration.
+
+# List of Neutron ML2 mechanism drivers to use.
+kolla_neutron_ml2_mechanism_drivers:
+  - openvswitch
+  - genericswitch
+
+# List of Neutron ML2 type drivers to use.
+kolla_neutron_ml2_type_drivers:
+  - flat
+  - vlan
+  - vxlan
+
+# List of Neutron ML2 tenant network types to use.
+kolla_neutron_ml2_tenant_network_types:
+  - flat
+  - vlan
+  - vxlan
+
+# List of Neutron ML2 network VLAN ranges to use. Each item should be a dict
+# containing the following items:
+# physical_network: The physical network
+# range: Range of allowed VLANs on this physical network (min:max, (optional)
+kolla_neutron_ml2_network_vlan_ranges: []
+
+# List of switches to configure for use by genericswitch ML2 mechanism driver.
+# Each item should be a dict containing the following items:
+# name: Hostname of the switch
+# ip: IP address on which to reach the switch
+# username: SSH username
+# password: SSH password (optional)
+# key_file: SSH key file (optional)
+# secret: SSH secret (optional)
+kolla_neutron_ml2_generic_switches: []
+
+# List of Ansible hosts representing switches to configure for use by
+# genericswitch ML2 mechanism driver. These switches will be appended to
+# kolla_neutron_ml2_generic_switches and their configuration will be determined
+# by the following host variables:
+# name: inventory_hostname
+# ip: ansible_host
+# username: ansible_user
+# password: ansible_ssh_pass
+# key_file: not currently supported
+# secret: not currently supported
+kolla_neutron_ml2_generic_switch_hosts: []
diff --git a/ansible/kolla-openstack.yml b/ansible/kolla-openstack.yml
index bafbc606..d7eac4ae 100644
--- a/ansible/kolla-openstack.yml
+++ b/ansible/kolla-openstack.yml
@@ -1,26 +1,64 @@
 ---
 - name: Ensure Kolla OpenStack components are configured
   hosts: config-mgmt
+  vars:
+    switch_type_to_device_type:
+      dellos9: netmiko_dell_force10
   pre_tasks:
-    - name: Check whether Kolla extra configuration files exist
-      stat:
-        path: "{{ kayobe_config_path }}/kolla/config/{{ item.file }}"
-      register: stat_result
-      with_items:
-        - { name: glance, file: glance.conf }
-        - { name: inspector, file: ironic-inspector.conf }
-        - { name: ironic, file: ironic.conf }
+    - block:
+        - name: Check whether Kolla extra configuration files exist
+          stat:
+            path: "{{ kayobe_config_path }}/kolla/config/{{ item.file }}"
+          register: stat_result
+          with_items:
+            - { name: glance, file: glance.conf }
+            - { name: inspector, file: ironic-inspector.conf }
+            - { name: ironic, file: ironic.conf }
+            - { name: neutron, file: neutron.conf }
+            - { name: neutron_ml2, file: neutron/ml2_conf.ini }
 
-    - name: Initialise a fact containing extra configuration
-      set_fact:
-        kolla_extra_config: {}
+        - name: Initialise a fact containing extra configuration
+          set_fact:
+            kolla_extra_config: {}
 
-    - name: Update a fact containing extra configuration
-      set_fact:
-        kolla_extra_config: "{{ kolla_extra_config | combine({item.item.name: lookup('template', '{{ item.stat.path }}')}) }}"
-      with_items: "{{ stat_result.results }}"
-      when: "{{ item.stat.exists }}"
+        - name: Update a fact containing extra configuration
+          set_fact:
+            kolla_extra_config: "{{ kolla_extra_config | combine({item.item.name: lookup('template', '{{ item.stat.path }}')}) }}"
+          with_items: "{{ stat_result.results }}"
+          when: "{{ item.stat.exists }}"
 
+        - name: Validate switch configuration for Neutron ML2 genericswitch driver
+          fail:
+            msg: >
+              Switch configuration for {{ item }} is invalid. The following
+              variables must be set for the host: switch_type, ansible_host,
+              ansible_user, ansible_ssh_pass. Further, switch_type must be one of
+              {{ switch_type_to_device_type.keys() | join(', ') }}.
+          with_items: "{{ kolla_neutron_ml2_generic_switch_hosts }}"
+          when: >
+            {{
+                item not in hostvars or
+                'switch_type' not in hostvars[item] or
+                hostvars[item].switch_type not in switch_type_to_device_type or
+                'ansible_host' not in hostvars[item] or
+                'ansible_user' not in hostvars[item] or
+                'ansible_ssh_pass' not in hostvars[item]
+            }}
+          tags:
+            - config-validation
+
+        - 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}] }}
+          with_items: "{{ kolla_neutron_ml2_generic_switch_hosts }}"
+      tags:
+        - config
   roles:
     - role: kolla-openstack
       # Ironic inspector configuration.
@@ -39,3 +77,5 @@
       kolla_extra_glance: "{{ kolla_extra_config.glance | default }}"
       kolla_extra_inspector: "{{ kolla_extra_config.inspector | default }}"
       kolla_extra_ironic: "{{ kolla_extra_config.ironic | default }}"
+      kolla_extra_neutron: "{{ kolla_extra_config.neutron | default }}"
+      kolla_extra_neutron_ml2: "{{ kolla_extra_config.neutron_ml2 | default }}"
diff --git a/ansible/roles/kolla-openstack/defaults/main.yml b/ansible/roles/kolla-openstack/defaults/main.yml
index bf10e3e9..66454f94 100644
--- a/ansible/roles/kolla-openstack/defaults/main.yml
+++ b/ansible/roles/kolla-openstack/defaults/main.yml
@@ -2,9 +2,22 @@
 # Directory where Kolla custom configuration files will be installed.
 kolla_node_custom_config_path:
 
+###############################################################################
+# Glance configuration.
+
+# Whether to enable Glance.
+kolla_enable_glance:
+
+# Free form extra configuration to append to glance-api.conf and
+# glance-registry.conf.
+kolla_extra_glance:
+
 ###############################################################################
 # Ironic configuration.
 
+# Whether to enable Ironic.
+kolla_enable_ironic:
+
 # List of enabled Ironic drivers.
 kolla_ironic_drivers:
   - agent_ssh
@@ -144,8 +157,50 @@ kolla_inspector_dhcp_pool_start:
 kolla_inspector_dhcp_pool_end:
 
 ###############################################################################
-# Glance configuration.
-
-# Free form extra configuration to append to glance-api.conf and
-# glance-registry.conf.
-kolla_extra_glance:
+# Neutron configuration.
+
+# Whether to enable Neutron.
+kolla_enable_neutron:
+
+# List of Neutron ML2 mechanism drivers to use.
+kolla_neutron_ml2_mechanism_drivers: []
+
+# List of Neutron ML2 type drivers to use.
+kolla_neutron_ml2_type_drivers: []
+
+# List of Neutron ML2 tenant network types to use.
+kolla_neutron_ml2_tenant_network_types: []
+
+# List of Neutron ML2 network VLAN ranges to use. Each item should be a dict
+# containing the following items:
+# physical_network: The physical network
+# range: Range of allowed VLANs on this physical network (min:max, (optional)
+kolla_neutron_ml2_network_vlan_ranges: []
+
+# List of switches to configure for use by genericswitch ML2 mechanism driver.
+# Each item should be a dict containing the following items;
+# name: Hostname of the switch
+# ip: IP address on which to reach the switch
+# username: SSH username
+# password: SSH password (optional)
+# key_file: SSH key file (optional)
+# secret: SSH secret (optional)
+kolla_neutron_ml2_generic_switches: []
+
+# List of Ansible hosts representing switches to configure for use by
+# genericswitch ML2 mechanism driver. These switches will be appended to
+# kolla_neutron_ml2_generic_switches and their configuration will be determined
+# by the following host variables:
+# name: inventory_hostname
+# ip: ansible_host
+# username: ansible_user
+# password: ansible_ssh_password
+# key_file: not currently supported
+# secret: not currently supported
+kolla_neutron_ml2_generic_switch_hosts: []
+
+# Free form extra configuration to append to neutron.conf.
+kolla_extra_neutron:
+
+# Free form extra configuration to append to ml2_conf.ini.
+kolla_extra_neutron_ml2:
diff --git a/ansible/roles/kolla-openstack/tasks/config.yml b/ansible/roles/kolla-openstack/tasks/config.yml
index 0bc69f50..679ffd0b 100644
--- a/ansible/roles/kolla-openstack/tasks/config.yml
+++ b/ansible/roles/kolla-openstack/tasks/config.yml
@@ -6,6 +6,7 @@
     mode: 0750
   with_items:
     - { name: ironic, enabled: "{{ kolla_enable_ironic }}" }
+    - { name: neutron, enabled: "{{ kolla_enable_neutron }}" }
     - { name: swift, enabled: "{{ kolla_enable_swift }}" }
   when: "{{ item.enabled | bool }}"
 
@@ -19,6 +20,8 @@
     - { src: ironic.conf.j2, dest: ironic.conf, enabled: "{{ kolla_enable_ironic }}" }
     - { src: ironic-dnsmasq.conf.j2, dest: ironic/ironic-dnsmasq.conf, enabled: "{{ kolla_enable_ironic }}" }
     - { src: ironic-inspector.conf.j2, dest: ironic-inspector.conf, enabled: "{{ kolla_enable_ironic }}" }
+    - { src: ml2_conf.ini.j2, dest: neutron/ml2_conf.ini, enabled: "{{ kolla_enable_neutron }}" }
+    - { src: neutron.conf.j2, dest: neutron.conf, enabled: "{{ kolla_enable_neutron }}" }
     - { src: pxelinux.default.j2, dest: ironic/pxelinux.default, enabled: "{{ kolla_enable_ironic }}" }
   when: "{{ item.enabled | bool }}"
 
diff --git a/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2 b/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2
new file mode 100644
index 00000000..89abe603
--- /dev/null
+++ b/ansible/roles/kolla-openstack/templates/ml2_conf.ini.j2
@@ -0,0 +1,44 @@
+# {{ ansible_managed }}
+
+[ml2]
+{% if kolla_neutron_ml2_mechanism_drivers %}
+mechanism_drivers = {{ kolla_neutron_ml2_mechanism_drivers | join(',') }}
+{% endif %}
+
+{% if kolla_neutron_ml2_type_drivers %}
+type_drivers = {{ kolla_neutron_ml2_type_drivers | join(',') }}
+{% endif %}
+
+{% if kolla_neutron_ml2_tenant_network_types %}
+tenant_network_types = {{ kolla_neutron_ml2_tenant_network_types | join(',') }}
+{% endif %}
+
+[ml2_type_vlan]
+{% if kolla_neutron_ml2_network_vlan_ranges %}
+network_vlan_ranges = {% for vnr in kolla_neutron_ml2_network_vlan_ranges %}{{ vnr.physical_network }}{% if vnr.range is defined %}:{{ vnr.range }}{% endif %}{% if not loop.last %},{% endif %}{% endfor %}
+{% endif %}
+
+{% for switch in kolla_neutron_ml2_generic_switches %}
+[genericswitch:{{ switch.name }}]
+device_type = {{ switch.device_type }}
+ip = {{ switch.ip }}
+username = {{ switch.username }}
+{% if switch.password is defined %}
+password = {{ switch.password }}
+{% endif %}
+{% if switch.key_file is defined %}
+key_file = {{ switch.key_file }}
+{% endif %}
+{% if switch.secret is defined %}
+secret = {{ switch.secret }}
+{% endif %}
+
+{% endfor %}
+
+{% if kolla_extra_neutron_ml2 %}
+#######################
+# Extra configuration
+#######################
+
+{{ kolla_extra_neutron_ml2 }}
+{% endif %}
diff --git a/ansible/roles/kolla-openstack/templates/neutron.conf.j2 b/ansible/roles/kolla-openstack/templates/neutron.conf.j2
new file mode 100644
index 00000000..1cf183d8
--- /dev/null
+++ b/ansible/roles/kolla-openstack/templates/neutron.conf.j2
@@ -0,0 +1,9 @@
+# {{ ansible_managed }}
+
+{% if kolla_extra_neutron %}
+#######################
+# Extra configuration
+#######################
+
+{{ kolla_extra_neutron }}
+{% endif %}
diff --git a/etc/kayobe/neutron.yml b/etc/kayobe/neutron.yml
new file mode 100644
index 00000000..d93d9f82
--- /dev/null
+++ b/etc/kayobe/neutron.yml
@@ -0,0 +1,41 @@
+---
+###############################################################################
+# Neutron configuration.
+
+# List of Neutron ML2 mechanism drivers to use.
+#kolla_neutron_ml2_mechanism_drivers:
+
+# List of Neutron ML2 type drivers to use.
+#kolla_neutron_ml2_type_drivers:
+
+# List of Neutron ML2 tenant network types to use.
+#kolla_neutron_ml2_tenant_network_types:
+
+# List of Neutron ML2 network VLAN ranges to use. Each item should be a dict
+# containing the following items:
+# physical_network: The physical network
+# min: Minimum of allowed VLAN range (optional)
+# max: Maximum of allowed VLAN range (optional)
+#kolla_neutron_ml2_network_vlan_ranges:
+
+# List of switches to configure for use by genericswitch ML2 mechanism driver.
+# Each item should be a dict containing the following items:
+# name: Hostname of the switch
+# ip: IP address on which to reach the switch
+# username: SSH username
+# password: SSH password (optional)
+# key_file: SSH key file (optional)
+# secret: SSH secret (optional)
+#kolla_neutron_ml2_generic_switches:
+
+# List of Ansible hosts representing switches to configure for use by
+# genericswitch ML2 mechanism driver. These switches will be appended to
+# kolla_neutron_ml2_generic_switches and their configuration will be determined
+# by the following host variables:
+# name: inventory_hostname
+# ip: ansible_host
+# username: ansible_user
+# password: ansible_ssh_pass
+# key_file: not currently supported
+# secret: not currently supported
+#kolla_neutron_ml2_generic_switch_hosts:
-- 
GitLab