From 2b86fd9945cbee93eb5c74772cf6a66b87158db8 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Fri, 19 Jun 2020 10:00:48 +0000
Subject: [PATCH] Add support for custom options in static routes

Currently it is possible to set the CIDR, gateway and route table for
static routes. Other options cannot be set. This change adds support for
setting arbitrary options via an 'options' attribute in the route, which
should be a list of additional options to apply.

Depends on
https://github.com/michaelrigart/ansible-role-interfaces/pull/74.

Story: 2007835
Task: 40122

Change-Id: Ib27deac4ddf4976a571b192ee5d1b8ca57701916
---
 ansible/filter_plugins/networks.py            |  1 +
 doc/source/configuration/network.rst          | 21 +++++++++++++++----
 ...custom-route-options-2ed446961262a34a.yaml |  5 +++++
 requirements.yml                              |  2 +-
 4 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 releasenotes/notes/custom-route-options-2ed446961262a34a.yaml

diff --git a/ansible/filter_plugins/networks.py b/ansible/filter_plugins/networks.py
index 3c3650e07..6812aa181 100644
--- a/ansible/filter_plugins/networks.py
+++ b/ansible/filter_plugins/networks.py
@@ -178,6 +178,7 @@ def _route_obj(route):
     optional = {
         'gateway',
         'table',
+        'options',
     }
     for option in optional:
         if option in route:
diff --git a/doc/source/configuration/network.rst b/doc/source/configuration/network.rst
index 6af03f82e..cbd1a3a8f 100644
--- a/doc/source/configuration/network.rst
+++ b/doc/source/configuration/network.rst
@@ -47,10 +47,11 @@ supported:
     Fully Qualified Domain Name (FQDN) used by API services on this network.
 ``routes``
     List of static IP routes. Each item should be a dict containing the
-    item ``cidr``, and optionally ``gateway`` and ``table``. ``cidr`` is the CIDR
-    representation of the route's destination. ``gateway`` is the IP address of
-    the next hop. ``table`` is the name or ID of a routing table to which the
-    route will be added.
+    item ``cidr``, and optionally ``gateway``, ``table`` and ``options``.
+    ``cidr`` is the CIDR representation of the route's destination. ``gateway``
+    is the IP address of the next hop. ``table`` is the name or ID of a routing
+    table to which the route will be added. ``options`` is a list of option
+    strings to add to the route.
 ``rules``
     List of IP routing rules. Each item should be an ``iproute2`` IP routing
     rule.
@@ -139,6 +140,18 @@ To configure a network called ``example`` with a single IP route to the
 
 These routes will be configured on all hosts to which the network is mapped.
 
+If necessary, custom options may be added to the route:
+
+.. code-block:: yaml
+   :caption: ``networks.yml``
+
+   example_routes:
+     - cidr: 10.1.0.0/24
+       gateway: 10.0.0.1
+       options:
+         - onlink
+         - metric 400
+
 Configuring a VLAN
 ------------------
 
diff --git a/releasenotes/notes/custom-route-options-2ed446961262a34a.yaml b/releasenotes/notes/custom-route-options-2ed446961262a34a.yaml
new file mode 100644
index 000000000..4295650ad
--- /dev/null
+++ b/releasenotes/notes/custom-route-options-2ed446961262a34a.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    Adds support for custom options in static routes. See `story 2007835
+    <https://storyboard.openstack.org/#!/story/2007835>`__ for details.
diff --git a/requirements.yml b/requirements.yml
index 10fe7bc9e..e79a01a4a 100644
--- a/requirements.yml
+++ b/requirements.yml
@@ -5,7 +5,7 @@
   # There are no versioned releases of this role.
   version: 8438592c84585c86e62ae07e526d3da53629b377
 - src: MichaelRigart.interfaces
-  version: v1.5.0
+  version: v1.6.0
 - src: mrlesmithjr.manage-lvm
   version: v0.1.4
 - src: mrlesmithjr.mdadm