From bb0d66b8008dfc9c6b9febb9a98e28a94d8262b7 Mon Sep 17 00:00:00 2001
From: Dan Prince <dprince@redhat.com>
Date: Thu, 10 Sep 2015 09:30:01 -0400
Subject: [PATCH] Add net_vip_map_external to be used for an external balancer

Changes VipMap into a new NetVipMap resource which defaults to
being the same as the 'old' VipMap. An environment file can be
used to map NetVipMap instead to the net_vip_map_external.yaml
which allows for passing in explicit Virtual IP addresses.

It also ensures that references to the Virtual IPs are gathered
from the VipMap resource and allows for an empty ControlPlaneIP
parameter in the neutron port templates where it can be.

Co-Authored-By: Giulio Fidente <gfidente@redhat.com>

Change-Id: Ifad32e18f12b9997e3f89e4afe3ebc4c30e14a86
---
 environments/external-loadbalancer-vip.yaml | 13 ++++++
 network/ports/ctlplane_vip.yaml             |  1 +
 network/ports/external.yaml                 |  1 +
 network/ports/internal_api.yaml             |  1 +
 network/ports/net_vip_map_external.yaml     | 50 +++++++++++++++++++++
 network/ports/storage.yaml                  |  2 +-
 network/ports/storage_mgmt.yaml             |  1 +
 network/ports/tenant.yaml                   |  1 +
 network/ports/vip.yaml                      |  1 +
 overcloud-resource-registry-puppet.yaml     |  1 +
 overcloud-resource-registry.yaml            |  1 +
 overcloud-without-mergepy.yaml              | 22 ++++-----
 12 files changed, 83 insertions(+), 12 deletions(-)
 create mode 100644 environments/external-loadbalancer-vip.yaml
 create mode 100644 network/ports/net_vip_map_external.yaml

diff --git a/environments/external-loadbalancer-vip.yaml b/environments/external-loadbalancer-vip.yaml
new file mode 100644
index 0000000000..0866806cd9
--- /dev/null
+++ b/environments/external-loadbalancer-vip.yaml
@@ -0,0 +1,13 @@
+resource_registry:
+  OS::TripleO::Network::Ports::NetVipMap: ../network/ports/net_vip_map_external.yaml
+
+parameter_defaults:
+  # When using an external loadbalancer set the following in parameter_defaults
+  # to control your VIPs (currently one per network)
+  # NOTE: we will eventually move to one VIP per service
+  #
+  # ControlNetworkVip:
+  # ExternalNetworkVip:
+  # InternalApiNetworkVip:
+  # StorageNetworkVip:
+  # StorageMgmtNetworkVip:
diff --git a/network/ports/ctlplane_vip.yaml b/network/ports/ctlplane_vip.yaml
index 0d2945bc81..3e949f413e 100644
--- a/network/ports/ctlplane_vip.yaml
+++ b/network/ports/ctlplane_vip.yaml
@@ -15,6 +15,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
   ControlPlaneNetwork:
     description: The name of the undercloud Neutron control plane
diff --git a/network/ports/external.yaml b/network/ports/external.yaml
index 63e3eeb3d0..1e2fff683f 100644
--- a/network/ports/external.yaml
+++ b/network/ports/external.yaml
@@ -15,6 +15,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
   ControlPlaneNetwork: # Here for compatibility with ctlplane_vip.yaml
     description: The name of the undercloud Neutron control plane
diff --git a/network/ports/internal_api.yaml b/network/ports/internal_api.yaml
index da1b1856bf..b671aa5f8f 100644
--- a/network/ports/internal_api.yaml
+++ b/network/ports/internal_api.yaml
@@ -14,6 +14,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
 
 resources:
