Skip to content

Commit

Permalink
Merge pull request #98 from MUTHU-RAKESH-27/main
Browse files Browse the repository at this point in the history
Supported both the camel and snake case.
  • Loading branch information
madhansansel authored Jan 16, 2024
2 parents 3344459 + 7c1ee6b commit 0c89a8e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions playbooks/network_settings_intent.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- hosts: dnac_servers
vars_files:
- credentials_245.yml
- credentials.yml
gather_facts: no
connection: local
tasks:
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions plugins/module_utils/dnac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/device_credential_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 5 additions & 4 deletions plugins/modules/network_settings_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
elements: str
type: list
type: dict
syslogServer:
syslog_server:
description: Network V2's syslogServer.
suboptions:
configure_dnac_ip:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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({
Expand Down
3 changes: 1 addition & 2 deletions plugins/modules/template_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 0c89a8e

Please sign in to comment.