Add ability to catch policy from mines based on compound targets
Related-Prod: PROD-31956
Change-Id: I848d5d202924ff664aff60498d3a23281e21b8cb
diff --git a/README.rst b/README.rst
index 7e52bf4..082d435 100644
--- a/README.rst
+++ b/README.rst
@@ -96,6 +96,13 @@
name: keystone_policy.json
grain_name: keystone_policy
enabled: true
+ dns:
+ enabled: True
+ source: 'mine'
+ target_type: 'compound'
+ host: 'I@designate:server'
+ grain_name: 'designate_policy'
+ name: 'designate_policy.json'
compute:
source: file
name: nova_policy.json
diff --git a/horizon/server/service.sls b/horizon/server/service.sls
index 1c3d883..8fd3298 100644
--- a/horizon/server/service.sls
+++ b/horizon/server/service.sls
@@ -31,8 +31,13 @@
{%- if policy.get('enabled', True) %}
{%- if policy.get('source', 'file') == 'mine' %}
- {%- set service_grains = salt['mine.get'](policy['host'], 'grains.items') %}
- {%- set service_policy = service_grains.get(policy['host'], {}).get(policy['grain_name'], {}) %}
+ {%- set service_grains = salt['mine.get'](policy['host'], 'grains.items', policy.get('target_type', 'glob')) %}
+ {%- if policy.get('target_type', 'glob') == 'compound' %}
+ {%- set node = service_grains.keys()[0] %}
+ {%- else %}
+ {%- set node = policy['host'] %}
+ {%- endif %}
+ {%- set service_policy = service_grains.get(node, {}).get(policy['grain_name'], {}) %}
{%- if service_policy %}