Skip to content

Commit b30b27e

Browse files
committed
Finish basic snapshot support
1 parent b6a48b9 commit b30b27e

9 files changed

+32
-9
lines changed

ec2stack/providers/cloudstack/snapshots.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def create_snapshot():
1717
1818
@return: Response.
1919
"""
20+
helpers.require_parameters(['VolumeId'])
2021
response = _create_snapshot_request()
2122
return _create_snapshot_response(response)
2223

@@ -27,7 +28,7 @@ def _create_snapshot_request():
2728
2829
@return: Response.
2930
"""
30-
args = {'command': 'createSnapshot'}
31+
args = {'command': 'createSnapshot', 'volumeid': helpers.get('VolumeId')}
3132

3233
response = requester.make_request_async(args)
3334

@@ -41,8 +42,11 @@ def _create_snapshot_response(response):
4142
@param response: Response from Cloudstack.
4243
@return: Response.
4344
"""
44-
45-
response = response['vmsnapshot']
45+
if 'errortext' in response:
46+
if 'Invalid parameter volumeid' in response['errortext']:
47+
errors.invalid_volume_id()
48+
else:
49+
response = response['snapshot']
4650
return {
4751
'template_name_or_list': 'create_snapshot.xml',
4852
'response_type': 'CreateSnapshotResponse',
@@ -58,8 +62,8 @@ def delete_snapshot():
5862
@return: Response.
5963
"""
6064
helpers.require_parameters(['SnapshotId'])
61-
_delete_snapshot_request()
62-
return _delete_snapshot_response()
65+
response = _delete_snapshot_request()
66+
return _delete_snapshot_response(response)
6367

6468

6569
def _delete_snapshot_request():
@@ -75,12 +79,15 @@ def _delete_snapshot_request():
7579
return response
7680

7781

78-
def _delete_snapshot_response():
82+
def _delete_snapshot_response(response):
7983
"""
8084
Generates a response for delete snapshot request.
8185
8286
@return: Response.
8387
"""
88+
if 'errortext' in response:
89+
if 'Invalid parameter id' in response['errortext']:
90+
errors.invalid_snapshot_id()
8491
return {
8592
'template_name_or_list': 'status.xml',
8693
'response_type': 'DeleteSnapshotResponse',

ec2stack/templates/snapshots.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "response.xml" %}
22
{% block response_content %}
33
<snapshotSet>
4-
{% for snapshot in response.vmsnapshot %}
4+
{% for snapshot in response.snapshot %}
55
<item>
66
<snapshotId>{{ snapshot.id }}</snapshotId>
77
<volumeId>{{ snapshot.volumeid }}</volumeId>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"createsnapshotresponse": {
3+
"errorcode": 431,
4+
"uuidlist": [],
5+
"cserrorcode": 9999,
6+
"errortext": "Unable to execute API command createsnapshot due to invalid value. Invalid parameter volumeid value=120a5425-6092-4700-baaf-600fcbaa10 due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class."
7+
}
8+
}
File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"deletesnapshotresponse": {
3+
"errorcode": 431,
4+
"uuidlist": [],
5+
"cserrorcode": 9999,
6+
"errortext": "Unable to execute API command deletesnapshot due to invalid value. Invalid parameter id value=abdb81fa-f4ac-4ec6-822c-34af7cd461 due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class."
7+
}
8+
}
File renamed without changes.

tests/data/invalid_describe_image_invalid_image_id.json renamed to tests/data/invalid_describe_image_image_not_found.json

File renamed without changes.

tests/data/invalid_describe_volume_invalid_instance_id.json renamed to tests/data/invalid_describe_volume_instance_not_found.json

File renamed without changes.

tests/tags_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_create_tag_resource_id_not_found(self):
7373

7474
get = mock.Mock()
7575
get.return_value.text = read_file(
76-
'tests/data/invalid_create_tag_invalid_id.json'
76+
'tests/data/invalid_create_tag_not_found.json'
7777
)
7878
get.return_value.status_code = 200
7979

@@ -145,7 +145,7 @@ def test_delete_tag_resource_id_not_found(self):
145145

146146
get = mock.Mock()
147147
get.return_value.text = read_file(
148-
'tests/data/invalid_delete_tag_invalid_tag_id.json'
148+
'tests/data/invalid_delete_tag_tag_not_found.json'
149149
)
150150
get.return_value.status_code = 200
151151

0 commit comments

Comments
 (0)