blob: c7302e87a4a149ae6e84c1ba60bada7d1c525e8c [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
Matthew Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020017import six
Matthew Treinish89128142015-04-23 10:44:30 -040018from six.moves.urllib import parse as urllib
Masayuki Igawabfa07602015-01-20 18:47:17 +090019from tempest_lib import exceptions as lib_exc
20
Joseph Lanoux6809bab2014-12-18 14:57:18 +000021from tempest.common import service_client
Ken'ichi Ohmichib942be62015-07-08 08:16:12 +000022from tempest.common import waiters
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053024
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000025class BaseVolumesClient(service_client.ServiceClient):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000026 """Base client class to send CRUD Volume API requests"""
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053027
Ken'ichi Ohmichia39d0be2014-12-17 08:46:11 +000028 create_resp = 200
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053029
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000030 def __init__(self, auth_provider, service, region,
31 default_volume_size=1, **kwargs):
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000032 super(BaseVolumesClient, self).__init__(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000033 auth_provider, service, region, **kwargs)
34 self.default_volume_size = default_volume_size
35
anju tiwari789449a2013-08-29 16:56:17 +053036 def get_attachment_from_volume(self, volume):
37 """Return the element 'attachment' from input volumes."""
38 return volume['attachments'][0]
39
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020040 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 Warren6177c9e2015-08-19 20:00:17 +000050 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020051 """List all the volumes created.
52
53 Params can be a string (must be urlencoded) or a dictionary.
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020054 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070055 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000056 if detail:
57 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050058 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020059 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053060
John Warren6177c9e2015-08-19 20:00:17 +000061 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-ganesanddd9e0e2012-03-21 00:49:22 +053065
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000066 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050067 """Returns the details of a single volume."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070068 url = "volumes/%s" % str(volume_id)
Attila Fazekasb8aa7592013-01-26 01:25:45 +010069 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053070 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000071 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +000072 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053073
Jerry Cai9733d0e2014-03-19 15:50:49 +080074 def create_volume(self, size=None, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000075 """Creates a new Volume.
76
Jerry Cai9733d0e2014-03-19 15:50:49 +080077 size: Size of volume in GB.
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053078 Following optional keyword arguments are accepted:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080079 display_name: Optional Volume Name(only for V1).
80 name: Optional Volume Name(only for V2).
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053081 metadata: A dictionary of values to be used as metadata.
Rohan Rhishikesh Kanadec316f0a2012-12-04 05:44:39 -080082 volume_type: Optional Name of volume_type for the volume
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010083 snapshot_id: When specified the volume is created from this snapshot
Giulio Fidente36836c42013-04-05 15:43:51 +020084 imageRef: When specified the volume is created from this image
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053085 """
Jerry Cai9733d0e2014-03-19 15:50:49 +080086 if size is None:
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000087 size = self.default_volume_size
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010088 post_body = {'size': size}
89 post_body.update(kwargs)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053090 post_body = json.dumps({'volume': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020091 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053092 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000093 self.expected_success(self.create_resp, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +000094 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053095
QingXin Meng611768a2013-09-18 00:51:33 -070096 def update_volume(self, volume_id, **kwargs):
97 """Updates the Specified Volume."""
98 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020099 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -0700100 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000101 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000102 return service_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -0700103
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +0530104 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500105 """Deletes the Specified Volume."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000106 resp, body = self.delete("volumes/%s" % str(volume_id))
107 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000108 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530109
Ryan Hsua67f4632013-08-29 16:03:06 -0700110 def upload_volume(self, volume_id, image_name, disk_format):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200111 """Uploads a volume in Glance."""
112 post_body = {
113 'image_name': image_name,
Ryan Hsua67f4632013-08-29 16:03:06 -0700114 'disk_format': disk_format
Giulio Fidente884e9da2013-06-21 17:25:42 +0200115 }
116 post_body = json.dumps({'os-volume_upload_image': post_body})
117 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200118 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200119 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000120 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000121 return service_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200122
Rohit Karajgia42fe442012-09-21 03:08:33 -0700123 def attach_volume(self, volume_id, instance_uuid, mountpoint):
Sean Daguef237ccb2013-01-04 15:19:14 -0500124 """Attaches a volume to a given instance on a given mountpoint."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700125 post_body = {
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900126 'instance_uuid': instance_uuid,
127 'mountpoint': mountpoint,
128 }
Rohit Karajgia42fe442012-09-21 03:08:33 -0700129 post_body = json.dumps({'os-attach': post_body})
130 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200131 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000132 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000133 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700134
bkopilov8a657ae2015-05-11 11:45:23 +0300135 def set_bootable_volume(self, volume_id, bootable):
136 """set a bootable flag for a volume - true or false."""
137 post_body = {"bootable": bootable}
138 post_body = json.dumps({'os-set_bootable': post_body})
139 url = 'volumes/%s/action' % (volume_id)
140 resp, body = self.post(url, post_body)
141 self.expected_success(200, resp.status)
142 return service_client.ResponseBody(resp, body)
143
Rohit Karajgia42fe442012-09-21 03:08:33 -0700144 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500145 """Detaches a volume from an instance."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700146 post_body = {}
147 post_body = json.dumps({'os-detach': post_body})
148 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200149 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000150 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000151 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700152
zhangyanzi6b632432013-10-24 19:08:50 +0800153 def reserve_volume(self, volume_id):
154 """Reserves a volume."""
155 post_body = {}
156 post_body = json.dumps({'os-reserve': post_body})
157 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200158 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000159 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000160 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800161
162 def unreserve_volume(self, volume_id):
163 """Restore a reserved volume ."""
164 post_body = {}
165 post_body = json.dumps({'os-unreserve': post_body})
166 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200167 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000168 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000169 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800170
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530171 def wait_for_volume_status(self, volume_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500172 """Waits for a Volume to reach a given status."""
Ken'ichi Ohmichib942be62015-07-08 08:16:12 +0000173 waiters.wait_for_volume_status(self, volume_id, status)
David Kranz6aceb4a2012-06-05 14:05:45 -0400174
175 def is_resource_deleted(self, id):
176 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000177 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900178 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400179 return True
180 return False
wanghao5b981752013-10-22 11:41:41 +0800181
Matt Riedemannd2b96512014-10-13 10:18:16 -0700182 @property
183 def resource_type(self):
184 """Returns the primary type of resource this client works with."""
185 return 'volume'
186
wanghao5b981752013-10-22 11:41:41 +0800187 def extend_volume(self, volume_id, extend_size):
188 """Extend a volume."""
189 post_body = {
190 'new_size': extend_size
191 }
192 post_body = json.dumps({'os-extend': post_body})
193 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200194 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000195 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000196 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800197
198 def reset_volume_status(self, volume_id, status):
199 """Reset the Specified Volume's Status."""
200 post_body = json.dumps({'os-reset_status': {"status": status}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200201 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000202 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000203 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800204
205 def volume_begin_detaching(self, volume_id):
206 """Volume Begin Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000207 # ref cinder/api/contrib/volume_actions.py#L158
wanghaoaa1f2f92013-10-10 11:30:37 +0800208 post_body = json.dumps({'os-begin_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200209 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000210 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000211 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800212
213 def volume_roll_detaching(self, volume_id):
214 """Volume Roll Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000215 # cinder/api/contrib/volume_actions.py#L170
wanghaoaa1f2f92013-10-10 11:30:37 +0800216 post_body = json.dumps({'os-roll_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200217 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000218 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000219 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800220
221 def create_volume_transfer(self, vol_id, display_name=None):
222 """Create a volume transfer."""
223 post_body = {
224 'volume_id': vol_id
225 }
226 if display_name:
227 post_body['name'] = display_name
228 post_body = json.dumps({'transfer': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200229 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800230 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000231 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000232 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800233
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000234 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800235 """Returns the details of a volume transfer."""
236 url = "os-volume-transfer/%s" % str(transfer_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200237 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800238 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000239 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000240 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800241
242 def list_volume_transfers(self, params=None):
243 """List all the volume transfers created."""
244 url = 'os-volume-transfer'
245 if params:
246 url += '?%s' % urllib.urlencode(params)
247 resp, body = self.get(url)
248 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000249 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000250 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800251
252 def delete_volume_transfer(self, transfer_id):
253 """Delete a volume transfer."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000254 resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id))
255 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000256 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800257
258 def accept_volume_transfer(self, transfer_id, transfer_auth_key):
259 """Accept a volume transfer."""
260 post_body = {
261 'auth_key': transfer_auth_key,
262 }
263 url = 'os-volume-transfer/%s/accept' % transfer_id
264 post_body = json.dumps({'accept': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200265 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800266 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000267 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000268 return service_client.ResponseBody(resp, body)
zhangyanziaa180072013-11-21 12:31:26 +0800269
270 def update_volume_readonly(self, volume_id, readonly):
271 """Update the Specified Volume readonly."""
272 post_body = {
273 'readonly': readonly
274 }
275 post_body = json.dumps({'os-update_readonly_flag': post_body})
276 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200277 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000278 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000279 return service_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800280
281 def force_delete_volume(self, volume_id):
282 """Force Delete Volume."""
283 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200284 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000285 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000286 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800287
288 def create_volume_metadata(self, volume_id, metadata):
289 """Create metadata for the volume."""
290 put_body = json.dumps({'metadata': metadata})
291 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200292 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800293 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000294 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000295 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800296
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000297 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800298 """Get metadata of the volume."""
299 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200300 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800301 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000302 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000303 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800304
305 def update_volume_metadata(self, volume_id, metadata):
306 """Update metadata for the volume."""
307 put_body = json.dumps({'metadata': metadata})
308 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200309 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800310 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000311 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000312 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800313
314 def update_volume_metadata_item(self, volume_id, id, meta_item):
315 """Update metadata item for the volume."""
316 put_body = json.dumps({'meta': meta_item})
317 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200318 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800319 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000320 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000321 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800322
323 def delete_volume_metadata_item(self, volume_id, id):
324 """Delete metadata item for the volume."""
325 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200326 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000327 self.expected_success(200, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000328 return service_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800329
nayna-patel78f743e2015-01-09 10:52:51 +0000330 def retype_volume(self, volume_id, volume_type, **kwargs):
331 """Updates volume with new volume type."""
332 post_body = {'new_type': volume_type}
333 post_body.update(kwargs)
334 post_body = json.dumps({'os-retype': post_body})
335 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
336 self.expected_success(202, resp.status)