in ebcli/objects/environmentsettings.py [0:0]
def collect_changes(self, usr_model):
"""
Grabs all things in the usr_model that are different and
returns just the changes
:param usr_model: User model, key-value style
:return: api_model
"""
self.api_model = self.remove_unwanted_settings()
self.ignore_default_resource_names()
changes = []
remove = []
option_settings = self.api_model['OptionSettings']
usr_options = usr_model['settings']
for setting in option_settings:
# Compare value for given optionName
namespace = setting['Namespace']
option = setting['OptionName']
resource_name = None
if 'ResourceName' in setting:
resource_name = setting['ResourceName']
key = resource_name + '.' + namespace
else:
key = namespace
try:
usr_value = usr_options[key][option]
del usr_options[key][option]
# If they dont match, take the user value
if 'Value' in setting:
if setting['Value'] != usr_value:
setting['Value'] = usr_value
if usr_value:
changes.append(setting)
else:
remove.append(
_get_option_setting_dict(
namespace,
option,
None,
resource_name
)
)
else:
if usr_value is not None:
setting['Value'] = usr_value
changes.append(setting)
except KeyError:
# user removed setting. We want to add to remove list
d = _get_option_setting_dict(
namespace,
option,
None,
resource_name
)
remove.append(d)
# Now we look for added options:
for namespace, options in six.iteritems(usr_options):
if options:
namespace, resource_name = \
_get_namespace_and_resource_name(namespace)
for option, value in six.iteritems(options):
if value is not None:
changes.append(_get_option_setting_dict(
namespace, option, value, resource_name))
return changes, remove