Skip to content

Commit

Permalink
Fixed ansible sanity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mmudigon committed Dec 12, 2023
1 parent 4f8d638 commit 465846c
Show file tree
Hide file tree
Showing 15 changed files with 3,002 additions and 2 deletions.
12 changes: 12 additions & 0 deletions plugins/httpapi/dcnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def get_version(self):
def set_version(self, version):
self.version = version

def set_token(self, token):
self.token = token

def get_token(self):
return self.token

def _login_old(self, username, password, method, path):
"""DCNM Helper Function to login to DCNM version 11."""
# Ansible expresses the persistent_connect_timeout in seconds.
Expand All @@ -88,6 +94,7 @@ def _login_old(self, username, password, method, path):
}
self.login_succeeded = True
self.set_version(11)
self.set_token(self.connection._auth)

except Exception as e:
self.login_fail_msg.append(
Expand Down Expand Up @@ -124,6 +131,7 @@ def _login_latestv1(self, username, password, login_domain, method, path):
}
self.login_succeeded = True
self.set_version(12)
self.set_token(self.connection._auth)

except Exception as e:
self.login_fail_msg.append(
Expand Down Expand Up @@ -160,6 +168,7 @@ def _login_latestv2(self, username, password, login_domain, method, path):
}
self.login_succeeded = True
self.set_version(12)
self.set_token(self.connection._auth)

except Exception as e:
self.login_fail_msg.append(
Expand Down Expand Up @@ -275,6 +284,9 @@ def check_url_connection(self):
)
raise ConnectionError(str(e) + msg)

def get_url_connection(self):
return self.connection._url

def send_request(self, method, path, json=None):
"""This method handles all DCNM REST API requests other then login"""

Expand Down
40 changes: 38 additions & 2 deletions plugins/module_utils/network/dcnm/dcnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
from ansible.module_utils.common import validation
from ansible.module_utils.connection import Connection

# Any third party module must be imported as shown. If not ansible sanity tests will fail
try:
import requests
HAS_REQUESTS = True
except ImportError:
HAS_REQUESTS = False


def validate_ip_address_format(type, item, invalid_params):

Expand Down Expand Up @@ -386,7 +393,7 @@ def dcnm_reset_connection(module):

conn = Connection(module._socket_path)

conn.logout()
# conn.logout()
return conn.login(
conn.get_option("remote_user"), conn.get_option("password")
)
Expand Down Expand Up @@ -429,7 +436,7 @@ def dcnm_version_supported(module):
supported = int(mo.group(1))

if supported is None:
msg = "Unable to determine the DCNM/NDFC Software Version"
msg = "Unable to determine the DCNM/NDFC Software Version, " + "RESP = " + str(response)
module.fail_json(msg=msg)

return supported
Expand Down Expand Up @@ -517,3 +524,32 @@ def dcnm_get_url(module, fabric, path, items, module_name):
iter += 1

return attach_objects


def dcnm_get_protocol_and_address(module):

conn = Connection(module._socket_path)

url_prefix = conn.get_url_connection()
split_url = url_prefix.split(":")

return [split_url[0], split_url[1]]


def dcnm_get_auth_token(module):

conn = Connection(module._socket_path)
return (conn.get_token())


def dcnm_post_request(path, hdrs, verify_flag, upload_files):

resp = requests.post(path, headers=hdrs, verify=verify_flag, files=upload_files)
json_resp = resp.json()
if json_resp:
json_resp["RETURN_CODE"] = resp.status_code
json_resp["DATA"] = json_resp["message"]
json_resp["METHOD"] = "POST"
json_resp["REQUEST_PATH"] = path
json_resp.pop("message")
return json_resp
Loading

0 comments on commit 465846c

Please sign in to comment.