Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mapledyne/skytap
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
  • Loading branch information
thewellington committed Jan 10, 2017
2 parents bf52701 + b1b235c commit 8792ecf
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -12,5 +12,5 @@ _build/
_static/
_templates/
tests/testHierarchy.py
.env
/build
/.env
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -5,7 +5,7 @@
setup(
name='skytap',
packages=find_packages(),
version='1.3.1',
version='1.4.0',
description='Skytap REST API access modules',
author='Bill Wellington, Michael Knowles, and Caleb Hawkins',
test_suite='nose.collector',
Expand All @@ -16,7 +16,7 @@
install_requires=['requests', 'six'],
scripts=['bin/skytap'],
url='https://github.com/mapledyne/skytap',
download_url='https://github.com/mapledyne/skytap/tarball/v1.2.0',
download_url='https://github.com/mapledyne/skytap/tarball/v1.4.0',
keywords=['skytap', 'cloud', 'client', 'rest', 'api', 'development'],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
58 changes: 58 additions & 0 deletions skytap/Exports.py
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,61 @@ 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

if isinstance(job, Export):
if job.id not in self.data:
raise KeyError
target_id = job.id
elif isinstance(job, int):
if job not in self.data:
raise KeyError
target_id = job
else:
raise KeyError

# or maybe should raise a KeyError?
# We'll only get here if somehow we didn't set target
if target_id == 0:
return false

self.data[target_id].delete()
self.refresh()
return target_id not in self.data


if __name__ == '__main__':
print(Exports().main(sys.argv[1:]))
6 changes: 5 additions & 1 deletion skytap/framework/ApiClient.py
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
14 changes: 14 additions & 0 deletions skytap/models/Export.py
@@ -1,4 +1,8 @@
"""Support for Skytap VM Exports."""
import json

from skytap.framework.ApiClient import ApiClient
import skytap.framework.Utils as Utils
from skytap.models.SkytapResource import SkytapResource


Expand All @@ -8,3 +12,13 @@ class Export(SkytapResource):
def __init__(self, export_json):
"""Create one Export object."""
super(Export, self).__init__(export_json)
self.url = '/v2/exports/' + str(self.id)

def delete(self):
"""Delete this export job."""
Utils.info('Deleting job ' + str(self.id) + ' from queue.')
api = ApiClient()
response = api.rest(self.url,
{},
'DELETE')
return response

0 comments on commit 8792ecf

Please sign in to comment.