From 7817fccc5bc85d9cb888a118490f094d2e1ad237 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20Jens=C3=A5s?= <hjensas@redhat.com>
Date: Tue, 3 Jul 2018 09:32:39 +0200
Subject: [PATCH] Add support for {{role.name}}IPs in Composable Role

Use the {{role.name}}IPs for network port resources in
Composable Role to enable setting predictable ip address
on network ports.

We currently support predictable ip addressing using the
from_pool templates. The from_pool creates a 'fake' neutron
port. Because of this we loose access to properties of
the ports subnet, properties that is useful to simplyfy
advanced configurations such as routed spine-and-leaf.

Creating a neutron port also open the possibility to use ML2
plugins in the future (Neutron Ansible ML2) to do port
binding that configures network devices.

The parameter (interface) to use this is the same as with
from_pool. Example:

parameter_defaults:
  {role.name}IPs:
    {network.name_lower}:
    - 10.0.0.1
    {network.name_lower}:
    - 172.16.1.1

We just don't need to override the resource registry. I.e
the following is not used/required.
resource_registry:
  ``OS::TripleO::{{role.name}}::Ports::{{network.name}}Port``

NOTE: This does not remove the from_pool templates. We may
      want to deprecate them, but in that case we need to
      ensure it is possible to upgrade an environment that
      used them by changeing the resource registry to use
      the default port templates in this change.

Related: blueprint tripleo-routed-networks-templates
Change-Id: I3f9b55ffbf6b6626b4d0dfbec3867811cb74de14
---
 puppet/role.role.j2.yaml                      | 12 ++++++++++
 ...port-predictable-ips-857b8369ca81aa4c.yaml | 23 +++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 releasenotes/notes/neutron-port-predictable-ips-857b8369ca81aa4c.yaml

diff --git a/puppet/role.role.j2.yaml b/puppet/role.role.j2.yaml
index 9f97fe7a93..9694c1d81f 100644
--- a/puppet/role.role.j2.yaml
+++ b/puppet/role.role.j2.yaml
@@ -301,6 +301,13 @@ conditions:
         - {get_param: [{{role.name}}IPs, 'ctlplane', {get_param: NodeIndex}]}
 {%- endif %}
         - ""
+{%- for network in networks %}
+  {{role.name}}_{{network.name}}_fixed_ip_set:
+    not:
+      equals:
+        - {get_param: [{{role.name}}IPs, '{{network.name_lower}}', {get_param: NodeIndex}]}
+        - ''
+{%- endfor %}
 
 resources:
   {{server_resource_name}}:
@@ -397,6 +404,11 @@ resources:
     type: OS::TripleO::{{role.name}}::Ports::{{network.name}}Port
     properties:
       ControlPlaneIP: {get_attr: [{{server_resource_name}}, networks, ctlplane, 0]}
+      FixedIPs:
+        if:
+          - {{role.name}}_{{network.name}}_fixed_ip_set
+          - [{ip_address: {get_param: [{{role.name}}IPs, '{{network.name_lower}}', {get_param: NodeIndex}]}}]
+          - []
       IPPool:
         map_merge:
 {%- if role.deprecated_param_ips is defined %}
diff --git a/releasenotes/notes/neutron-port-predictable-ips-857b8369ca81aa4c.yaml b/releasenotes/notes/neutron-port-predictable-ips-857b8369ca81aa4c.yaml
new file mode 100644
index 0000000000..ac187393de
--- /dev/null
+++ b/releasenotes/notes/neutron-port-predictable-ips-857b8369ca81aa4c.yaml
@@ -0,0 +1,23 @@
+---
+features:
+  - |
+    Support for predictable IP addressing added to the default port templates.
+    In previous releases the use of _from_pool templates was required to have
+    predictable ip addresses assigned to the nodes. Use of the
+    ``port_from_pool`` templates is no longer required. The interface to
+    configure predictable IP addressing without ``port_from_pool`` templates is
+    the same. For example::
+
+      parameter_defaults:
+        ControllerIPs:
+          intapi:
+            - 10.0.0.10
+            - 10.0.0.11
+          external:
+            - 172.16.1.10
+            - 172.16.1.11
+upgrade:
+  - |
+    Support for predictable IP addressing has been added to the default port
+    templates. This however has not been tested for upgrades. If upgrading
+    continues use of the _from_pool templates is required.