Raise clear exception when a given private cloud does not support a given api

This commit is contained in:
Madison May
2015-02-27 16:12:16 -05:00
parent e9fc025e95
commit 6dd0738a8b
+7 -3
View File
@@ -25,10 +25,14 @@ def api_handler(arg, cloud, api, batch=False, auth=None, **kwargs):
if not auth:
auth = config.AUTH
response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth).json()
results = response.get('results', False)
response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth)
if response.status_code == 503 and cloud != None:
raise Exception("Private cloud '%s' does not include api '%s'" % (cloud, api))
json_results = response.json()
results = json_results.get('results', False)
if results is False:
error = response.get('error')
error = json_results.get('error')
raise ValueError(error)
return results