Skip to content

Commit

Permalink
Add early check of status for SDA modules
Browse files Browse the repository at this point in the history
  • Loading branch information
William Astorga committed Feb 12, 2022
1 parent a3f612c commit dc1dd07
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 26 deletions.
13 changes: 11 additions & 2 deletions plugins/action/sda_fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -138,6 +139,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -204,8 +210,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_fabric_authentication_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -144,6 +145,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def update(self):
Expand Down Expand Up @@ -226,8 +232,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))

elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_fabric_border_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -145,6 +146,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -211,8 +217,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_fabric_control_plane_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -139,6 +140,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -205,8 +211,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_fabric_edge_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -139,6 +140,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -205,8 +211,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_fabric_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -139,6 +140,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -205,8 +211,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_multicast.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -142,6 +143,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -205,8 +211,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_port_assignment_for_access_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -148,6 +149,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -214,8 +220,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_port_assignment_for_user_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -148,6 +149,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -214,8 +220,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
14 changes: 12 additions & 2 deletions plugins/action/sda_provision_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -134,6 +135,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -197,8 +203,12 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))

elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
13 changes: 11 additions & 2 deletions plugins/action/sda_virtual_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from ansible_collections.cisco.dnac.plugins.plugin_utils.exceptions import (
InconsistentParameters,
AnsibleSDAException,
)

# Get common arguments specification
Expand Down Expand Up @@ -144,6 +145,11 @@ def create(self):
params=self.create_params(),
op_modifies=True,
)
if isinstance(result, dict):
if 'response' in result:
result = result.get('response')
if isinstance(result, dict) and result.get("status") == "failed":
raise AnsibleSDAException(response=result)
return result

def delete(self):
Expand Down Expand Up @@ -210,8 +216,11 @@ def run(self, tmp=None, task_vars=None):
response = prev_obj
dnac.object_already_present()
else:
response = obj.create()
dnac.object_created()
try:
response = obj.create()
dnac.object_created()
except AnsibleSDAException as e:
dnac.fail_json("Could not create object {e}".format(e=e._response))
elif state == "absent":
(obj_exists, prev_obj) = obj.exists()
if obj_exists:
Expand Down
Loading

0 comments on commit dc1dd07

Please sign in to comment.