diff --git a/network/ports/net_vip_map_external.yaml b/network/ports/net_vip_map_external.yaml
new file mode 100644
index 0000000000..36426b3239
--- /dev/null
+++ b/network/ports/net_vip_map_external.yaml
@@ -0,0 +1,50 @@
+heat_template_version: 2015-04-30
+
+parameters:
+  # Set these via parameter defaults to configure external VIPs
+  ControlNetworkVip:
+    default: ''
+    type: string
+  ExternalNetworkVip:
+    default: ''
+    type: string
+  InternalApiNetworkVip:
+    default: ''
+    type: string
+  StorageNetworkVip:
+    default: ''
+    type: string
+  StorageMgmtNetworkVip:
+    default: ''
+    type: string
+  # The following are unused in this template
+  ControlPlaneIp:
+    default: ''
+    type: string
+  ExternalIp:
+    default: ''
+    type: string
+  InternalApiIp:
+    default: ''
+    type: string
+  StorageIp:
+    default: ''
+    type: string
+  StorageMgmtIp:
+    default: ''
+    type: string
+  TenantIp:
+    default: ''
+    type: string
+
+outputs:
+  net_ip_map:
+    description: >
+      A Hash containing a mapping of network names to assigned IPs
+      for a specific machine.
+    value:
+      ctlplane: {get_param: ControlNetworkVip}
+      external: {get_param: ExternalNetworkVip}
+      internal_api: {get_param: InternalApiNetworkVip}
+      storage: {get_param: StorageNetworkVip}
+      storage_mgmt: {get_param: StorageMgmtNetworkVip}
diff --git a/network/ports/storage.yaml b/network/ports/storage.yaml
index ecb20b8fc1..e1ef8e031c 100644
--- a/network/ports/storage.yaml
+++ b/network/ports/storage.yaml
@@ -14,6 +14,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
 
 resources:
@@ -39,4 +40,3 @@ outputs:
               - '/'
               - {get_attr: [StoragePort, subnets, 0, cidr, -2]}
               - {get_attr: [StoragePort, subnets, 0, cidr, -1]}
-
diff --git a/network/ports/storage_mgmt.yaml b/network/ports/storage_mgmt.yaml
index 2ab39f213e..e5b5b8844f 100644
--- a/network/ports/storage_mgmt.yaml
+++ b/network/ports/storage_mgmt.yaml
@@ -14,6 +14,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
 
 resources:
diff --git a/network/ports/tenant.yaml b/network/ports/tenant.yaml
index aae12d460b..9a351a24be 100644
--- a/network/ports/tenant.yaml
+++ b/network/ports/tenant.yaml
@@ -14,6 +14,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
 
 resources:
diff --git a/network/ports/vip.yaml b/network/ports/vip.yaml
index 299579dce5..56efc1781e 100644
--- a/network/ports/vip.yaml
+++ b/network/ports/vip.yaml
@@ -15,6 +15,7 @@ parameters:
     type: string
   ControlPlaneIP: # Here for compatability with noop.yaml
     description: IP address on the control plane
+    default: ''
     type: string
   ControlPlaneNetwork:
     description: The name of the undercloud Neutron control plane
diff --git a/overcloud-resource-registry-puppet.yaml b/overcloud-resource-registry-puppet.yaml
index 4cfed6b428..7437fdfc0a 100644
--- a/overcloud-resource-registry-puppet.yaml
+++ b/overcloud-resource-registry-puppet.yaml
@@ -56,6 +56,7 @@ resource_registry:
   OS::TripleO::Network::Storage: network/noop.yaml
   OS::TripleO::Network::Tenant: network/noop.yaml
 
+  OS::TripleO::Network::Ports::NetVipMap: network/ports/net_ip_map.yaml
   OS::TripleO::Network::Ports::NetIpMap: network/ports/net_ip_map.yaml
   OS::TripleO::Network::Ports::NetIpSubnetMap: network/ports/net_ip_subnet_map.yaml
   OS::TripleO::Network::Ports::NetIpListMap: network/ports/net_ip_list_map.yaml
diff --git a/overcloud-resource-registry.yaml b/overcloud-resource-registry.yaml
index ed02551bc2..11a33599d9 100644
--- a/overcloud-resource-registry.yaml
+++ b/overcloud-resource-registry.yaml
@@ -39,6 +39,7 @@ resource_registry:
   OS::TripleO::Network::Storage: network/noop.yaml
   OS::TripleO::Network::Tenant: network/noop.yaml
 
+  OS::TripleO::Network::Ports::NetVipMap: network/ports/net_ip_map.yaml
   OS::TripleO::Network::Ports::NetIpMap: network/ports/net_ip_map.yaml
   OS::TripleO::Network::Ports::NetIpSubnetMap: network/ports/net_ip_subnet_map.yaml
   OS::TripleO::Network::Ports::NetIpListMap: network/ports/net_ip_list_map.yaml
diff --git a/overcloud-without-mergepy.yaml b/overcloud-without-mergepy.yaml
index f679c6bb8d..82121dcfa1 100644
--- a/overcloud-without-mergepy.yaml
+++ b/overcloud-without-mergepy.yaml
@@ -889,8 +889,8 @@ resources:
           SwiftPartPower: {get_param: SwiftPartPower}
           SwiftPassword: {get_param: SwiftPassword}
           SwiftReplicas: { get_param: SwiftReplicas}
