Skip to content

Commit

Permalink
getting back http response codes
Browse files Browse the repository at this point in the history
This was Michael’s work — she should get credit for this commit.
  • Loading branch information
thewellington committed Jan 5, 2017
1 parent 1f0f6fe commit 8f37ac1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
34 changes: 34 additions & 0 deletions skytap/Exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
return a list of current Exports from Skytap in a JSON format.
"""
import sys
import json

from skytap.framework.ApiClient import ApiClient
import skytap.framework.Utils as Utils
from skytap.models.SkytapGroup import SkytapGroup
from skytap.models.Export import Export

Expand All @@ -25,6 +28,37 @@ def __init__(self):
super(Exports, self).__init__()
self.load_list_from_api('/v2/exports', Export)

def create(self, vmid):
"""Create an export job
Args:
vm_id (int):
Returns:
Example:
.. code-block:: python
"""
if type(vmid) is not int:
raise TypeError('vmid must be an int')

Utils.info('creating export job for VM ' + str(vmid))
api = ApiClient()
data = {"vm_id": vmid}
url = self.url + '.json'
response = api.rest(url, data, "POST")
exports = json.loads(response)
self.refresh()
if 'id' in exports:
return int(exports['id'])
Utils.warning('Trying to create new export job from VM ' + vmid +
', but got an unexpected response from Skytap. ' +
'Response:\n' + response)
return 0

def delete(self, job):
"""Delete an Export job."""
target_id = 0
Expand Down
6 changes: 5 additions & 1 deletion skytap/framework/ApiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def _check_response(self, resp, attempts=1):
# If we made it this far, we need to handle an exception
if attempts >= Config.max_http_attempts or (resp.status_code != 429 and
resp.status_code != 423):
raise Exception(json.loads(resp.text))
Utils.error('Error recieved in API return. Response code: ' + str(resp.status_code) + '. Reponse text: ' + resp.text)
# print(resp.headers)
error_response = json.loads(resp.text)
error_response['status_code'] = resp.status_code
raise Exception(error_response)

if resp.status_code == 423: # "Busy"
if 'Retry-After' in resp.headers:
Expand Down

0 comments on commit 8f37ac1

Please sign in to comment.