Skip to content

Commit 3517143

Browse files
akinrosslhercot
authored andcommitted
[ignore] restructure code of aci_config_snapshot for code coverage improvement and introduction of base_url property to aci class for reuse of protocol/host with optional port combination
1 parent 00c90bb commit 3517143

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

plugins/module_utils/aci.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ def __init__(self, module):
361361
self.module.warn("Enable debug output because ANSIBLE_DEBUG was set.")
362362
self.params["output_level"] = "debug"
363363

364+
if self.params.get("port") is not None:
365+
self.base_url = "{protocol}://{host}:{port}".format_map(self.params)
366+
else:
367+
self.base_url = "{protocol}://{host}".format_map(self.params)
368+
364369
if self.params.get("private_key"):
365370
# Perform signature-based authentication, no need to log on separately
366371
if not HAS_CRYPTOGRAPHY and not HAS_OPENSSL:
@@ -415,10 +420,7 @@ def login(self):
415420
"""Log in to APIC"""
416421

417422
# Perform login request
418-
if self.params.get("port") is not None:
419-
url = "{protocol}://{host}:{port}/api/aaaLogin.json".format_map(self.params)
420-
else:
421-
url = "{protocol}://{host}/api/aaaLogin.json".format_map(self.params)
423+
url = "{0}/api/aaaLogin.json".format(self.base_url)
422424
payload = {
423425
"aaaUser": {
424426
"attributes": {

plugins/modules/aci_config_snapshot.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@
227227
sample: https://10.11.12.13/api/mo/uni/tn-production.json
228228
"""
229229

230-
import json
231-
232230
from ansible.module_utils.basic import AnsibleModule
233231
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
234232

@@ -304,18 +302,9 @@ def main():
304302
aci.post_config()
305303

306304
# Query for job information and add to results
307-
path = "/api/node/mo/uni/backupst/jobs-[uni/fabric/configexp-{0}].json".format(export_policy)
308-
if "port" in aci.params and aci.params.get("port") is not None:
309-
port_url = "{protocol}://{host}:{port}/".format_map(aci.params) + path.lstrip("/")
310-
else:
311-
port_url = "{protocol}://{host}/".format_map(aci.params) + path.lstrip("/")
312-
resp, info = aci.api_call("GET", port_url, data=None, return_response=True)
313-
try:
314-
aci.imdata = json.loads(resp.read())["imdata"]
315-
except AttributeError:
316-
aci.imdata = json.loads(info.get("body"))["imdata"]
317-
318-
aci.result["job_details"] = aci.imdata[0].get("configJobCont", {})
305+
path = "api/node/mo/uni/backupst/jobs-[uni/fabric/configexp-{0}].json".format(export_policy)
306+
aci.api_call("GET", url="{0}/{1}".format(aci.base_url, path))
307+
aci.result["job_details"] = aci.existing[0].get("configJobCont", {})
319308
# Reset state and url to display correct in output and trigger get_existing() function with correct url
320309
aci.url = reset_url
321310

0 commit comments

Comments
 (0)