blob: 5d8d73b386e77d28c1f63ee040b6e07a5ca36224 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07002# 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
songwenping99d6e002021-01-05 03:07:46 +000016from urllib import parse as urllib
17
Matthew Treinish21905512015-07-13 10:33:35 -040018from oslo_serialization import jsonutils as json
Masayuki Igawabfa07602015-01-20 18:47:17 +090019
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080020from tempest.lib.common import rest_client
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050021from tempest.lib import exceptions as lib_exc
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070022
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053023
lkuchlanf53947e2016-09-15 10:37:57 +030024class VolumesClient(rest_client.RestClient):
lkuchlan63ddf2e2016-11-06 08:42:56 +020025 """Client class to send CRUD Volume V1 API requests"""
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053026
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020027 def _prepare_params(self, params):
28 """Prepares params for use in get or _ext_get methods.
29
30 If params is a string it will be left as it is, but if it's not it will
31 be urlencoded.
32 """
songwenpinga6ee2d12021-02-22 10:24:16 +080033 if isinstance(params, str):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020034 return params
35 return urllib.urlencode(params)
36
John Warren6177c9e2015-08-19 20:00:17 +000037 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020038 """List all the volumes created.
39
40 Params can be a string (must be urlencoded) or a dictionary.
Felipe Monteiro25084512017-11-14 22:07:31 +000041
42 For a full list of available parameters, please refer to the official
43 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020044 https://docs.openstack.org/api-ref/block-storage/v2/#list-volumes
45 https://docs.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020046 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070047 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000048 if detail:
49 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050050 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020051 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053052
John Warren6177c9e2015-08-19 20:00:17 +000053 resp, body = self.get(url)
54 body = json.loads(body)
55 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080056 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053057
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000058 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050059 """Returns the details of a single volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080060 url = "volumes/%s" % volume_id
Attila Fazekasb8aa7592013-01-26 01:25:45 +010061 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053062 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000063 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080064 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053065
Ghanshyam8fc0ed22015-12-18 10:25:14 +090066 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000067 """Creates a new Volume.
68
Dong Ma127887a2016-10-19 09:09:11 -070069 For a full list of available parameters, please refer to the official
70 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020071 https://docs.openstack.org/api-ref/block-storage/v2/#create-volume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053072 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +090073 post_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020074 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053075 body = json.loads(body)
lkuchlanf53947e2016-09-15 10:37:57 +030076 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080077 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053078
QingXin Meng611768a2013-09-18 00:51:33 -070079 def update_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +080080 """Updates the Specified Volume.
81
Dong Ma127887a2016-10-19 09:09:11 -070082 For a full list of available parameters, please refer to the official
83 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020084 https://docs.openstack.org/api-ref/block-storage/v2/#update-volume
guo xiand8bc1cd2016-06-23 12:35:43 +080085 """
QingXin Meng611768a2013-09-18 00:51:33 -070086 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020087 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -070088 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000089 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080090 return rest_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -070091
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053092 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050093 """Deletes the Specified Volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080094 resp, body = self.delete("volumes/%s" % volume_id)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000095 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080096 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053097
Ghanshyam8fc0ed22015-12-18 10:25:14 +090098 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +020099 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900100 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +0200101 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200102 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200103 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000104 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800105 return rest_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200106
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900107 def attach_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800108 """Attaches a volume to a given instance on a given mountpoint.
109
Dong Ma127887a2016-10-19 09:09:11 -0700110 For a full list of available parameters, please refer to the official
111 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200112 https://docs.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server
guo xiand8bc1cd2016-06-23 12:35:43 +0800113 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900114 post_body = json.dumps({'os-attach': kwargs})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700115 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200116 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000117 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800118 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700119
Ghanshyam58a9e872015-12-18 10:46:07 +0900120 def set_bootable_volume(self, volume_id, **kwargs):
bkopilov8a657ae2015-05-11 11:45:23 +0300121 """set a bootable flag for a volume - true or false."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900122 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300123 url = 'volumes/%s/action' % (volume_id)
124 resp, body = self.post(url, post_body)
125 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800126 return rest_client.ResponseBody(resp, body)
bkopilov8a657ae2015-05-11 11:45:23 +0300127
Rohit Karajgia42fe442012-09-21 03:08:33 -0700128 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500129 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900130 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700131 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200132 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000133 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800134 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700135
zhangyanzi6b632432013-10-24 19:08:50 +0800136 def reserve_volume(self, volume_id):
137 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900138 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800139 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200140 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000141 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800142 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800143
144 def unreserve_volume(self, volume_id):
145 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900146 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800147 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200148 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000149 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800150 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800151
David Kranz6aceb4a2012-06-05 14:05:45 -0400152 def is_resource_deleted(self, id):
153 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000154 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900155 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400156 return True
157 return False
wanghao5b981752013-10-22 11:41:41 +0800158
Matt Riedemannd2b96512014-10-13 10:18:16 -0700159 @property
160 def resource_type(self):
161 """Returns the primary type of resource this client works with."""
162 return 'volume'
163
Ghanshyam58a9e872015-12-18 10:46:07 +0900164 def extend_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800165 """Extend a volume.
166
Dong Ma127887a2016-10-19 09:09:11 -0700167 For a full list of available parameters, please refer to the official
168 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200169 https://docs.openstack.org/api-ref/block-storage/v2/#extend-volume-size
guo xiand8bc1cd2016-06-23 12:35:43 +0800170 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900171 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +0800172 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200173 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000174 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800175 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800176
Ghanshyam58a9e872015-12-18 10:46:07 +0900177 def reset_volume_status(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800178 """Reset the Specified Volume's Status.
179
Dong Ma127887a2016-10-19 09:09:11 -0700180 For a full list of available parameters, please refer to the official
181 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200182 https://docs.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses
guo xiand8bc1cd2016-06-23 12:35:43 +0800183 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900184 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200185 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000186 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800187 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800188
Ghanshyam58a9e872015-12-18 10:46:07 +0900189 def create_volume_transfer(self, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800190 """Create a volume transfer.
191
Dong Ma127887a2016-10-19 09:09:11 -0700192 For a full list of available parameters, please refer to the official
193 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200194 https://docs.openstack.org/api-ref/block-storage/v2/#create-volume-transfer
guo xiand8bc1cd2016-06-23 12:35:43 +0800195 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900196 post_body = json.dumps({'transfer': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200197 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800198 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000199 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800200 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800201
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000202 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800203 """Returns the details of a volume transfer."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800204 url = "os-volume-transfer/%s" % transfer_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200205 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800206 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000207 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800208 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800209
Ghanshyam58a9e872015-12-18 10:46:07 +0900210 def list_volume_transfers(self, **params):
guo xiand8bc1cd2016-06-23 12:35:43 +0800211 """List all the volume transfers created.
212
Dong Ma127887a2016-10-19 09:09:11 -0700213 For a full list of available parameters, please refer to the official
214 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200215 https://docs.openstack.org/api-ref/block-storage/v2/#list-volume-transfers
guo xiand8bc1cd2016-06-23 12:35:43 +0800216 """
wingwjcbd82dc2013-10-22 16:38:39 +0800217 url = 'os-volume-transfer'
218 if params:
219 url += '?%s' % urllib.urlencode(params)
220 resp, body = self.get(url)
221 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000222 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800223 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800224
225 def delete_volume_transfer(self, transfer_id):
226 """Delete a volume transfer."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800227 resp, body = self.delete("os-volume-transfer/%s" % transfer_id)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000228 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800229 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800230
Ghanshyam58a9e872015-12-18 10:46:07 +0900231 def accept_volume_transfer(self, transfer_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800232 """Accept a volume transfer.
233
Dong Ma127887a2016-10-19 09:09:11 -0700234 For a full list of available parameters, please refer to the official
235 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200236 https://docs.openstack.org/api-ref/block-storage/v2/#accept-volume-transfer
guo xiand8bc1cd2016-06-23 12:35:43 +0800237 """
wingwjcbd82dc2013-10-22 16:38:39 +0800238 url = 'os-volume-transfer/%s/accept' % transfer_id
Ghanshyam58a9e872015-12-18 10:46:07 +0900239 post_body = json.dumps({'accept': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200240 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800241 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000242 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800243 return rest_client.ResponseBody(resp, body)
zhangyanziaa180072013-11-21 12:31:26 +0800244
Ghanshyam58a9e872015-12-18 10:46:07 +0900245 def update_volume_readonly(self, volume_id, **kwargs):
zhangyanziaa180072013-11-21 12:31:26 +0800246 """Update the Specified Volume readonly."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900247 post_body = json.dumps({'os-update_readonly_flag': kwargs})
zhangyanziaa180072013-11-21 12:31:26 +0800248 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200249 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000250 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800251 return rest_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800252
253 def force_delete_volume(self, volume_id):
254 """Force Delete Volume."""
255 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200256 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000257 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800258 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800259
260 def create_volume_metadata(self, volume_id, metadata):
261 """Create metadata for the volume."""
262 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800263 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200264 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800265 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000266 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800267 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800268
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000269 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800270 """Get metadata of the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800271 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200272 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800273 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000274 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800275 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800276
277 def update_volume_metadata(self, volume_id, metadata):
278 """Update metadata for the volume."""
279 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800280 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200281 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800282 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000283 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800284 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800285
286 def update_volume_metadata_item(self, volume_id, id, meta_item):
287 """Update metadata item for the volume."""
288 put_body = json.dumps({'meta': meta_item})
guo yunxian6cdf0562016-08-17 16:21:52 +0800289 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200290 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800291 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000292 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800293 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800294
295 def delete_volume_metadata_item(self, volume_id, id):
296 """Delete metadata item for the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800297 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200298 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000299 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800300 return rest_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800301
Ghanshyam58a9e872015-12-18 10:46:07 +0900302 def retype_volume(self, volume_id, **kwargs):
nayna-patel78f743e2015-01-09 10:52:51 +0000303 """Updates volume with new volume type."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900304 post_body = json.dumps({'os-retype': kwargs})
zhufl3ead9982020-11-19 14:39:04 +0800305 resp, _ = self.post('volumes/%s/action' % volume_id, post_body)
nayna-patel78f743e2015-01-09 10:52:51 +0000306 self.expected_success(202, resp.status)