-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
plugins/module_utils/dnac.py
Outdated
@@ -485,6 +486,30 @@ def update_site_type_key(self, config): | |||
|
|||
return new_config | |||
|
|||
def is_valid_ip(self, ip_address): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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..
plugins/modules/discovery_intent.py
Outdated
@@ -721,6 +721,43 @@ def validate_input(self, state=None): | |||
self.status = "success" | |||
return self | |||
|
|||
def validate_ip_address_list(self): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
plugins/modules/discovery_intent.py
Outdated
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" |
There was a problem hiding this comment.
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...)
plugins/modules/discovery_intent.py
Outdated
self.log(msg, "CRITICAL") | ||
self.module.fail_json(msg=msg) | ||
else: | ||
msg = "IP address range should have only upper and lower limit values" |
There was a problem hiding this comment.
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)
plugins/modules/discovery_intent.py
Outdated
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") |
There was a problem hiding this comment.
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
…y and event subscription modules.'
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)