summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host
diff options
context:
space:
mode:
authorDhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>2017-07-12 06:45:14 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-08-08 14:55:33 +0000
commite251ef95850a75c73794a5eccbf0930d76f0d182 (patch)
tree737bd160588716b9650e8cbb4647f6a24b7901b9 /meta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host
parent1025084ea00ab69774d72ab19ae416af724710c0 (diff)
downloadtalos-openbmc-e251ef95850a75c73794a5eccbf0930d76f0d182.tar.gz
talos-openbmc-e251ef95850a75c73794a5eccbf0930d76f0d182.zip
Configuration yaml changes for virtual sensors
Change-Id: I270a62022340d6be382091a6595859dafdb634ae Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Diffstat (limited to 'meta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host')
-rwxr-xr-xmeta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host/merge_yamls.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/meta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host/merge_yamls.py b/meta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host/merge_yamls.py
new file mode 100755
index 000000000..5e6c4b5e6
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/ipmi/phosphor-ipmi-host/merge_yamls.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+"""Copied from phosphor-settings-manager
+Loads a "target" YAML file and overwrites its values with values from
+"override" YAML files.
+
+Override files are processed in the order given.
+
+Usage:
+ merge_settings.py <target yaml> [override yamls]
+"""
+import sys
+import yaml
+import copy
+
+def dict_merge(target, source):
+ """Deep merge for dicts.
+
+ Works like dict.update() that recursively updates any dict values present in
+ both parameters.
+
+ Args:
+ target (dict): Values to be overwritten by corresponding values from
+ `source`.
+ source (dict): Overriding values. Not changed by call.
+
+ Returns:
+ `target` with values overwritten from those in `source` at any and all
+ levels of nested dicts.
+ """
+ if not isinstance(source, dict):
+ return source
+ for k, v in source.iteritems():
+ if k in target and isinstance(target[k], dict):
+ dict_merge(target[k], v)
+ else:
+ target[k] = copy.deepcopy(v)
+ return target
+
+if len(sys.argv) < 2:
+ sys.exit('Argument required: target yaml')
+
+if len(sys.argv) == 2:
+ # No overrides to handle
+ sys.exit(0)
+
+target_filename = sys.argv[1]
+with open(target_filename) as target_file:
+ data = yaml.safe_load(target_file)
+ print('Loaded target YAML file ' + target_filename)
+
+for override_filename in sys.argv[2:]:
+ with open(override_filename) as override_file:
+ override = yaml.safe_load(override_file)
+ dict_merge(data, override)
+ print('Merged override YAML file ' + override_filename)
+
+with open(target_filename, 'w') as target_file:
+ yaml.dump(data, target_file, default_flow_style=False)
+ print('Wrote merged target YAML file ' + target_filename)
OpenPOWER on IntegriCloud