aboutsummaryrefslogtreecommitdiffstats
path: root/mcp/patches/0014-reclass.storage.node-Merge-duplicate-nodes.patch
blob: a9d5b6589f84fc9f901727e1b507ad244a6d1cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Copyright (c) 2018 Mirantis Inc., Enea AB and others.
:
: All rights reserved. This program and the accompanying materials
: are made available under the terms of the Apache License, Version 2.0
: which accompanies this distribution, and is available at
: http://www.apache.org/licenses/LICENSE-2.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Date: Sun, 03 Dec 2017 22:03:01 +0200
Subject: [PATCH] reclass.storage.node: Merge duplicate nodes

Reclass does not support duplicate nodes in top pillar, so merge all
nodes with the same name into a single node, inheriting classes from
all instances.

This allows using multiple "system.reclass.storage.system.*_cluster"
classes for the same node, based on re-using the name (hostname).

NOTE: defaults.merge module does not merge lists (e.g. for classes),
so handle that case separately.

Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
---

diff --git a/reclass/storage/node.sls b/reclass/storage/node.sls
--- a/reclass/storage/node.sls
+++ b/reclass/storage/node.sls
@@ -1,7 +1,15 @@
 {%- from "reclass/map.jinja" import storage with context %}
 {%- if storage.enabled %}

+{%- set storage_by_name = {} %}
 {%- for node_name, node in storage.get('node', {}).iteritems() %}
+{%- set new_node_name = node.get('name', node_name) %}
+{%- set new_node = storage_by_name.get(new_node_name, {'classes': []}) %}
+{%- do salt['defaults.merge'](node, {'classes': new_node.classes + node.classes}) %}
+{%- do salt['defaults.merge'](storage_by_name, {new_node_name: node}) %}
+{%- endfor %}
+
+{%- for node_name, node in storage_by_name.iteritems() %}

 {%- if node.repeat is defined %}