Skip to content

Commit

Permalink
[ignore] move proposed and output_path logic for aci_rest from aci.py…
Browse files Browse the repository at this point in the history
… to the aci_rest module
  • Loading branch information
akinross authored and lhercot committed Sep 28, 2023
1 parent f57d32a commit cc180dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
15 changes: 0 additions & 15 deletions plugins/module_utils/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,6 @@ def exit_json(self, filter_existing=None, **kwargs):
self.result["sent"] = self.config
self.result["proposed"] = self.proposed

elif self.__class__.__name__ == "ACIRESTModule" and self.method != "GET":
self.result["proposed"] = self.proposed

self.dump_json()
self.result.update(**kwargs)
self.module.exit_json(**self.result)
Expand Down Expand Up @@ -1489,9 +1486,6 @@ def fail_json(self, msg, **kwargs):
self.result["sent"] = self.config
self.result["proposed"] = self.proposed

elif self.__class__.__name__ == "ACIRESTModule" and self.method != "GET":
self.result["proposed"] = self.proposed

self.result.update(**kwargs)
self.module.fail_json(msg=msg, **self.result)

Expand Down Expand Up @@ -1520,15 +1514,6 @@ def dump_json(self):
if self.result.get("changed") is True:
json.dump([mo], output_file)

elif self.__class__.__name__ == "ACIRESTModule" and self.method != "GET":
output_path = self.params.get("output_path")
if output_path is not None:
with open(output_path, "a") as output_file:
if self.module.check_mode:
json.dump([self.proposed], output_file)
else:
output_file.write(str(self.proposed))

def parsed_url_path(self, url):
if not HAS_URLPARSE:
self.fail_json(msg="urlparse is not installed")
Expand Down
18 changes: 14 additions & 4 deletions plugins/modules/aci_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,21 @@ def main():
# Set changed to true so check_mode changed result is behaving similar to non aci_rest modules
aci.result["changed"] = True

if payload:
# Only set proposed if we have a payload and thus also only allow output_path if we have a payload
# DELETE and GET do not have a payload
if payload and method == "POST":
if rest_type == "json":
aci.proposed = json.loads(payload)
elif rest_type == "xml":
aci.proposed = payload
payload = json.loads(payload)

aci.result["proposed"] = payload

output_path = aci.params.get("output_path")
if output_path is not None:
with open(output_path, "a") as output_file:
if aci.module.check_mode:
json.dump([payload], output_file)
else:
output_file.write(str(payload))

# Report success
aci.exit_json(**aci.result)
Expand Down

0 comments on commit cc180dd

Please sign in to comment.