From 9313e18f302aafaa1cbe92ef59499af6d2074e1f Mon Sep 17 00:00:00 2001
From: Dan Prince <dprince@redhat.com>
Date: Sun, 11 Dec 2016 08:16:36 -0500
Subject: [PATCH] Add "deployed server" fake neutron ports

This patch swaps out the noop ctlplane port for a more
proper fake neutron port stack. This stack is a swap
in for the OS::Neutron::Port heat resource and can be
controlled via the DeployedServerPortMap parameter.

By relying on <hostname>-<network> naming conventions in the
map we can map IPs to specific servers without using the
Neutron API. This will allow us to inject IP information
into the Heat stack within the new t-h-t undercloud installer
which currently does not run a Neutron service.

Change-Id: I29fbc720c3d582cbb94385e65e4b64b101f7eac9
---
 deployed-server/ctlplane-port.yaml            | 23 -------
 deployed-server/deployed-neutron-port.yaml    | 67 +++++++++++++++++++
 deployed-server/deployed-server.yaml          | 12 +++-
 environments/deployed-server-environment.yaml |  2 +-
 .../deployed-server-noop-ctlplane.yaml        |  3 +-
 5 files changed, 78 insertions(+), 29 deletions(-)
 delete mode 100644 deployed-server/ctlplane-port.yaml
 create mode 100644 deployed-server/deployed-neutron-port.yaml

diff --git a/deployed-server/ctlplane-port.yaml b/deployed-server/ctlplane-port.yaml
deleted file mode 100644
index eb10fba05d..0000000000
--- a/deployed-server/ctlplane-port.yaml
+++ /dev/null
@@ -1,23 +0,0 @@
-heat_template_version: 2014-10-16
-
-parameters:
-  Hostname:
-    type: string
-
-resources:
-
-  ControlPlanePort:
-    type: OS::Neutron::Port
-    properties:
-      network: ctlplane
-      name:
-        list_join:
-          - '-'
-          - - {get_param: Hostname}
-            - ctlplane
-            - port
-      replacement_policy: AUTO
-
-outputs:
-  ip_address:
-    value: {get_attr: [ControlPlanePort, fixed_ips, 0, ip_address]}
diff --git a/deployed-server/deployed-neutron-port.yaml b/deployed-server/deployed-neutron-port.yaml
new file mode 100644
index 0000000000..7855be89f4
--- /dev/null
+++ b/deployed-server/deployed-neutron-port.yaml
@@ -0,0 +1,67 @@
+heat_template_version: 2016-10-14
+
+description: "
+  A fake OS::Neutron::Port stack which outputs fixed_ips and subnets based on
+  the input from the DeployedServerPortMap (set via parameter_defaults). This
+  lookup requires the use of port naming conventions. In order for this to work
+  with deployed-server the keys should be <hostname>-<network>.
+  Example:
+    parameter_defaults:
+      DeployedServerPortMap:
+        gatsby_ctlplane:
+          fixed_ips:
+            - ip_address: 127.0.0.1
+          subnets:
+            - cidr: 24"
+
+parameters:
+  name:
+    default: ''
+    type: string
+  network:
+    default: ''
+    type: string
+  fixed_ips:
+    default: ''
+    type: comma_delimited_list
+  replacement_policy:
+    default: ''
+    type: string
+  DeployedServerPortMap:
+    default: {}
+    type: json
+
+
+outputs:
+  fixed_ips:
+    value:
+      {get_param: [DeployedServerPortMap, {get_param: name}, fixed_ips]}
+  subnets:
+    value:
+      {get_param: [DeployedServerPortMap, {get_param: name}, subnets]}
+  name:
+    value: {get_param: name}
+  status:
+    value: DOWN
+  allowed_address_pairs:
+    value: {}
+  device_id:
+    value: ''
+  device_owner:
+    value: {get_param: network}
+  dns_assignment:
+    value: ''
+  port_security_enabled:
+    value: False
+  admin_state_up:
+    value: False
+  security_groups:
+    value: {}
+  network_id:
+    value: ''
+  tenant_id:
+    value: ''
+  qos_policy_id:
+    value: ''
+  mac_address:
+    value: ''
diff --git a/deployed-server/deployed-server.yaml b/deployed-server/deployed-server.yaml
index 10e934d1fc..690c3f2fcb 100644
--- a/deployed-server/deployed-server.yaml
+++ b/deployed-server/deployed-server.yaml
@@ -80,10 +80,16 @@ resources:
       config: {get_resource: HostsEntryConfig}
       server: {get_resource: deployed-server}
 
-  ControlPlanePort:
+  ControlPlanePortImpl:
     type: OS::TripleO::DeployedServer::ControlPlanePort
     properties:
-      Hostname: {get_attr: [HostsEntryDeployment, hostname]}
+      network: ctlplane
+      name:
+        list_join:
+          - '-'
+          - - {get_attr: [HostsEntryDeployment, hostname]}
+            - ctlplane
+      replacement_policy: AUTO
 
 outputs:
   OS::stack_id:
@@ -91,6 +97,6 @@ outputs:
   networks:
     value:
       ctlplane:
-        - {get_attr: [ControlPlanePort, ip_address]}
+        - {get_attr: [ControlPlanePortImpl, fixed_ips, 0, ip_address]}
   name:
     value: {get_attr: [HostsEntryDeployment, hostname]}
diff --git a/environments/deployed-server-environment.yaml b/environments/deployed-server-environment.yaml
index e9004bd610..7a6639f9be 100644
--- a/environments/deployed-server-environment.yaml
+++ b/environments/deployed-server-environment.yaml
@@ -1,3 +1,3 @@
 resource_registry:
   OS::TripleO::Server: ../deployed-server/deployed-server.yaml
-  OS::TripleO::DeployedServer::ControlPlanePort: ../deployed-server/ctlplane-port.yaml
+  OS::TripleO::DeployedServer::ControlPlanePort: OS::Neutron::Port
diff --git a/environments/deployed-server-noop-ctlplane.yaml b/environments/deployed-server-noop-ctlplane.yaml
index cfda314d04..54f5e41deb 100644
--- a/environments/deployed-server-noop-ctlplane.yaml
+++ b/environments/deployed-server-noop-ctlplane.yaml
@@ -1,4 +1,3 @@
 resource_registry:
   OS::TripleO::Server: ../deployed-server/deployed-server.yaml
-  OS::TripleO::DeployedServerConfig: ../deployed-server/deployed-server-config.yaml
-  OS::TripleO::DeployedServer::ControlPlanePort: OS::Heat::None
+  OS::TripleO::DeployedServer::ControlPlanePort: ../deployed-server/deployed-neutron-port.yaml