Meraki modules - Added support for checking HTTP response codes (#42144)

* Added support for checking HTTP response codes
- All request calls now check for response code before responding
- If the response code isn't what it should be, it fails or returns nothing
- Breaking this into multiple PRs to make backporting easier
- Using status property in Meraki module utility which has the code

* Change logic of HTTP checks so success is default
This commit is contained in:
Kevin Breit 2018-07-02 21:24:06 -05:00 committed by Dag Wieers
commit 40b9862d38
5 changed files with 52 additions and 29 deletions

View file

@ -150,7 +150,10 @@ class MerakiModule(object):
def get_orgs(self):
"""Downloads all organizations for a user."""
return self.request('/organizations', method='GET')
response = self.request('/organizations', method='GET')
if self.status != 200:
self.fail_json(msg='Organization lookup failed')
return response
def is_org_valid(self, data, org_name=None, org_id=None):
"""Checks whether a specific org exists and is duplicated.
@ -195,6 +198,8 @@ class MerakiModule(object):
org_id = self.get_org_id(org_name)
path = self.construct_path('get_all', org_id=org_id, function='network')
r = self.request(path, method='GET')
if self.status != 200:
self.fail_json(msg='Network lookup failed')
return r
def get_net(self, org_name, net_name, data=None):