-          VirtualIP: {get_attr: [ControlVirtualIP, fixed_ips, 0, ip_address]} # deprecated. Use per service VIP settings instead now.
-          PublicVirtualIP: {get_attr: [PublicVirtualIP, ip_address]}
+          VirtualIP: {get_attr: [VipMap, net_ip_map, ctlplane]} # deprecated. Use per service VIP settings instead now.
+          PublicVirtualIP: {get_attr: [VipMap, net_ip_map, external]}
           ServiceNetMap: {get_param: ServiceNetMap}
           EndpointMap: {get_attr: [EndpointMap, endpoint_map]}
           CeilometerApiVirtualIP: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, CeilometerApiNetwork]}]}
@@ -963,7 +963,7 @@ resources:
           NovaComputeExtraConfig: {get_param: NovaComputeExtraConfig}
           NovaComputeLibvirtType: {get_param: NovaComputeLibvirtType}
           NovaEnableRbdBackend: {get_param: NovaEnableRbdBackend}
-          NovaPublicIP: {get_attr: [PublicVirtualIP, ip_address]}
+          NovaPublicIP: {get_attr: [VipMap, net_ip_map, external]}
           NovaPassword: {get_param: NovaPassword}
           NtpServer: {get_param: NtpServer}
           RabbitHost: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, RabbitMqNetwork]}]}
@@ -1000,7 +1000,7 @@ resources:
           CinderPassword: {get_param: CinderPassword}
           KeyName: {get_param: KeyName}
           Flavor: {get_param: OvercloudBlockStorageFlavor}
-          VirtualIP: {get_attr: [ControlVirtualIP, fixed_ips, 0, ip_address]}
+          VirtualIP: {get_attr: [VipMap, net_ip_map, ctlplane]}
           GlanceApiVirtualIP: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, GlanceApiNetwork]}]}
           RabbitPassword: {get_param: RabbitPassword}
           RabbitUserName: {get_param: RabbitUserName}
@@ -1178,7 +1178,7 @@ resources:
       PortName: storage_management_virtual_ip
 
   VipMap:
-    type: OS::TripleO::Network::Ports::NetIpMap
+    type: OS::TripleO::Network::Ports::NetVipMap
     properties:
       ControlPlaneIp: {get_attr: [ControlVirtualIP, fixed_ips, 0, ip_address]}
       ExternalIp: {get_attr: [PublicVirtualIP, ip_address]}
@@ -1213,11 +1213,11 @@ resources:
         mysql_vip: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, MysqlNetwork]}]}
         rabbit_vip: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, RabbitMqNetwork]}]}
         # direct configuration of Virtual IPs for each network
-        control_virtual_ip: {get_attr: [ControlVirtualIP, fixed_ips, 0, ip_address]}
-        public_virtual_ip: {get_attr: [PublicVirtualIP, ip_address]}
-        internal_api_virtual_ip: {get_attr: [InternalApiVirtualIP, ip_address]}
-        storage_virtual_ip: {get_attr: [StorageVirtualIP, ip_address]}
-        storage_mgmt_virtual_ip: {get_attr: [StorageMgmtVirtualIP, ip_address]}
+        control_virtual_ip: {get_attr: [VipMap, net_ip_map, ctlplane]}
+        public_virtual_ip: {get_attr: [VipMap, net_ip_map, external]}
+        internal_api_virtual_ip: {get_attr: [VipMap, net_ip_map, internal_api]}
+        storage_virtual_ip: {get_attr: [VipMap, net_ip_map, storage]}
+        storage_mgmt_virtual_ip: {get_attr: [VipMap, net_ip_map, storage_mgmt]}
 
   ControllerBootstrapNodeConfig:
     type: OS::TripleO::BootstrapNode::SoftwareConfig
@@ -1451,7 +1451,7 @@ outputs:
     value: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, KeystoneAdminApiNetwork]}]}
   PublicVip:
     description: Controller VIP for public API endpoints
-    value: {get_attr: [PublicVirtualIP, ip_address]}
+    value: {get_attr: [VipMap, net_ip_map, external]}
   CeilometerInternalVip:
     description: VIP for Ceilometer API internal endpoint
     value: {get_attr: [VipMap, net_ip_map, {get_param: [ServiceNetMap, CeilometerApiNetwork]}]}