From 08d34db3d1987fd12ea32ec09ee11a407298a2c2 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Wed, 15 Mar 2017 09:44:26 +0000
Subject: [PATCH] Add initial work on network configuration for management
 network

Currently supports configuration of network interfaces
---
 ansible/group_vars/switches/interfaces        | 12 ++++++++++
 ansible/mgmt-switch-config.yml                | 23 +++++++++++++++++++
 .../inventory/group_vars/switches/interfaces  | 20 ++++++++++++++++
 etc/kayobe/inventory/groups                   | 17 ++++++++++++++
 etc/kayobe/inventory/hosts.example            |  9 ++++++++
 5 files changed, 81 insertions(+)
 create mode 100644 ansible/group_vars/switches/interfaces
 create mode 100644 ansible/mgmt-switch-config.yml
 create mode 100644 etc/kayobe/inventory/group_vars/switches/interfaces

diff --git a/ansible/group_vars/switches/interfaces b/ansible/group_vars/switches/interfaces
new file mode 100644
index 000000000..c24b68661
--- /dev/null
+++ b/ansible/group_vars/switches/interfaces
@@ -0,0 +1,12 @@
+---
+# Switch configuration.
+
+###############################################################################
+# Interface configuration.
+
+# Interface configuration. Dict mapping switch interface names to configuration
+# dicts. Each dict contains a description item and a 'config' item which should
+# contain a list of additional per-interface configuration.
+# Generally this should be configured on a per-switch basis via a host_vars
+# file.
+switch_interface_config: {}
diff --git a/ansible/mgmt-switch-config.yml b/ansible/mgmt-switch-config.yml
new file mode 100644
index 000000000..a2fbe186e
--- /dev/null
+++ b/ansible/mgmt-switch-config.yml
@@ -0,0 +1,23 @@
+---
+- name: Ensure the power and management network switches are configured
+  hosts: mgmt-switches
+  gather_facts: no
+  vars:
+    provider:
+      host: "{{ ansible_host }}"
+      username: "{{ ansible_user }}"
+      password: "{{ ansible_ssh_pass }}"
+      transport: cli
+      authorize: yes
+      auth_pass: "{{ switch_auth_pass }}"
+  tasks:
+    - name: Ensure switch interfaces are configured
+      local_action:
+        module: dellos6_config
+        provider: "{{ provider }}"
+        lines: >
+          {{ ['description ' ~ item.value.description] +
+             item.value.config | default([]) }}
+        parents:
+          - "interface {{ item.key }}"
+      with_dict: "{{ switch_interface_config }}"
diff --git a/etc/kayobe/inventory/group_vars/switches/interfaces b/etc/kayobe/inventory/group_vars/switches/interfaces
new file mode 100644
index 000000000..e7e8ce3ce
--- /dev/null
+++ b/etc/kayobe/inventory/group_vars/switches/interfaces
@@ -0,0 +1,20 @@
+---
+# Switch configuration.
+
+###############################################################################
+# Interface configuration.
+
+# Interface configuration. Dict mapping switch interface names to configuration
+# dicts. Each dict contains a description item and the name of a network which
+# is used to lookup a variable containing interface config for ports on that
+# network (switch_interface_config_<network>). Each dict can also have a 
+# 'config' item which should contain a list of additional per-interface
+# configuration.
+# Generally this should be configured on a per-switch basis via a host_vars
+# file.
+switch_interface_config: {}
+
+# Example of an interface configuration variable for a network, referenced by
+# the 'network' item of an interface in 'switch_interface_config'.
+#switch_interface_config_example_net:
+#  - switchport access vlan 42
diff --git a/etc/kayobe/inventory/groups b/etc/kayobe/inventory/groups
index 15f9ea96d..0212af5d4 100644
--- a/etc/kayobe/inventory/groups
+++ b/etc/kayobe/inventory/groups
@@ -11,3 +11,20 @@
 # Hosts in this group will have Docker installed.
 seed
 controllers
+
+###############################################################################
+# Networking groups.
+
+[mgmt-switches]
+# Empty group to provide declaration of mgmt-switches group.
+
+[ctl-switches]
+# Empty group to provide declaration of ctl-switches group.
+
+[hs-switches]
+# Empty group to provide declaration of hs-switches group.
+
+[switches:children]
+mgmt-switches
+ctl-switches
+hs-switches
diff --git a/etc/kayobe/inventory/hosts.example b/etc/kayobe/inventory/hosts.example
index 16b7dbf44..b3dc7a39d 100644
--- a/etc/kayobe/inventory/hosts.example
+++ b/etc/kayobe/inventory/hosts.example
@@ -17,3 +17,12 @@ localhost ansible_connection=local
 [controllers]
 # Add controller nodes here if required. These hosts will provide the
 # OpenStack overcloud.
+
+[mgmt-switches]
+# Add management network switches here if required.
+
+[ctl-switches]
+# Add control and provisioning switches here if required.
+
+[hs-switches]
+# Add high speed switches here if required.