Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing dnac_log_level from code along with fixing is… #127

Merged
merged 3 commits into from
Feb 1, 2024

Conversation

abimishr
Copy link
Collaborator

@abimishr abimishr commented Feb 1, 2024

Problem description: Discovery can't take more than 5 CLI credentials. Along with that, we haven't covered range based discovery.
Fix: Now the customer has the option to add the number of CLI credentials to be added. We have changed the IP address list input method.
Test cases: Tested for CDP, LLDP, MULTI RANGE and SINGLE RANGE
Limitation: Deletion is not tested

@abimishr abimishr changed the title Removing config_verify, dnac_log_level from code along with fixing is… Removing dnac_log_level from code along with fixing is… Feb 1, 2024
timeout:
description: Time to wait for device response in seconds
type: int
cli_cred_len:
description: Total CLI credentials that needs to be used. This value can vary from 1 to 5.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description: Specifies the total number of CLI credentials to be used, ranging from 1 to 5.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

return devices_list
ip_address_list = self.validated_config[0].get('ip_address_list')
self.result.update(dict(devices_info=ip_address_list))
self.log("Devices list info passed: {0}".format(str(ip_address_list)), "INFO")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we. say

self.log("Details of the device list passed: {0}".format(str(ip_address_list)), "INFO")  (OR)
self.log("Information about the list of devices passed: {0}".format(str(ip_address_list)), "INFO")

"""
Preprocess the devices' information. Extract the IP addresses from
the list of devices and perform additional processing based on the
'discovery_type' in the validated configuration.

Parameters:
- devices_list: The list of devices to preprocess. If not
- ip_address_list: The list of devices to preprocess. If not
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we meant to say
" the list of devices' IP addresses intended for preprocessing" ?

ip_address_list: The list of devices' IP addresses intended for preprocessing. If not provided, an empty list will be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah
It is resolved now


self.log("Discovery type passed for the discovery is {0}".format(self.validated_config[0].get('discovery_type')), "INFO")
if self.validated_config[0].get('discovery_type') in ["SINGLE", "CDP", "LLDP"]:
if len(ip_address_list) == 1:
ip_address_list = ip_address_list[0]
else:
self.log("Device list's length is longer than 1", "ERROR")
self.module.fail_json(msg="Device list's length is longer than 1", response=[])
self.log("IP Address list's length is longer than 1", "ERROR")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.log("The length of the IP address list is greater than 1", "ERROR")
greater or longer than 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

elif self.validated_config[0].get('discovery_type') == "CIDR":
if len(ip_address_list) == 1 and self.validated_config[0].get('prefix_length'):
ip_address_list = ip_address_list[0]
ip_address_list = str(ip_address_list) + "/" + str(self.validated_config[0].get('prefix_length'))
else:
self.log("Device list's length is longer than 1", "ERROR")
self.module.fail_json(msg="Device list's length is longer than 1", response=[])
self.log("IP Address list's length is longer than 1", "ERROR")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.log("The length of the IP address list is greater than 1", "ERROR")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved


ip_address_list = [device['ip'] for device in devices_list]
if ip_address_list is None:
ip_address_list = []

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can get and store discovery_type as we use many places.. self.validated_config[0].get('discovery_type')

  discovery_type = self.validated_config[0].get('discovery_type')
   self.log(f"Discovery type: {discovery_type}", "INFO")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved


def preprocessing_devices_info(self, devices_list=None):
def preprocessing_devices_info(self, ip_address_list=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name the function like preprocess_device_discovery?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

ip_address_list = ip_address_list[0]
else:
ip_address_list = "{0}-{1}".format(ip_address_list[0], ip_address_list[0])
else:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these error messages are repeated for more than 3 times. Can we write an API and simplify it?
def preprocess_device_discovery_handle_error(self):
self.log("IP Address list's length is longer than 1", "ERROR")
self.module.fail_json(msg="IP Address list's length is longer than 1", response=[])

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

ip_address_list = "{0}-{1}".format(ip_address_list[0], ip_address_list[0])
else:
self.log("IP Address list's length is longer than 1", "ERROR")
self.module.fail_json(msg="IP Address list's length is longer than 1", response=[])
else:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As many lines are repeated in this API:

if discovery_type in ["SINGLE", "CDP", "LLDP"]:
    if len(ip_address_list) == 1: 
        processed_ip_addresses = ip_address_list[0] 
    else:
        self.handle_discovery_error()
elif discovery_type == "CIDR":
    processed_ip_addresses = self.process_discovery_cidr(ip_address_list)
elif discovery_type == "RANGE":
    processed_ip_addresses = self.process_discovery_range(ip_address_list)
else:
    processed_ip_addresses = self.process_discovery_other(ip_address_list)

self.log("Collected IP address/addresses are {0}".format(str(processed_ip_addresses)), "INFO")

And followed by the functions?

def handle_discovery_error(self):
    self.log("The length of the IP address list is longer than 1", "ERROR")
    self.module.fail_json(msg="he length of the IP address list is longer than 1", response=[])

def process_cidr(self, ip_address_list):
    if  len(ip_address_list) != 1:
                self.handle_discovery_error()
                return

    prefix_length = self.validated_config[0].get('prefix_length')
#check prefix length if required...
    return "{0}/{1}".format(ip_address_list[0], prefix_length))

Likewise you can write other APIs...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

elif self.validated_config[0].get('discovery_type') == "RANGE":
if len(ip_address_list) == 1:
if len(str(ip_address_list[0]).split("-")) == 2:
ip_address_list = ip_address_list[0]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we getting a list from a list?
or
ip_address = ip_address_list[0]

We can also simply write like:
ip = ip_list[0]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are actually fetching the data for performing the API call

@madhansansel madhansansel merged commit 1c75af9 into madhansansel:main Feb 1, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants