Skip to content

Commit

Permalink
Merge pull request #46 from madhansansel/main
Browse files Browse the repository at this point in the history
latest changes 04/12/24
  • Loading branch information
rukapse authored Apr 12, 2024
2 parents 7165e1e + e612450 commit a0d7eaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 11 additions & 7 deletions plugins/modules/inventory_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,12 @@ def get_udf_id(self, field_name):

return udf_id

def mandatory_parameter(self):
def mandatory_parameter(self, device_to_add_in_ccc):
"""
Check for and validate mandatory parameters for adding network devices in Cisco Catalyst Center.
Parameters:
self (object): An instance of a class used for interacting with Cisco Cisco Catalyst Center.
device_to_add_in_ccc(list): List to device ip addresses to be added in Cisco Catalyst Center.
Returns:
dict: The input `config` dictionary if all mandatory parameters are present.
Description:
Expand All @@ -1953,12 +1954,12 @@ def mandatory_parameter(self):

if mandatory_params_absent:
self.status = "failed"
self.msg = "Required parameters {0} for adding devices are not present".format(str(mandatory_params_absent))
self.msg = "Required parameters {0} for adding devices '{1}' are not present".format(str(mandatory_params_absent), str(device_to_add_in_ccc))
self.result['msg'] = self.msg
self.log(self.msg, "ERROR")
else:
self.status = "success"
self.msg = "Required parameter for Adding the devices in Inventory are present."
self.msg = "Required parameters for adding the devices '{0}' to inventory are present.".format(str(device_to_add_in_ccc))
self.log(self.msg, "INFO")

return self
Expand Down Expand Up @@ -2569,6 +2570,7 @@ def update_interface_detail_of_device(self, device_to_update):

# Call the Get interface details by device IP API and fetch the interface Id
is_update_occurred = False
response_list = []
for device_ip in device_to_update:
interface_params = self.config[0].get('update_interface_details')
interface_names_list = interface_params.get('interface_name')
Expand Down Expand Up @@ -2597,7 +2599,7 @@ def update_interface_detail_of_device(self, device_to_update):
if response.get('role').upper() != "ACCESS":
self.msg = "The action to clear the MAC Address table is only supported for devices with the ACCESS role."
self.log(self.msg, "WARNING")
self.result['response'] = self.msg
response_list.append(self.msg)
self.result['changed'] = False
else:
deploy_mode = interface_params.get('deployment_mode', 'Deploy')
Expand Down Expand Up @@ -2663,7 +2665,7 @@ def update_interface_detail_of_device(self, device_to_update):
self.status = "success"
is_update_occurred = True
self.msg = "Successfully updated the Interface Details for device '{0}'.".format(device_ip)
self.result['response'] = self.msg
response_list.append(self.msg)
self.log(self.msg, "INFO")
break
elif execution_details.get("isError"):
Expand All @@ -2683,9 +2685,10 @@ def update_interface_detail_of_device(self, device_to_update):
self.result['changed'] = False
self.msg = "Port actions are only supported on user facing/access ports as it's not allowed or No Updation required"
self.log(self.msg, "INFO")
self.result['response'] = self.msg
response_list.append(self.msg)

self.result['changed'] = is_update_occurred
self.result['response'] = response_list

return self

Expand Down Expand Up @@ -2977,7 +2980,8 @@ def get_diff_merged(self, config):
device_params.pop('snmpPrivPassphrase', None)
device_params.pop('snmpPrivProtocol', None)

self.mandatory_parameter().check_return_status()
device_to_add_in_ccc = device_params['ipAddress']
self.mandatory_parameter(device_to_add_in_ccc).check_return_status()
try:
response = self.dnac._exec(
family="devices",
Expand Down
20 changes: 12 additions & 8 deletions plugins/modules/inventory_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1916,11 +1916,12 @@ def get_udf_id(self, field_name):

return udf_id

def mandatory_parameter(self):
def mandatory_parameter(self, device_to_add_in_ccc):
"""
Check for and validate mandatory parameters for adding network devices in Cisco Catalyst Center.
Parameters:
self (object): An instance of a class used for interacting with Cisco Cisco Catalyst Center.
device_to_add_in_ccc(list): List to device ip addresses to be added in Cisco Catalyst Center.
Returns:
dict: The input `config` dictionary if all mandatory parameters are present.
Description:
Expand All @@ -1945,12 +1946,12 @@ def mandatory_parameter(self):

if mandatory_params_absent:
self.status = "failed"
self.msg = "Required parameters {0} for adding devices are not present".format(str(mandatory_params_absent))
self.msg = "Required parameters {0} for adding devices '{1}' are not present".format(str(mandatory_params_absent), str(device_to_add_in_ccc))
self.result['msg'] = self.msg
self.log(self.msg, "ERROR")
else:
self.status = "success"
self.msg = "Required parameter for Adding the devices in Inventory are present."
self.msg = "Required parameters for adding the devices '{0}' to inventory are present.".format(str(device_to_add_in_ccc))
self.log(self.msg, "INFO")

return self
Expand Down Expand Up @@ -2561,6 +2562,7 @@ def update_interface_detail_of_device(self, device_to_update):

# Call the Get interface details by device IP API and fetch the interface Id
is_update_occurred = False
response_list = []
for device_ip in device_to_update:
interface_params = self.config[0].get('update_interface_details')
interface_names_list = interface_params.get('interface_name')
Expand Down Expand Up @@ -2589,7 +2591,7 @@ def update_interface_detail_of_device(self, device_to_update):
if response.get('role').upper() != "ACCESS":
self.msg = "The action to clear the MAC Address table is only supported for devices with the ACCESS role."
self.log(self.msg, "WARNING")
self.result['response'] = self.msg
response_list.append(self.msg)
self.result['changed'] = False
else:
deploy_mode = interface_params.get('deployment_mode', 'Deploy')
Expand Down Expand Up @@ -2622,7 +2624,7 @@ def update_interface_detail_of_device(self, device_to_update):
self.msg = """Interface details for the given interface '{0}' are already updated in the Cisco Catalyst Center for the
device '{1}'.""".format(interface_name, device_ip)
self.log(self.msg, "INFO")
self.result['response'] = self.msg
response_list.append(self.msg)
continue

update_interface_params = {
Expand Down Expand Up @@ -2655,7 +2657,7 @@ def update_interface_detail_of_device(self, device_to_update):
self.status = "success"
is_update_occurred = True
self.msg = "Successfully updated the Interface Details for device '{0}'.".format(device_ip)
self.result['response'] = self.msg
response_list.append(self.msg)
self.log(self.msg, "INFO")
break
elif execution_details.get("isError"):
Expand All @@ -2675,9 +2677,10 @@ def update_interface_detail_of_device(self, device_to_update):
self.result['changed'] = False
self.msg = "Port actions are only supported on user facing/access ports as it's not allowed or No Updation required"
self.log(self.msg, "INFO")
self.result['response'] = self.msg
response_list.append(self.msg)

self.result['changed'] = is_update_occurred
self.result['response'] = response_list

return self

Expand Down Expand Up @@ -2968,7 +2971,8 @@ def get_diff_merged(self, config):
device_params.pop('snmpPrivPassphrase', None)
device_params.pop('snmpPrivProtocol', None)

self.mandatory_parameter().check_return_status()
device_to_add_in_ccc = device_params['ipAddress']
self.mandatory_parameter(device_to_add_in_ccc).check_return_status()
try:
response = self.dnac._exec(
family="devices",
Expand Down

0 comments on commit a0d7eaa

Please sign in to comment.