ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 16 | from oslo_serialization import jsonutils as json |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 17 | import six |
Matthew Treinish | 8912814 | 2015-04-23 10:44:30 -0400 | [diff] [blame] | 18 | from six.moves.urllib import parse as urllib |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 19 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 20 | from tempest.common import service_client |
Ken'ichi Ohmichi | b942be6 | 2015-07-08 08:16:12 +0000 | [diff] [blame] | 21 | from tempest.common import waiters |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame^] | 22 | from tempest.lib import exceptions as lib_exc |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 23 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 24 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 25 | class BaseVolumesClient(service_client.ServiceClient): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 26 | """Base client class to send CRUD Volume API requests""" |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 27 | |
Ken'ichi Ohmichi | a39d0be | 2014-12-17 08:46:11 +0000 | [diff] [blame] | 28 | create_resp = 200 |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 29 | |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 30 | def __init__(self, auth_provider, service, region, |
| 31 | default_volume_size=1, **kwargs): |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 32 | super(BaseVolumesClient, self).__init__( |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 33 | auth_provider, service, region, **kwargs) |
| 34 | self.default_volume_size = default_volume_size |
| 35 | |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 36 | def get_attachment_from_volume(self, volume): |
| 37 | """Return the element 'attachment' from input volumes.""" |
| 38 | return volume['attachments'][0] |
| 39 | |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 40 | def _prepare_params(self, params): |
| 41 | """Prepares params for use in get or _ext_get methods. |
| 42 | |
| 43 | If params is a string it will be left as it is, but if it's not it will |
| 44 | be urlencoded. |
| 45 | """ |
| 46 | if isinstance(params, six.string_types): |
| 47 | return params |
| 48 | return urllib.urlencode(params) |
| 49 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 50 | def list_volumes(self, detail=False, params=None): |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 51 | """List all the volumes created. |
| 52 | |
| 53 | Params can be a string (must be urlencoded) or a dictionary. |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 54 | """ |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 55 | url = 'volumes' |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 56 | if detail: |
| 57 | url += '/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 58 | if params: |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 59 | url += '?%s' % self._prepare_params(params) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 60 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 61 | resp, body = self.get(url) |
| 62 | body = json.loads(body) |
| 63 | self.expected_success(200, resp.status) |
| 64 | return service_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 65 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 66 | def show_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 67 | """Returns the details of a single volume.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 68 | url = "volumes/%s" % str(volume_id) |
Attila Fazekas | b8aa759 | 2013-01-26 01:25:45 +0100 | [diff] [blame] | 69 | resp, body = self.get(url) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 70 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 71 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 72 | return service_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 73 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 74 | def create_volume(self, **kwargs): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 75 | """Creates a new Volume. |
| 76 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 77 | Available params: see http://developer.openstack.org/ |
| 78 | api-ref-blockstorage-v2.html#createVolume |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 79 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 80 | if 'size' not in kwargs: |
| 81 | kwargs['size'] = self.default_volume_size |
| 82 | post_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 83 | resp, body = self.post('volumes', post_body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 84 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 85 | self.expected_success(self.create_resp, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 86 | return service_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 87 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 88 | def update_volume(self, volume_id, **kwargs): |
| 89 | """Updates the Specified Volume.""" |
| 90 | put_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 91 | resp, body = self.put('volumes/%s' % volume_id, put_body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 92 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 93 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 94 | return service_client.ResponseBody(resp, body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 95 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 96 | def delete_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 97 | """Deletes the Specified Volume.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 98 | resp, body = self.delete("volumes/%s" % str(volume_id)) |
| 99 | self.expected_success(202, resp.status) |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 100 | return service_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 101 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 102 | def upload_volume(self, volume_id, **kwargs): |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 103 | """Uploads a volume in Glance.""" |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 104 | post_body = json.dumps({'os-volume_upload_image': kwargs}) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 105 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 106 | resp, body = self.post(url, post_body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 107 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 108 | self.expected_success(202, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 109 | return service_client.ResponseBody(resp, body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 110 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 111 | def attach_volume(self, volume_id, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 112 | """Attaches a volume to a given instance on a given mountpoint.""" |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 113 | post_body = json.dumps({'os-attach': kwargs}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 114 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 115 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 116 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 117 | return service_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 118 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 119 | def set_bootable_volume(self, volume_id, **kwargs): |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 120 | """set a bootable flag for a volume - true or false.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 121 | post_body = json.dumps({'os-set_bootable': kwargs}) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 122 | url = 'volumes/%s/action' % (volume_id) |
| 123 | resp, body = self.post(url, post_body) |
| 124 | self.expected_success(200, resp.status) |
| 125 | return service_client.ResponseBody(resp, body) |
| 126 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 127 | def detach_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 128 | """Detaches a volume from an instance.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 129 | post_body = json.dumps({'os-detach': {}}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 130 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 131 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 132 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 133 | return service_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 134 | |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 135 | def reserve_volume(self, volume_id): |
| 136 | """Reserves a volume.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 137 | post_body = json.dumps({'os-reserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 138 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 139 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 140 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 141 | return service_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 142 | |
| 143 | def unreserve_volume(self, volume_id): |
| 144 | """Restore a reserved volume .""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 145 | post_body = json.dumps({'os-unreserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 146 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 147 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 148 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 149 | return service_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 150 | |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 151 | def wait_for_volume_status(self, volume_id, status): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 152 | """Waits for a Volume to reach a given status.""" |
Ken'ichi Ohmichi | b942be6 | 2015-07-08 08:16:12 +0000 | [diff] [blame] | 153 | waiters.wait_for_volume_status(self, volume_id, status) |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 154 | |
| 155 | def is_resource_deleted(self, id): |
| 156 | try: |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 157 | self.show_volume(id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 158 | except lib_exc.NotFound: |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 159 | return True |
| 160 | return False |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 161 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 162 | @property |
| 163 | def resource_type(self): |
| 164 | """Returns the primary type of resource this client works with.""" |
| 165 | return 'volume' |
| 166 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 167 | def extend_volume(self, volume_id, **kwargs): |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 168 | """Extend a volume.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 169 | post_body = json.dumps({'os-extend': kwargs}) |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 170 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 171 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 172 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 173 | return service_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 174 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 175 | def reset_volume_status(self, volume_id, **kwargs): |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 176 | """Reset the Specified Volume's Status.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 177 | post_body = json.dumps({'os-reset_status': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 178 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 179 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 180 | return service_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 181 | |
| 182 | def volume_begin_detaching(self, volume_id): |
| 183 | """Volume Begin Detaching.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 184 | # ref cinder/api/contrib/volume_actions.py#L158 |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 185 | post_body = json.dumps({'os-begin_detaching': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 186 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 187 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 188 | return service_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 189 | |
| 190 | def volume_roll_detaching(self, volume_id): |
| 191 | """Volume Roll Detaching.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 192 | # cinder/api/contrib/volume_actions.py#L170 |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 193 | post_body = json.dumps({'os-roll_detaching': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 194 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 195 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 196 | return service_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 197 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 198 | def create_volume_transfer(self, **kwargs): |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 199 | """Create a volume transfer.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 200 | post_body = json.dumps({'transfer': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 201 | resp, body = self.post('os-volume-transfer', post_body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 202 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 203 | self.expected_success(202, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 204 | return service_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 205 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 206 | def show_volume_transfer(self, transfer_id): |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 207 | """Returns the details of a volume transfer.""" |
| 208 | url = "os-volume-transfer/%s" % str(transfer_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 209 | resp, body = self.get(url) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 210 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 211 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 212 | return service_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 213 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 214 | def list_volume_transfers(self, **params): |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 215 | """List all the volume transfers created.""" |
| 216 | url = 'os-volume-transfer' |
| 217 | if params: |
| 218 | url += '?%s' % urllib.urlencode(params) |
| 219 | resp, body = self.get(url) |
| 220 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 221 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 222 | return service_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 223 | |
| 224 | def delete_volume_transfer(self, transfer_id): |
| 225 | """Delete a volume transfer.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 226 | resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id)) |
| 227 | self.expected_success(202, resp.status) |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 228 | return service_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 229 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 230 | def accept_volume_transfer(self, transfer_id, **kwargs): |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 231 | """Accept a volume transfer.""" |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 232 | url = 'os-volume-transfer/%s/accept' % transfer_id |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 233 | post_body = json.dumps({'accept': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 234 | resp, body = self.post(url, post_body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 235 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 236 | self.expected_success(202, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 237 | return service_client.ResponseBody(resp, body) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 238 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 239 | def update_volume_readonly(self, volume_id, **kwargs): |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 240 | """Update the Specified Volume readonly.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 241 | post_body = json.dumps({'os-update_readonly_flag': kwargs}) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 242 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 243 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 244 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 245 | return service_client.ResponseBody(resp, body) |
wanghao | 9d3d6cb | 2013-11-12 15:10:10 +0800 | [diff] [blame] | 246 | |
| 247 | def force_delete_volume(self, volume_id): |
| 248 | """Force Delete Volume.""" |
| 249 | post_body = json.dumps({'os-force_delete': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 250 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 251 | self.expected_success(202, resp.status) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 252 | return service_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 253 | |
| 254 | def create_volume_metadata(self, volume_id, metadata): |
| 255 | """Create metadata for the volume.""" |
| 256 | put_body = json.dumps({'metadata': metadata}) |
| 257 | url = "volumes/%s/metadata" % str(volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 258 | resp, body = self.post(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 259 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 260 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 261 | return service_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 262 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 263 | def show_volume_metadata(self, volume_id): |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 264 | """Get metadata of the volume.""" |
| 265 | url = "volumes/%s/metadata" % str(volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 266 | resp, body = self.get(url) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 267 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 268 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 269 | return service_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 270 | |
| 271 | def update_volume_metadata(self, volume_id, metadata): |
| 272 | """Update metadata for the volume.""" |
| 273 | put_body = json.dumps({'metadata': metadata}) |
| 274 | url = "volumes/%s/metadata" % str(volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 275 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 276 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 277 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 278 | return service_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 279 | |
| 280 | def update_volume_metadata_item(self, volume_id, id, meta_item): |
| 281 | """Update metadata item for the volume.""" |
| 282 | put_body = json.dumps({'meta': meta_item}) |
| 283 | url = "volumes/%s/metadata/%s" % (str(volume_id), str(id)) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 284 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 285 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 286 | self.expected_success(200, resp.status) |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 287 | return service_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 288 | |
| 289 | def delete_volume_metadata_item(self, volume_id, id): |
| 290 | """Delete metadata item for the volume.""" |
| 291 | url = "volumes/%s/metadata/%s" % (str(volume_id), str(id)) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 292 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 293 | self.expected_success(200, resp.status) |
Joseph Lanoux | 2cdd550 | 2015-01-16 14:46:51 +0000 | [diff] [blame] | 294 | return service_client.ResponseBody(resp, body) |
Zhi Kun Liu | 6e6cf83 | 2014-05-08 17:25:22 +0800 | [diff] [blame] | 295 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 296 | def retype_volume(self, volume_id, **kwargs): |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 297 | """Updates volume with new volume type.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 298 | post_body = json.dumps({'os-retype': kwargs}) |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 299 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 300 | self.expected_success(202, resp.status) |