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 |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 22 | from tempest.lib.services.volume import base_client |
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 | |
zhufl | 0273652 | 2017-06-19 13:57:28 +0800 | [diff] [blame] | 25 | class VolumesClient(base_client.BaseClient): |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 26 | """Client class to send CRUD Volume V2 API requests""" |
| 27 | api_version = "v2" |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 28 | |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 29 | def _prepare_params(self, params): |
| 30 | """Prepares params for use in get or _ext_get methods. |
| 31 | |
| 32 | If params is a string it will be left as it is, but if it's not it will |
| 33 | be urlencoded. |
| 34 | """ |
| 35 | if isinstance(params, six.string_types): |
| 36 | return params |
| 37 | return urllib.urlencode(params) |
| 38 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 39 | def list_volumes(self, detail=False, params=None): |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 40 | """List all the volumes created. |
| 41 | |
| 42 | Params can be a string (must be urlencoded) or a dictionary. |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 43 | For a full list of available parameters, please refer to the official |
| 44 | API reference: |
| 45 | http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details |
| 46 | http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 47 | """ |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 48 | url = 'volumes' |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 49 | if detail: |
| 50 | url += '/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 51 | if params: |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 52 | url += '?%s' % self._prepare_params(params) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 53 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 54 | resp, body = self.get(url) |
| 55 | body = json.loads(body) |
| 56 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 57 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 58 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 59 | def show_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 60 | """Returns the details of a single volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 61 | url = "volumes/%s" % volume_id |
Attila Fazekas | b8aa759 | 2013-01-26 01:25:45 +0100 | [diff] [blame] | 62 | resp, body = self.get(url) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 63 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 64 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 65 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 66 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 67 | def create_volume(self, **kwargs): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 68 | """Creates a new Volume. |
| 69 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 70 | For a full list of available parameters, please refer to the official |
| 71 | API reference: |
Andrea Frittoli | 2715d22 | 2017-03-29 14:53:48 +0100 | [diff] [blame] | 72 | http://developer.openstack.org/api-ref/block-storage/v2/#create-volume |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 73 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 74 | post_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 75 | resp, body = self.post('volumes', post_body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 76 | body = json.loads(body) |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 77 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 78 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 79 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 80 | def update_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 81 | """Updates the Specified Volume. |
| 82 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 83 | For a full list of available parameters, please refer to the official |
| 84 | API reference: |
Andrea Frittoli | 2715d22 | 2017-03-29 14:53:48 +0100 | [diff] [blame] | 85 | http://developer.openstack.org/api-ref/block-storage/v2/#update-volume |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 86 | """ |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 87 | put_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 88 | resp, body = self.put('volumes/%s' % volume_id, put_body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 89 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 90 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 91 | return rest_client.ResponseBody(resp, body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 92 | |
Jordan Pittier | cb5f650 | 2017-04-10 14:27:39 +0200 | [diff] [blame] | 93 | def delete_volume(self, volume_id, **params): |
| 94 | """Deletes the Specified Volume. |
| 95 | |
| 96 | For a full list of available parameters, please refer to the official |
| 97 | API reference: |
| 98 | https://developer.openstack.org/api-ref/block-storage/v2/#delete-volume |
| 99 | """ |
lkuchlan | 0e3bbdf | 2016-07-11 12:06:51 +0300 | [diff] [blame] | 100 | url = 'volumes/%s' % volume_id |
Jordan Pittier | cb5f650 | 2017-04-10 14:27:39 +0200 | [diff] [blame] | 101 | if params: |
| 102 | url += '?%s' % urllib.urlencode(params) |
lkuchlan | 0e3bbdf | 2016-07-11 12:06:51 +0300 | [diff] [blame] | 103 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 104 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 105 | return rest_client.ResponseBody(resp, body) |
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 | def upload_volume(self, volume_id, **kwargs): |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 108 | """Uploads a volume in Glance.""" |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 109 | post_body = json.dumps({'os-volume_upload_image': kwargs}) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 110 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 111 | resp, body = self.post(url, post_body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 112 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 113 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 114 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 115 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 116 | def attach_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 117 | """Attaches a volume to a given instance on a given mountpoint. |
| 118 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 119 | For a full list of available parameters, please refer to the official |
| 120 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 121 | http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 122 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 123 | post_body = json.dumps({'os-attach': kwargs}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 124 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 125 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 126 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 127 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 128 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 129 | def set_bootable_volume(self, volume_id, **kwargs): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 130 | """Set a bootable flag for a volume - true or false. |
| 131 | |
| 132 | For a full list of available parameters, please refer to the official |
| 133 | API reference: |
| 134 | http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-bootable-status |
| 135 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 136 | post_body = json.dumps({'os-set_bootable': kwargs}) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 137 | url = 'volumes/%s/action' % (volume_id) |
| 138 | resp, body = self.post(url, post_body) |
| 139 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 140 | return rest_client.ResponseBody(resp, body) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 141 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 142 | def detach_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 143 | """Detaches a volume from an instance.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 144 | post_body = json.dumps({'os-detach': {}}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 145 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 146 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 147 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 148 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 149 | |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 150 | def reserve_volume(self, volume_id): |
| 151 | """Reserves a volume.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 152 | post_body = json.dumps({'os-reserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 153 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 154 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 155 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 156 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 157 | |
| 158 | def unreserve_volume(self, volume_id): |
| 159 | """Restore a reserved volume .""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 160 | post_body = json.dumps({'os-unreserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 161 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 162 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 163 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 164 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 165 | |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 166 | def is_resource_deleted(self, id): |
Ken'ichi Ohmichi | 4723fde | 2017-04-26 14:19:57 -0700 | [diff] [blame] | 167 | """Check the specified resource is deleted or not. |
| 168 | |
| 169 | :param id: A checked resource id |
| 170 | :raises lib_exc.DeleteErrorException: If the specified resource is on |
| 171 | the status the delete was failed. |
| 172 | """ |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 173 | try: |
Ken'ichi Ohmichi | 4723fde | 2017-04-26 14:19:57 -0700 | [diff] [blame] | 174 | volume = self.show_volume(id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 175 | except lib_exc.NotFound: |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 176 | return True |
Ken'ichi Ohmichi | 4723fde | 2017-04-26 14:19:57 -0700 | [diff] [blame] | 177 | if volume["volume"]["status"] == "error_deleting": |
| 178 | raise lib_exc.DeleteErrorException(resource_id=id) |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 179 | return False |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 180 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 181 | @property |
| 182 | def resource_type(self): |
| 183 | """Returns the primary type of resource this client works with.""" |
| 184 | return 'volume' |
| 185 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 186 | def extend_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 187 | """Extend a volume. |
| 188 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 189 | For a full list of available parameters, please refer to the official |
| 190 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 191 | http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 192 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 193 | post_body = json.dumps({'os-extend': kwargs}) |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 194 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 195 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 196 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 197 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 198 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 199 | def reset_volume_status(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 200 | """Reset the Specified Volume's Status. |
| 201 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 202 | For a full list of available parameters, please refer to the official |
| 203 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 204 | http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 205 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 206 | post_body = json.dumps({'os-reset_status': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 207 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 208 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 209 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 210 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 211 | def update_volume_readonly(self, volume_id, **kwargs): |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 212 | """Update the Specified Volume readonly.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 213 | post_body = json.dumps({'os-update_readonly_flag': kwargs}) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 214 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 215 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 216 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 217 | return rest_client.ResponseBody(resp, body) |
wanghao | 9d3d6cb | 2013-11-12 15:10:10 +0800 | [diff] [blame] | 218 | |
| 219 | def force_delete_volume(self, volume_id): |
| 220 | """Force Delete Volume.""" |
| 221 | post_body = json.dumps({'os-force_delete': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 222 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 223 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 224 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 225 | |
| 226 | def create_volume_metadata(self, volume_id, metadata): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 227 | """Create metadata for the volume. |
| 228 | |
| 229 | For a full list of available parameters, please refer to the official |
| 230 | API reference: |
| 231 | http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-metadata |
| 232 | """ |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 233 | put_body = json.dumps({'metadata': metadata}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 234 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 235 | resp, body = self.post(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 236 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 237 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 238 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 239 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 240 | def show_volume_metadata(self, volume_id): |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 241 | """Get metadata of the volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 242 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 243 | resp, body = self.get(url) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 244 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 245 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 246 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 247 | |
| 248 | def update_volume_metadata(self, volume_id, metadata): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 249 | """Update metadata for the volume. |
| 250 | |
| 251 | For a full list of available parameters, please refer to the official |
| 252 | API reference: |
| 253 | http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-metadata |
| 254 | """ |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 255 | put_body = json.dumps({'metadata': metadata}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 256 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 257 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 258 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 259 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 260 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 261 | |
jeremy.zhang | b40cb19 | 2017-07-04 12:56:59 +0800 | [diff] [blame] | 262 | def show_volume_metadata_item(self, volume_id, id): |
| 263 | """Show metadata item for the volume.""" |
| 264 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
| 265 | resp, body = self.get(url) |
| 266 | body = json.loads(body) |
| 267 | self.expected_success(200, resp.status) |
| 268 | return rest_client.ResponseBody(resp, body) |
| 269 | |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 270 | def update_volume_metadata_item(self, volume_id, id, meta_item): |
| 271 | """Update metadata item for the volume.""" |
| 272 | put_body = json.dumps({'meta': meta_item}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 273 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 274 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 275 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 276 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 277 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 278 | |
| 279 | def delete_volume_metadata_item(self, volume_id, id): |
| 280 | """Delete metadata item for the volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 281 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 282 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 283 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 284 | return rest_client.ResponseBody(resp, body) |
Zhi Kun Liu | 6e6cf83 | 2014-05-08 17:25:22 +0800 | [diff] [blame] | 285 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 286 | def retype_volume(self, volume_id, **kwargs): |
jeremy.zhang | 83b3e55 | 2017-06-23 15:53:50 +0800 | [diff] [blame] | 287 | """Updates volume with new volume type. |
| 288 | |
| 289 | For a full list of available parameters, please refer to the official |
| 290 | API reference: |
| 291 | https://developer.openstack.org/api-ref/block-storage/v2/#retype-volume |
| 292 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 293 | post_body = json.dumps({'os-retype': kwargs}) |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 294 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 295 | self.expected_success(202, resp.status) |
raigax9 | d850882 | 2017-07-12 18:31:39 -0400 | [diff] [blame] | 296 | return rest_client.ResponseBody(resp, body) |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 297 | |
jeremy.zhang | 7b0eaf8 | 2017-04-25 15:11:15 +0800 | [diff] [blame] | 298 | def force_detach_volume(self, volume_id, **kwargs): |
| 299 | """Force detach a volume. |
| 300 | |
| 301 | For a full list of available parameters, please refer to the official |
| 302 | API reference: |
| 303 | https://developer.openstack.org/api-ref/block-storage/v2/#force-detach-volume |
| 304 | """ |
| 305 | post_body = json.dumps({'os-force_detach': kwargs}) |
| 306 | url = 'volumes/%s/action' % volume_id |
| 307 | resp, body = self.post(url, post_body) |
| 308 | self.expected_success(202, resp.status) |
| 309 | return rest_client.ResponseBody(resp, body) |
| 310 | |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 311 | def update_volume_image_metadata(self, volume_id, **kwargs): |
| 312 | """Update image metadata for the volume. |
| 313 | |
Dong Ma | 127887a | 2016-10-19 09:09:11 -0700 | [diff] [blame] | 314 | For a full list of available parameters, please refer to the official |
| 315 | API reference: |
zhufl | ccd9d65 | 2017-03-30 15:01:49 +0800 | [diff] [blame] | 316 | http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume |
lkuchlan | f53947e | 2016-09-15 10:37:57 +0300 | [diff] [blame] | 317 | """ |
| 318 | post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}}) |
| 319 | url = "volumes/%s/action" % (volume_id) |
| 320 | resp, body = self.post(url, post_body) |
| 321 | body = json.loads(body) |
| 322 | self.expected_success(200, resp.status) |
| 323 | return rest_client.ResponseBody(resp, body) |
| 324 | |
| 325 | def delete_volume_image_metadata(self, volume_id, key_name): |
| 326 | """Delete image metadata item for the volume.""" |
| 327 | post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}}) |
| 328 | url = "volumes/%s/action" % (volume_id) |
| 329 | resp, body = self.post(url, post_body) |
| 330 | self.expected_success(200, resp.status) |
| 331 | return rest_client.ResponseBody(resp, body) |
| 332 | |
jeremy.zhang | f0599b1 | 2017-08-03 20:02:51 +0800 | [diff] [blame] | 333 | def show_volume_image_metadata(self, volume_id): |
| 334 | """Show image metadata for the volume.""" |
| 335 | post_body = json.dumps({'os-show_image_metadata': {}}) |
| 336 | url = "volumes/%s/action" % volume_id |
| 337 | resp, body = self.post(url, post_body) |
| 338 | body = json.loads(body) |
| 339 | self.expected_success(200, resp.status) |
| 340 | return rest_client.ResponseBody(resp, body) |
| 341 | |
jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 342 | def unmanage_volume(self, volume_id): |
| 343 | """Unmanage volume. |
| 344 | |
| 345 | For a full list of available parameters, please refer to the official |
| 346 | API reference: |
| 347 | https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume |
| 348 | """ |
| 349 | post_body = json.dumps({'os-unmanage': {}}) |
| 350 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 351 | self.expected_success(202, resp.status) |
| 352 | return rest_client.ResponseBody(resp, body) |