diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-26 04:06:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-26 04:06:02 +0000 |
commit | e3eb94c23206603103f3c4faec6c227f59a1544c (patch) | |
tree | f2639459807ba88f55fc9c54d745bd7075d7f15c /ansible_collections/cisco/dnac/plugins/module_utils | |
parent | Releasing progress-linux version 9.4.0+dfsg-1~progress7.99u1. (diff) | |
download | ansible-e3eb94c23206603103f3c4faec6c227f59a1544c.tar.xz ansible-e3eb94c23206603103f3c4faec6c227f59a1544c.zip |
Merging upstream version 9.5.1+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/cisco/dnac/plugins/module_utils')
-rw-r--r-- | ansible_collections/cisco/dnac/plugins/module_utils/dnac.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ansible_collections/cisco/dnac/plugins/module_utils/dnac.py b/ansible_collections/cisco/dnac/plugins/module_utils/dnac.py index a12e7eaf4..1d4b804cd 100644 --- a/ansible_collections/cisco/dnac/plugins/module_utils/dnac.py +++ b/ansible_collections/cisco/dnac/plugins/module_utils/dnac.py @@ -27,6 +27,7 @@ import json # import datetime import inspect import re +import socket class DnacBase(): @@ -485,6 +486,66 @@ class DnacBase(): return new_config + def is_valid_ipv4(self, ip_address): + """ + Validates an IPv4 address. + + Parameters: + ip_address - String denoting the IPv4 address passed. + + Returns: + bool - Returns true if the passed IP address value is correct or it returns + false if it is incorrect + """ + + try: + socket.inet_aton(ip_address) + octets = ip_address.split('.') + if len(octets) != 4: + return False + for octet in octets: + if not 0 <= int(octet) <= 255: + return False + return True + except socket.error: + return False + + def is_path_exists(self, file_path): + """ + Check if the file path 'file_path' exists or not. + + Parameters: + file_path (string) - Path of the provided file. + + Returns: + True/False (bool) - True if the file path exists, else False. + """ + + if not os.path.exists(file_path): + return False + + return True + + def is_json(self, file_path): + """ + Check if the file in the file path is JSON or not. + + Parameters: + file_path (string) - Path of the provided file. + + Returns: + True/False (bool) - True if the file is in JSON format, else False. + """ + + try: + with open(file_path, 'r') as file: + json.load(file) + return True + + except (ValueError, FileNotFoundError): + self.log("The provided file '{0}' is not in JSON format".format(file_path), "CRITICAL") + return False + def is_list_complex(x): return isinstance(x[0], dict) or isinstance(x[0], list) |