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

Adding method to check valid ip address #200

Merged
merged 4 commits into from
Mar 27, 2024

Conversation

abimishr
Copy link
Collaborator

@abimishr abimishr commented Mar 26, 2024

Problem description: Validity of IPv4 addresses are there on GUI. Similar check needs to be added in modules as well.
Fix: Have added a method in dnac.py file called is_valid_ip which takes an ip address as input and returns True if it is valid else it returns False. Have implemented the same in discovery module as well.
Test cases: Returned False for IP addresses like 204.1.1.900, 204.1.1.80-204.1.1.900, 204.1.1.80-204.1.1.79 (Reverse range is not allowed)

@@ -485,6 +486,30 @@ def update_site_type_key(self, config):

return new_config

def is_valid_ip(self, ip_address):
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 change into ipv4?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi I didn't keep the name IPv4 since we don't use ipv6 as internal ip address. Even on GUI we only use IPv4

"""

try:
socket.inet_aton(ip_address)
Copy link
Owner

Choose a reason for hiding this comment

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

Check if ip_address is Zero. If Zero then return with error message..

@@ -721,6 +721,43 @@ def validate_input(self, state=None):
self.status = "success"
return self

def validate_ip_address_list(self):
Copy link
Owner

Choose a reason for hiding this comment

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

is it validating ipv4 only?

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

ip2_parts = list(map(int, ip2.split('.')))
for part in range(4):
if ip1_parts[part] > ip2_parts[part]:
msg = "Incorrect range passed. Please pass correct IP address range"
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 print the range ?
msg = "Incorrect range passed: {0}. Please pass correct IP address range".format(ip_address...)

self.log(msg, "CRITICAL")
self.module.fail_json(msg=msg)
else:
msg = "IP address range should have only upper and lower limit values"
Copy link
Owner

Choose a reason for hiding this comment

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

What is the range? Can we print it?
msg = "Provided range '{0}' is incorrect. IP address range should have only upper and lower limit values".format(provided_range)

msg = "IP address {0} is not valid".format(ip)
self.log(msg, "CRITICAL")
self.module.fail_json(msg=msg)
self.log("All the IP adresses passed are correct", "INFO")
Copy link
Owner

Choose a reason for hiding this comment

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

All the IP addresses passed are correct

@madhansansel madhansansel merged commit 9586045 into madhansansel:main Mar 27, 2024
3 checks passed
md-rafeek pushed a commit to md-rafeek/madhan-dnacenter-ansible that referenced this pull request Nov 14, 2024
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