diff --git a/playbooks/network_settings_intent.yml b/playbooks/network_settings_intent.yml index f74d80049a..5cb7cd4bfb 100644 --- a/playbooks/network_settings_intent.yml +++ b/playbooks/network_settings_intent.yml @@ -1,6 +1,6 @@ - hosts: dnac_servers vars_files: - - credentials_245.yml + - credentials.yml gather_facts: no connection: local tasks: @@ -79,7 +79,7 @@ configure_dnac_ip: false # ip_addresses: # - 10.0.0.6 - syslogServer: + syslog_server: configure_dnac_ip: false # ip_addresses: # - 10.0.0.7 diff --git a/plugins/module_utils/dnac.py b/plugins/module_utils/dnac.py index 6b22e70419..b88f1a7afa 100644 --- a/plugins/module_utils/dnac.py +++ b/plugins/module_utils/dnac.py @@ -361,6 +361,31 @@ def check_string_dictionary(self, task_details_data): pass return None + def camel_to_snake_case(self, config): + """ + Convert camel case keys to snake case keys in the config. + + Parameters: + config (list) - Playbook details provided by the user. + + Returns: + new_config (list) - Updated config after eliminating the camel cases. + """ + + if isinstance(config, dict): + new_config = {} + for key, value in config.items(): + new_key = re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', key).lower() + if new_key != key: + self.log("{0} will be deprecated soon. Please use {1}.".format(key, new_key)) + new_value = self.camel_to_snake_case(value) + new_config[new_key] = new_value + elif isinstance(config, list): + return [self.camel_to_snake_case(item) for item in config] + else: + return config + return new_config + def log(msg, frameIncrement=0): with open('dnac.log', 'a') as of: diff --git a/plugins/modules/device_credential_intent.py b/plugins/modules/device_credential_intent.py index 68c3ce31e5..0cd6b79170 100644 --- a/plugins/modules/device_credential_intent.py +++ b/plugins/modules/device_credential_intent.py @@ -840,6 +840,7 @@ def validate_input(self): } # Validate playbook params against the specification (temp_spec) + self.config = self.camel_to_snake_case(self.config) valid_temp, invalid_params = validate_list_of_dicts(self.config, temp_spec) if invalid_params: self.msg = "Invalid parameters in playbook: {0}".format("\n".join(invalid_params)) diff --git a/plugins/modules/network_settings_intent.py b/plugins/modules/network_settings_intent.py index 3d1f319b0a..a88b8151c3 100644 --- a/plugins/modules/network_settings_intent.py +++ b/plugins/modules/network_settings_intent.py @@ -256,7 +256,7 @@ elements: str type: list type: dict - syslogServer: + syslog_server: description: Network V2's syslogServer. suboptions: configure_dnac_ip: @@ -359,7 +359,7 @@ snmp_server: configure_dnac_ip: True ip_addresses: list - syslogServer: + syslog_server: configure_dnac_ip: True ip_addresses: list site_name: string @@ -499,7 +499,7 @@ def validate_input(self): "primary_ip_address": {"type": 'string'}, "secondary_ip_address": {"type": 'string'} }, - "syslogServer": { + "syslog_server": { "type": 'dict', "ip_addresses": {"type": 'list'}, "configure_dnac_ip": {"type": 'bool'} @@ -544,6 +544,7 @@ def validate_input(self): } # Validate playbook params against the specification (temp_spec) + self.config = self.camel_to_snake_case(self.config) valid_temp, invalid_params = validate_list_of_dicts(self.config, temp_spec) if invalid_params: self.msg = "Invalid parameters in playbook: {0}".format("\n".join(invalid_params)) @@ -1474,7 +1475,7 @@ def get_want_network(self, network_management_details): else: del want_network_settings["snmpServer"] - syslogServer = network_management_details.get("syslogServer") + syslogServer = network_management_details.get("syslog_server") if syslogServer is not None: if syslogServer.get("configure_dnac_ip") is not None: want_network_settings.get("syslogServer").update({ diff --git a/plugins/modules/template_intent.py b/plugins/modules/template_intent.py index ad5056336d..ef221201e2 100644 --- a/plugins/modules/template_intent.py +++ b/plugins/modules/template_intent.py @@ -1436,8 +1436,7 @@ def validate_input(self): } } # Validate template params - self.log(str(self.config)) - self.log(str(temp_spec)) + self.config = self.camel_to_snake_case(self.config) valid_temp, invalid_params = validate_list_of_dicts( self.config, temp_spec )