Merge "Make node_ips generic in the Heat template"

This commit is contained in:
Zuul 2019-06-04 16:16:54 +00:00 committed by Gerrit Code Review
commit d290ebfaa8
2 changed files with 32 additions and 38 deletions

View File

@ -72,6 +72,29 @@ resources:
{{network.name_lower}}: {get_param: {{network.name}}NetName}
{%- endfor %}
ServicesIpData:
type: OS::Heat::Value
depends_on: EnabledServicesValue
properties:
value:
map_merge:
repeat:
template:
# $$ is used here to indicate the start/end of an ansible jinja
# expression. we could use {{ and }} but the escaping would make it
# difficult to read, and it would still come out surrounded by
# quotes. On the ansible side,
# we then set variable_start_string/variable_end_string to $$ for
# use with the template module
SERVICE_node_ips: $$ groups['SERVICE'] | default ([]) | map('extract', hostvars, service_net_map['SERVICE_network'] | default('ctlplane') ~ '_ip') | list | to_json $$
for_each:
SERVICE:
yaql:
expression: let(root => $) -> coalesce($root.data.enabled_services, []).where($root.data.service_net_map.keys().contains($ + "_network"))
data:
service_net_map: {get_param: ServiceNetMap}
enabled_services: {get_attr: [EnabledServicesValue, value]}
outputs:
net_ip_map:
description: >
@ -81,39 +104,17 @@ outputs:
service_ips:
description: >
Map of enabled services to a list of their IP addresses
value:
yaql:
# This filters any entries where the value hasn't been substituted for
# a list, e.g it's still $service_network. This happens when there is
# no network defined for the service in the ServiceNetMap, which is OK
# as not all services have to be bound to a network, so we filter them
expression: dict($.data.map.items().where(not isString($[1])))
data:
map:
map_replace:
- map_replace:
- map_merge:
repeat:
template:
SERVICE_node_ips: SERVICE_network
for_each:
SERVICE: {get_attr: [EnabledServicesValue, value]}
- values: {get_param: ServiceNetMap}
- values: {get_attr: [NetIpMapValue, value]}
value: {get_attr: [ServicesIpData, value]}
ctlplane_service_ips:
description: >
Map of enabled services to a list of their ctlplane IP addresses
value:
yaql:
expression: dict($.data.map.items().where(len($[1]) > 0))
data:
map:
map_merge:
repeat:
template:
SERVICE_ctlplane_node_ips: {get_param: ControlPlaneIpList}
for_each:
SERVICE: {get_attr: [EnabledServicesValue, value]}
map_merge:
repeat:
template:
SERVICE_ctlplane_node_ips: $$ groups['SERVICE'] | default ([]) | map('extract', hostvars, 'ctlplane_ip') | list | to_json $$
for_each:
SERVICE: {get_attr: [EnabledServicesValue, value]}
service_hostnames:
description: >
Map of enabled services to a list of hostnames where they're running

View File

@ -785,16 +785,9 @@ resources:
controller_ips: {get_attr: [{{primary_role_name}}, ip_address]}
controller_names: {get_attr: [{{primary_role_name}}, hostname]}
service_ips:
# Note (shardy) this somewhat complex yaql may be replaced
# with a map_deep_merge function in ocata. It merges the
# list of maps, but appends to colliding lists when a service
# is deployed on more than one role
yaql:
expression: dict($.data.l.where($ != null).selectMany($.items()).groupBy($[0], $[1]).select([$[0], $[1].flatten()]))
data:
l:
map_merge:
{%- for role in roles %}
- {get_attr: [{{role.name}}IpListMap, service_ips]}
- {get_attr: [{{role.name}}IpListMap, service_ips]}
{%- endfor %}
service_node_names:
yaql: