Added yaml class dumper to support indentation

The default py yaml `safe_dumps` keeps to the yaml spec which states
incremental indentations are not required. Sadly, without the
indentations some consumers of yaml configurations files will break.
This commit adds an incremental indentation dumper to cater for all
yaml configuration consumers.

Change-Id: Ifa5bcc6ff9f0a9cb5e619e62d0356f5d6887ca6e
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2017-01-24 23:00:20 -06:00
parent b78bf8ce43
commit 80d59cdf96
No known key found for this signature in database
GPG Key ID: 69FEFFC5E2D9273F
3 changed files with 16 additions and 10 deletions

View File

@ -73,6 +73,11 @@ def _convert_2_string(item):
return str(item)
class IDumper(yaml.SafeDumper):
def increase_indent(self, flow=False, indentless=False):
return super(IDumper, self).increase_indent(flow, False)
class MultiKeyDict(dict):
"""Dictionary class which supports duplicate keys.
This class allows for an item to be added into a standard python dictionary
@ -374,8 +379,9 @@ class ActionModule(ActionBase):
new_items=config_overrides,
list_extend=list_extend
)
return yaml.safe_dump(
return yaml.dump(
merged_resultant,
Dumper=IDumper,
default_flow_style=False,
width=1000,
)

View File

@ -1,8 +1,8 @@
list_one:
- one
- two
- three
- four
- one
- two
- three
- four
list_two:
- one
- two
- one
- two

View File

@ -1,5 +1,5 @@
list_one:
- four
- four
list_two:
- one
- two
- one
- two