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 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 20 | from tempest.lib.common import rest_client |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 21 | from tempest.lib import exceptions as lib_exc |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 22 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 23 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 24 | class BaseVolumesClient(rest_client.RestClient): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 25 | """Base client class to send CRUD Volume API requests""" |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 26 | |
Ken'ichi Ohmichi | a39d0be | 2014-12-17 08:46:11 +0000 | [diff] [blame] | 27 | create_resp = 200 |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 28 | |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 29 | def __init__(self, auth_provider, service, region, |
| 30 | default_volume_size=1, **kwargs): |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 31 | super(BaseVolumesClient, self).__init__( |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 32 | auth_provider, service, region, **kwargs) |
| 33 | self.default_volume_size = default_volume_size |
| 34 | |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 35 | def get_attachment_from_volume(self, volume): |
| 36 | """Return the element 'attachment' from input volumes.""" |
| 37 | return volume['attachments'][0] |
| 38 | |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 39 | def _prepare_params(self, params): |
| 40 | """Prepares params for use in get or _ext_get methods. |
| 41 | |
| 42 | If params is a string it will be left as it is, but if it's not it will |
| 43 | be urlencoded. |
| 44 | """ |
| 45 | if isinstance(params, six.string_types): |
| 46 | return params |
| 47 | return urllib.urlencode(params) |
| 48 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 49 | def list_volumes(self, detail=False, params=None): |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 50 | """List all the volumes created. |
| 51 | |
| 52 | Params can be a string (must be urlencoded) or a dictionary. |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 53 | """ |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 54 | url = 'volumes' |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 55 | if detail: |
| 56 | url += '/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 57 | if params: |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 58 | url += '?%s' % self._prepare_params(params) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 59 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 60 | resp, body = self.get(url) |
| 61 | body = json.loads(body) |
| 62 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 63 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 64 | |
bkopilov | 1f161e5 | 2016-04-18 13:27:48 +0300 | [diff] [blame] | 65 | def show_pools(self, detail=False): |
lkuchlan | b6baff8 | 2016-06-01 11:55:47 +0300 | [diff] [blame] | 66 | """List all the volumes pools (hosts). |
| 67 | |
| 68 | Output params: see http://developer.openstack.org/ |
| 69 | api-ref-blockstorage-v2.html#listPools |
| 70 | """ |
bkopilov | 1f161e5 | 2016-04-18 13:27:48 +0300 | [diff] [blame] | 71 | url = 'scheduler-stats/get_pools' |
| 72 | if detail: |
| 73 | url += '?detail=True' |
| 74 | |
| 75 | resp, body = self.get(url) |
| 76 | body = json.loads(body) |
| 77 | self.expected_success(200, resp.status) |
| 78 | return rest_client.ResponseBody(resp, body) |
| 79 | |
lkuchlan | b6baff8 | 2016-06-01 11:55:47 +0300 | [diff] [blame] | 80 | def show_backend_capabilities(self, host): |
| 81 | """Shows capabilities for a storage back end. |
| 82 | |
| 83 | Output params: see http://developer.openstack.org/ |
| 84 | api-ref-blockstorage-v2.html |
| 85 | #showBackendCapabilities |
| 86 | """ |
| 87 | url = 'capabilities/%s' % host |
| 88 | resp, body = self.get(url) |
| 89 | body = json.loads(body) |
| 90 | self.expected_success(200, resp.status) |
| 91 | return rest_client.ResponseBody(resp, body) |
| 92 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 93 | def show_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 94 | """Returns the details of a single volume.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 95 | url = "volumes/%s" % str(volume_id) |
Attila Fazekas | b8aa759 | 2013-01-26 01:25:45 +0100 | [diff] [blame] | 96 | resp, body = self.get(url) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 97 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 98 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 99 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 100 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 101 | def create_volume(self, **kwargs): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 102 | """Creates a new Volume. |
| 103 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 104 | Available params: see http://developer.openstack.org/ |
| 105 | api-ref-blockstorage-v2.html#createVolume |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 106 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 107 | if 'size' not in kwargs: |
| 108 | kwargs['size'] = self.default_volume_size |
| 109 | post_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 110 | resp, body = self.post('volumes', post_body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 111 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 112 | self.expected_success(self.create_resp, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 113 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 114 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 115 | def update_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 116 | """Updates the Specified Volume. |
| 117 | |
| 118 | Available params: see http://developer.openstack.org/ |
| 119 | api-ref-blockstorage-v2.html#updateVolume |
| 120 | """ |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 121 | put_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 122 | resp, body = self.put('volumes/%s' % volume_id, put_body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 123 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 124 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 125 | return rest_client.ResponseBody(resp, body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 126 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 127 | def delete_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 128 | """Deletes the Specified Volume.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 129 | resp, body = self.delete("volumes/%s" % str(volume_id)) |
| 130 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 131 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 132 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 133 | def upload_volume(self, volume_id, **kwargs): |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 134 | """Uploads a volume in Glance.""" |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 135 | post_body = json.dumps({'os-volume_upload_image': kwargs}) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 136 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 137 | resp, body = self.post(url, post_body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 138 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 139 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 140 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 141 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 142 | def attach_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 143 | """Attaches a volume to a given instance on a given mountpoint. |
| 144 | |
| 145 | Available params: see http://developer.openstack.org/ |
| 146 | api-ref-blockstorage-v2.html#attachVolume |
| 147 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 148 | post_body = json.dumps({'os-attach': kwargs}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 149 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 150 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 151 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 152 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 153 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 154 | def set_bootable_volume(self, volume_id, **kwargs): |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 155 | """set a bootable flag for a volume - true or false.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 156 | post_body = json.dumps({'os-set_bootable': kwargs}) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 157 | url = 'volumes/%s/action' % (volume_id) |
| 158 | resp, body = self.post(url, post_body) |
| 159 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 160 | return rest_client.ResponseBody(resp, body) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 161 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 162 | def detach_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 163 | """Detaches a volume from an instance.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 164 | post_body = json.dumps({'os-detach': {}}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 165 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 166 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 167 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 168 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 169 | |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 170 | def reserve_volume(self, volume_id): |
| 171 | """Reserves a volume.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 172 | post_body = json.dumps({'os-reserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 173 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 174 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 175 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 176 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 177 | |
| 178 | def unreserve_volume(self, volume_id): |
| 179 | """Restore a reserved volume .""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 180 | post_body = json.dumps({'os-unreserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 181 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 182 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 183 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 184 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 185 | |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 186 | def is_resource_deleted(self, id): |
| 187 | try: |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 188 | self.show_volume(id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 189 | except lib_exc.NotFound: |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 190 | return True |
| 191 | return False |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 192 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 193 | @property |
| 194 | def resource_type(self): |
| 195 | """Returns the primary type of resource this client works with.""" |
| 196 | return 'volume' |
| 197 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 198 | def extend_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 199 | """Extend a volume. |
| 200 | |
| 201 | Available params: see http://developer.openstack.org/ |
| 202 | api-ref-blockstorage-v2.html#extendVolume |
| 203 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 204 | post_body = json.dumps({'os-extend': kwargs}) |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 205 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 206 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 207 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 208 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 209 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 210 | def reset_volume_status(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 211 | """Reset the Specified Volume's Status. |
| 212 | |
| 213 | Available params: see http://developer.openstack.org/ |
| 214 | api-ref-blockstorage-v2.html#resetVolume |
| 215 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 216 | post_body = json.dumps({'os-reset_status': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 217 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 218 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 219 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 220 | |
| 221 | def volume_begin_detaching(self, volume_id): |
| 222 | """Volume Begin Detaching.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 223 | # ref cinder/api/contrib/volume_actions.py#L158 |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 224 | post_body = json.dumps({'os-begin_detaching': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 225 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 226 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 227 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 228 | |
| 229 | def volume_roll_detaching(self, volume_id): |
| 230 | """Volume Roll Detaching.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 231 | # cinder/api/contrib/volume_actions.py#L170 |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 232 | post_body = json.dumps({'os-roll_detaching': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 233 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 234 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 235 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 236 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 237 | def create_volume_transfer(self, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 238 | """Create a volume transfer. |
| 239 | |
| 240 | Available params: see http://developer.openstack.org/ |
| 241 | api-ref-blockstorage-v2.html#createVolumeTransfer |
| 242 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 243 | post_body = json.dumps({'transfer': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 244 | resp, body = self.post('os-volume-transfer', post_body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 245 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 246 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 247 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 248 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 249 | def show_volume_transfer(self, transfer_id): |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 250 | """Returns the details of a volume transfer.""" |
| 251 | url = "os-volume-transfer/%s" % str(transfer_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 252 | resp, body = self.get(url) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 253 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 254 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 255 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 256 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 257 | def list_volume_transfers(self, **params): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 258 | """List all the volume transfers created. |
| 259 | |
| 260 | Available params: see http://developer.openstack.org/ |
| 261 | api-ref-blockstorage-v2.html#listVolumeTransfer |
| 262 | """ |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 263 | url = 'os-volume-transfer' |
| 264 | if params: |
| 265 | url += '?%s' % urllib.urlencode(params) |
| 266 | resp, body = self.get(url) |
| 267 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 268 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 269 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 270 | |
| 271 | def delete_volume_transfer(self, transfer_id): |
| 272 | """Delete a volume transfer.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 273 | resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id)) |
| 274 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 275 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 276 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 277 | def accept_volume_transfer(self, transfer_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 278 | """Accept a volume transfer. |
| 279 | |
| 280 | Available params: see http://developer.openstack.org/ |
| 281 | api-ref-blockstorage-v2.html#acceptVolumeTransfer |
| 282 | """ |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 283 | url = 'os-volume-transfer/%s/accept' % transfer_id |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 284 | post_body = json.dumps({'accept': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 285 | resp, body = self.post(url, post_body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 286 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 287 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 288 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 289 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 290 | def update_volume_readonly(self, volume_id, **kwargs): |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 291 | """Update the Specified Volume readonly.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 292 | post_body = json.dumps({'os-update_readonly_flag': kwargs}) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 293 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 294 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 295 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 296 | return rest_client.ResponseBody(resp, body) |
wanghao | 9d3d6cb | 2013-11-12 15:10:10 +0800 | [diff] [blame] | 297 | |
| 298 | def force_delete_volume(self, volume_id): |
| 299 | """Force Delete Volume.""" |
| 300 | post_body = json.dumps({'os-force_delete': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 301 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 302 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 303 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 304 | |
| 305 | def create_volume_metadata(self, volume_id, metadata): |
| 306 | """Create metadata for the volume.""" |
| 307 | put_body = json.dumps({'metadata': metadata}) |
| 308 | url = "volumes/%s/metadata" % str(volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 309 | resp, body = self.post(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 310 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 311 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 312 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 313 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 314 | def show_volume_metadata(self, volume_id): |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 315 | """Get metadata of the volume.""" |
| 316 | url = "volumes/%s/metadata" % str(volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 317 | resp, body = self.get(url) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 318 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 319 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 320 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 321 | |
| 322 | def update_volume_metadata(self, volume_id, metadata): |
| 323 | """Update metadata for the volume.""" |
| 324 | put_body = json.dumps({'metadata': metadata}) |
| 325 | url = "volumes/%s/metadata" % str(volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 326 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 327 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 328 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 329 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 330 | |
| 331 | def update_volume_metadata_item(self, volume_id, id, meta_item): |
| 332 | """Update metadata item for the volume.""" |
| 333 | put_body = json.dumps({'meta': meta_item}) |
| 334 | url = "volumes/%s/metadata/%s" % (str(volume_id), str(id)) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 335 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 336 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 337 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 338 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 339 | |
| 340 | def delete_volume_metadata_item(self, volume_id, id): |
| 341 | """Delete metadata item for the volume.""" |
| 342 | url = "volumes/%s/metadata/%s" % (str(volume_id), str(id)) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 343 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 344 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 345 | return rest_client.ResponseBody(resp, body) |
Zhi Kun Liu | 6e6cf83 | 2014-05-08 17:25:22 +0800 | [diff] [blame] | 346 | |
lkuchlan | 119b2f2 | 2016-06-20 20:59:41 +0300 | [diff] [blame] | 347 | def update_volume_image_metadata(self, volume_id, **kwargs): |
lkuchlan | 6a61bd9 | 2016-06-23 22:46:08 +0300 | [diff] [blame] | 348 | """Update image metadata for the volume. |
| 349 | |
| 350 | Available params: see http://developer.openstack.org/ |
| 351 | api-ref-blockstorage-v2.html |
| 352 | #setVolumeimagemetadata |
| 353 | """ |
lkuchlan | 119b2f2 | 2016-06-20 20:59:41 +0300 | [diff] [blame] | 354 | post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}}) |
| 355 | url = "volumes/%s/action" % (volume_id) |
| 356 | resp, body = self.post(url, post_body) |
| 357 | body = json.loads(body) |
| 358 | self.expected_success(200, resp.status) |
| 359 | return rest_client.ResponseBody(resp, body) |
| 360 | |
| 361 | def delete_volume_image_metadata(self, volume_id, key_name): |
| 362 | """Delete image metadata item for the volume.""" |
| 363 | post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}}) |
| 364 | url = "volumes/%s/action" % (volume_id) |
| 365 | resp, body = self.post(url, post_body) |
| 366 | self.expected_success(200, resp.status) |
| 367 | return rest_client.ResponseBody(resp, body) |
| 368 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 369 | def retype_volume(self, volume_id, **kwargs): |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 370 | """Updates volume with new volume type.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 371 | post_body = json.dumps({'os-retype': kwargs}) |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 372 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 373 | self.expected_success(202, resp.status) |