blob: 9304f6378b581847e05fc57b75e608cd1a80d7e5 [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):
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070026 """
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080027 Base client class to send CRUD Volume API requests to a Cinder endpoint
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070028 """
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053029
Ken'ichi Ohmichia39d0be2014-12-17 08:46:11 +000030 create_resp = 200
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053031
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000032 def __init__(self, auth_provider, service, region,
33 default_volume_size=1, **kwargs):
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000034 super(BaseVolumesClient, self).__init__(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000035 auth_provider, service, region, **kwargs)
36 self.default_volume_size = default_volume_size
37
anju tiwari789449a2013-08-29 16:56:17 +053038 def get_attachment_from_volume(self, volume):
39 """Return the element 'attachment' from input volumes."""
40 return volume['attachments'][0]
41
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020042 def _prepare_params(self, params):
43 """Prepares params for use in get or _ext_get methods.
44
45 If params is a string it will be left as it is, but if it's not it will
46 be urlencoded.
47 """
48 if isinstance(params, six.string_types):
49 return params
50 return urllib.urlencode(params)
51
John Warren6177c9e2015-08-19 20:00:17 +000052 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020053 """List all the volumes created.
54
55 Params can be a string (must be urlencoded) or a dictionary.
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020056 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070057 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000058 if detail:
59 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050060 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020061 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053062
John Warren6177c9e2015-08-19 20:00:17 +000063 resp, body = self.get(url)
64 body = json.loads(body)
65 self.expected_success(200, resp.status)
66 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053067
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000068 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050069 """Returns the details of a single volume."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070070 url = "volumes/%s" % str(volume_id)
Attila Fazekasb8aa7592013-01-26 01:25:45 +010071 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053072 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000073 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +000074 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053075
Jerry Cai9733d0e2014-03-19 15:50:49 +080076 def create_volume(self, size=None, **kwargs):
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053077 """
78 Creates a new Volume.
Jerry Cai9733d0e2014-03-19 15:50:49 +080079 size: Size of volume in GB.
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053080 Following optional keyword arguments are accepted:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080081 display_name: Optional Volume Name(only for V1).
82 name: Optional Volume Name(only for V2).
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053083 metadata: A dictionary of values to be used as metadata.
Rohan Rhishikesh Kanadec316f0a2012-12-04 05:44:39 -080084 volume_type: Optional Name of volume_type for the volume
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010085 snapshot_id: When specified the volume is created from this snapshot
Giulio Fidente36836c42013-04-05 15:43:51 +020086 imageRef: When specified the volume is created from this image
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053087 """
Jerry Cai9733d0e2014-03-19 15:50:49 +080088 if size is None:
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000089 size = self.default_volume_size
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010090 post_body = {'size': size}
91 post_body.update(kwargs)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053092 post_body = json.dumps({'volume': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020093 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053094 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000095 self.expected_success(self.create_resp, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +000096 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053097
QingXin Meng611768a2013-09-18 00:51:33 -070098 def update_volume(self, volume_id, **kwargs):
99 """Updates the Specified Volume."""
100 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200101 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -0700102 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000103 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000104 return service_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -0700105
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +0530106 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500107 """Deletes the Specified Volume."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000108 resp, body = self.delete("volumes/%s" % str(volume_id))
109 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000110 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530111
Ryan Hsua67f4632013-08-29 16:03:06 -0700112 def upload_volume(self, volume_id, image_name, disk_format):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200113 """Uploads a volume in Glance."""
114 post_body = {
115 'image_name': image_name,
Ryan Hsua67f4632013-08-29 16:03:06 -0700116 'disk_format': disk_format
Giulio Fidente884e9da2013-06-21 17:25:42 +0200117 }
118 post_body = json.dumps({'os-volume_upload_image': post_body})
119 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200120 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200121 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000122 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000123 return service_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200124
Rohit Karajgia42fe442012-09-21 03:08:33 -0700125 def attach_volume(self, volume_id, instance_uuid, mountpoint):
Sean Daguef237ccb2013-01-04 15:19:14 -0500126 """Attaches a volume to a given instance on a given mountpoint."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700127 post_body = {
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900128 'instance_uuid': instance_uuid,
129 'mountpoint': mountpoint,
130 }
Rohit Karajgia42fe442012-09-21 03:08:33 -0700131 post_body = json.dumps({'os-attach': post_body})
132 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200133 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000134 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000135 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700136
bkopilov8a657ae2015-05-11 11:45:23 +0300137 def set_bootable_volume(self, volume_id, bootable):
138 """set a bootable flag for a volume - true or false."""
139 post_body = {"bootable": bootable}
140 post_body = json.dumps({'os-set_bootable': post_body})
141 url = 'volumes/%s/action' % (volume_id)
142 resp, body = self.post(url, post_body)
143 self.expected_success(200, resp.status)
144 return service_client.ResponseBody(resp, body)
145
Rohit Karajgia42fe442012-09-21 03:08:33 -0700146 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500147 """Detaches a volume from an instance."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700148 post_body = {}
149 post_body = json.dumps({'os-detach': post_body})
150 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200151 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000152 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000153 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700154
zhangyanzi6b632432013-10-24 19:08:50 +0800155 def reserve_volume(self, volume_id):
156 """Reserves a volume."""
157 post_body = {}
158 post_body = json.dumps({'os-reserve': post_body})
159 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200160 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000161 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000162 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800163
164 def unreserve_volume(self, volume_id):
165 """Restore a reserved volume ."""
166 post_body = {}
167 post_body = json.dumps({'os-unreserve': post_body})
168 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200169 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000170 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000171 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800172
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530173 def wait_for_volume_status(self, volume_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500174 """Waits for a Volume to reach a given status."""
Ken'ichi Ohmichib942be62015-07-08 08:16:12 +0000175 waiters.wait_for_volume_status(self, volume_id, status)
David Kranz6aceb4a2012-06-05 14:05:45 -0400176
177 def is_resource_deleted(self, id):
178 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000179 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900180 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400181 return True
182 return False
wanghao5b981752013-10-22 11:41:41 +0800183
Matt Riedemannd2b96512014-10-13 10:18:16 -0700184 @property
185 def resource_type(self):
186 """Returns the primary type of resource this client works with."""
187 return 'volume'
188
wanghao5b981752013-10-22 11:41:41 +0800189 def extend_volume(self, volume_id, extend_size):
190 """Extend a volume."""
191 post_body = {
192 'new_size': extend_size
193 }
194 post_body = json.dumps({'os-extend': post_body})
195 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200196 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000197 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000198 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800199
200 def reset_volume_status(self, volume_id, status):
201 """Reset the Specified Volume's Status."""
202 post_body = json.dumps({'os-reset_status': {"status": status}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200203 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000204 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000205 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800206
207 def volume_begin_detaching(self, volume_id):
208 """Volume Begin Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000209 # ref cinder/api/contrib/volume_actions.py#L158
wanghaoaa1f2f92013-10-10 11:30:37 +0800210 post_body = json.dumps({'os-begin_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200211 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000212 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000213 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800214
215 def volume_roll_detaching(self, volume_id):
216 """Volume Roll Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000217 # cinder/api/contrib/volume_actions.py#L170
wanghaoaa1f2f92013-10-10 11:30:37 +0800218 post_body = json.dumps({'os-roll_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200219 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000220 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000221 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800222
223 def create_volume_transfer(self, vol_id, display_name=None):
224 """Create a volume transfer."""
225 post_body = {
226 'volume_id': vol_id
227 }
228 if display_name:
229 post_body['name'] = display_name
230 post_body = json.dumps({'transfer': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200231 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800232 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000233 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000234 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800235
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000236 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800237 """Returns the details of a volume transfer."""
238 url = "os-volume-transfer/%s" % str(transfer_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200239 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800240 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000241 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000242 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800243
244 def list_volume_transfers(self, params=None):
245 """List all the volume transfers created."""
246 url = 'os-volume-transfer'
247 if params:
248 url += '?%s' % urllib.urlencode(params)
249 resp, body = self.get(url)
250 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000251 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000252 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800253
254 def delete_volume_transfer(self, transfer_id):
255 """Delete a volume transfer."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000256 resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id))
257 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000258 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800259
260 def accept_volume_transfer(self, transfer_id, transfer_auth_key):
261 """Accept a volume transfer."""
262 post_body = {
263 'auth_key': transfer_auth_key,
264 }
265 url = 'os-volume-transfer/%s/accept' % transfer_id
266 post_body = json.dumps({'accept': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200267 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800268 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000269 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000270 return service_client.ResponseBody(resp, body)
zhangyanziaa180072013-11-21 12:31:26 +0800271
272 def update_volume_readonly(self, volume_id, readonly):
273 """Update the Specified Volume readonly."""
274 post_body = {
275 'readonly': readonly
276 }
277 post_body = json.dumps({'os-update_readonly_flag': post_body})
278 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200279 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000280 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000281 return service_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800282
283 def force_delete_volume(self, volume_id):
284 """Force Delete Volume."""
285 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200286 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000287 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000288 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800289
290 def create_volume_metadata(self, volume_id, metadata):
291 """Create metadata for the volume."""
292 put_body = json.dumps({'metadata': metadata})
293 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200294 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800295 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000296 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000297 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800298
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000299 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800300 """Get metadata of the volume."""
301 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200302 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800303 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000304 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000305 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800306
307 def update_volume_metadata(self, volume_id, metadata):
308 """Update metadata for the volume."""
309 put_body = json.dumps({'metadata': metadata})
310 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200311 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800312 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000313 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000314 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800315
316 def update_volume_metadata_item(self, volume_id, id, meta_item):
317 """Update metadata item for the volume."""
318 put_body = json.dumps({'meta': meta_item})
319 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200320 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800321 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000322 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000323 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800324
325 def delete_volume_metadata_item(self, volume_id, id):
326 """Delete metadata item for the volume."""
327 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200328 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000329 self.expected_success(200, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000330 return service_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800331
nayna-patel78f743e2015-01-09 10:52:51 +0000332 def retype_volume(self, volume_id, volume_type, **kwargs):
333 """Updates volume with new volume type."""
334 post_body = {'new_type': volume_type}
335 post_body.update(kwargs)
336 post_body = json.dumps({'os-retype': post_body})
337 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
338 self.expected_success(202, resp.status)
339
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800340
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +0000341class VolumesClient(BaseVolumesClient):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800342 """
343 Client class to send CRUD Volume V1 API requests to a Cinder endpoint
344 """