diff options
author | Andrew Butcher <abutcher@redhat.com> | 2016-04-19 13:12:04 -0400 |
---|---|---|
committer | Andrew Butcher <abutcher@redhat.com> | 2016-04-20 10:31:41 -0400 |
commit | 7247fb26ada1973d895b5831005250cf494b6d93 (patch) | |
tree | 1a6c16ba2b8c3cf617c8db307f03f2d9f0ca5495 /roles | |
parent | be00d3399795278ac799fab848918d5bd64a2c46 (diff) | |
download | openshift-7247fb26ada1973d895b5831005250cf494b6d93.tar.gz openshift-7247fb26ada1973d895b5831005250cf494b6d93.tar.bz2 openshift-7247fb26ada1973d895b5831005250cf494b6d93.tar.xz openshift-7247fb26ada1973d895b5831005250cf494b6d93.zip |
Remove empty facts from nested dictionaries.
Diffstat (limited to 'roles')
-rwxr-xr-x | roles/openshift_facts/library/openshift_facts.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index f0f3e3861..681521f51 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1837,14 +1837,7 @@ class OpenShiftFacts(object): val = [x.strip() for x in val.split(',')] new_local_facts['docker'][key] = list(set(val) - set([''])) - for facts in new_local_facts.values(): - keys_to_delete = [] - if isinstance(facts, dict): - for fact, value in facts.iteritems(): - if value == "" or value is None: - keys_to_delete.append(fact) - for key in keys_to_delete: - del facts[key] + new_local_facts = self.remove_empty_facts(new_local_facts) if new_local_facts != local_facts: self.validate_local_facts(new_local_facts) @@ -1855,6 +1848,23 @@ class OpenShiftFacts(object): self.changed = changed return new_local_facts + def remove_empty_facts(self, facts=None): + """ Remove empty facts + + Args: + facts (dict): facts to clean + """ + facts_to_remove = [] + for fact, value in facts.iteritems(): + if isinstance(facts[fact], dict): + facts[fact] = self.remove_empty_facts(facts[fact]) + else: + if value == "" or value is None: + facts_to_remove.append(fact) + for fact in facts_to_remove: + del facts[fact] + return facts + def validate_local_facts(self, facts=None): """ Validate local facts |