summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager
diff options
context:
space:
mode:
Diffstat (limited to 'meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager')
-rwxr-xr-xmeta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/merge_settings.py58
-rw-r--r--meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/xyz.openbmc_project.Settings.service12
2 files changed, 70 insertions, 0 deletions
diff --git a/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/merge_settings.py b/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/merge_settings.py
new file mode 100755
index 000000000..01f5e3552
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/merge_settings.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+"""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()
+
+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)
+ print('Wrote merged target YAML file ' + target_filename)
diff --git a/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/xyz.openbmc_project.Settings.service b/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/xyz.openbmc_project.Settings.service
new file mode 100644
index 000000000..50e21665c
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/settings/phosphor-settings-manager/xyz.openbmc_project.Settings.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Phosphor Settings Daemon
+
+[Service]
+ExecStart=/usr/bin/env phosphor-settings-manager
+SyslogIdentifier=phosphor-settings-manager
+Restart=always
+Type=dbus
+BusName={BUSNAME}
+
+[Install]
+WantedBy={SYSTEMD_DEFAULT_TARGET}
OpenPOWER on IntegriCloud