diff --git a/skytap/Exports.py b/skytap/Exports.py index 12e1080..ee31116 100644 --- a/skytap/Exports.py +++ b/skytap/Exports.py @@ -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 @@ -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 diff --git a/skytap/framework/ApiClient.py b/skytap/framework/ApiClient.py index b40aafa..5c9683c 100644 --- a/skytap/framework/ApiClient.py +++ b/skytap/framework/ApiClient.py @@ -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: