blob: 5c0c7f7a9727869e1d545d0453431ae42a45565a [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 +090019
Joseph Lanoux6809bab2014-12-18 14:57:18 +000020from tempest.common import service_client
Ken'ichi Ohmichib942be62015-07-08 08:16:12 +000021from tempest.common import waiters
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050022from tempest.lib import exceptions as lib_exc
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
Ghanshyam8fc0ed22015-12-18 10:25:14 +090074 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000075 """Creates a new Volume.
76
Ghanshyam8fc0ed22015-12-18 10:25:14 +090077 Available params: see http://developer.openstack.org/
78 api-ref-blockstorage-v2.html#createVolume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053079 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +090080 if 'size' not in kwargs:
81 kwargs['size'] = self.default_volume_size
82 post_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020083 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053084 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000085 self.expected_success(self.create_resp, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +000086 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053087
QingXin Meng611768a2013-09-18 00:51:33 -070088 def update_volume(self, volume_id, **kwargs):
89 """Updates the Specified Volume."""
90 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020091 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -070092 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000093 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +000094 return service_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -070095
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053096 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050097 """Deletes the Specified Volume."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000098 resp, body = self.delete("volumes/%s" % str(volume_id))
99 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000100 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530101
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900102 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200103 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900104 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +0200105 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200106 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200107 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000108 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000109 return service_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200110
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900111 def attach_volume(self, volume_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500112 """Attaches a volume to a given instance on a given mountpoint."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900113 post_body = json.dumps({'os-attach': kwargs})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700114 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200115 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000116 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000117 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700118
Ghanshyam58a9e872015-12-18 10:46:07 +0900119 def set_bootable_volume(self, volume_id, **kwargs):
bkopilov8a657ae2015-05-11 11:45:23 +0300120 """set a bootable flag for a volume - true or false."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900121 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300122 url = 'volumes/%s/action' % (volume_id)
123 resp, body = self.post(url, post_body)
124 self.expected_success(200, resp.status)
125 return service_client.ResponseBody(resp, body)
126
Rohit Karajgia42fe442012-09-21 03:08:33 -0700127 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500128 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900129 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700130 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
zhangyanzi6b632432013-10-24 19:08:50 +0800135 def reserve_volume(self, volume_id):
136 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900137 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800138 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200139 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000140 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000141 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800142
143 def unreserve_volume(self, volume_id):
144 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900145 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800146 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200147 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000148 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000149 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800150
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530151 def wait_for_volume_status(self, volume_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500152 """Waits for a Volume to reach a given status."""
Ken'ichi Ohmichib942be62015-07-08 08:16:12 +0000153 waiters.wait_for_volume_status(self, volume_id, status)
David Kranz6aceb4a2012-06-05 14:05:45 -0400154
155 def is_resource_deleted(self, id):
156 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000157 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900158 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400159 return True
160 return False
wanghao5b981752013-10-22 11:41:41 +0800161
Matt Riedemannd2b96512014-10-13 10:18:16 -0700162 @property
163 def resource_type(self):
164 """Returns the primary type of resource this client works with."""
165 return 'volume'
166
Ghanshyam58a9e872015-12-18 10:46:07 +0900167 def extend_volume(self, volume_id, **kwargs):
wanghao5b981752013-10-22 11:41:41 +0800168 """Extend a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900169 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +0800170 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200171 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000172 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000173 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800174
Ghanshyam58a9e872015-12-18 10:46:07 +0900175 def reset_volume_status(self, volume_id, **kwargs):
wanghaoaa1f2f92013-10-10 11:30:37 +0800176 """Reset the Specified Volume's Status."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900177 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200178 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000179 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000180 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800181
182 def volume_begin_detaching(self, volume_id):
183 """Volume Begin Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000184 # ref cinder/api/contrib/volume_actions.py#L158
wanghaoaa1f2f92013-10-10 11:30:37 +0800185 post_body = json.dumps({'os-begin_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200186 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000187 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000188 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800189
190 def volume_roll_detaching(self, volume_id):
191 """Volume Roll Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000192 # cinder/api/contrib/volume_actions.py#L170
wanghaoaa1f2f92013-10-10 11:30:37 +0800193 post_body = json.dumps({'os-roll_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200194 resp, body = self.post('volumes/%s/action' % volume_id, 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)
wingwjcbd82dc2013-10-22 16:38:39 +0800197
Ghanshyam58a9e872015-12-18 10:46:07 +0900198 def create_volume_transfer(self, **kwargs):
wingwjcbd82dc2013-10-22 16:38:39 +0800199 """Create a volume transfer."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900200 post_body = json.dumps({'transfer': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200201 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800202 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000203 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000204 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800205
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000206 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800207 """Returns the details of a volume transfer."""
208 url = "os-volume-transfer/%s" % str(transfer_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200209 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800210 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000211 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000212 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800213
Ghanshyam58a9e872015-12-18 10:46:07 +0900214 def list_volume_transfers(self, **params):
wingwjcbd82dc2013-10-22 16:38:39 +0800215 """List all the volume transfers created."""
216 url = 'os-volume-transfer'
217 if params:
218 url += '?%s' % urllib.urlencode(params)
219 resp, body = self.get(url)
220 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000221 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000222 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800223
224 def delete_volume_transfer(self, transfer_id):
225 """Delete a volume transfer."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000226 resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id))
227 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000228 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800229
Ghanshyam58a9e872015-12-18 10:46:07 +0900230 def accept_volume_transfer(self, transfer_id, **kwargs):
wingwjcbd82dc2013-10-22 16:38:39 +0800231 """Accept a volume transfer."""
wingwjcbd82dc2013-10-22 16:38:39 +0800232 url = 'os-volume-transfer/%s/accept' % transfer_id
Ghanshyam58a9e872015-12-18 10:46:07 +0900233 post_body = json.dumps({'accept': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200234 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800235 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000236 self.expected_success(202, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000237 return service_client.ResponseBody(resp, body)
zhangyanziaa180072013-11-21 12:31:26 +0800238
Ghanshyam58a9e872015-12-18 10:46:07 +0900239 def update_volume_readonly(self, volume_id, **kwargs):
zhangyanziaa180072013-11-21 12:31:26 +0800240 """Update the Specified Volume readonly."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900241 post_body = json.dumps({'os-update_readonly_flag': kwargs})
zhangyanziaa180072013-11-21 12:31:26 +0800242 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200243 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000244 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000245 return service_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800246
247 def force_delete_volume(self, volume_id):
248 """Force Delete Volume."""
249 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200250 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000251 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000252 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800253
254 def create_volume_metadata(self, volume_id, metadata):
255 """Create metadata for the volume."""
256 put_body = json.dumps({'metadata': metadata})
257 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200258 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800259 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000260 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000261 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800262
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000263 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800264 """Get metadata of the volume."""
265 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200266 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800267 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000268 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000269 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800270
271 def update_volume_metadata(self, volume_id, metadata):
272 """Update metadata for the volume."""
273 put_body = json.dumps({'metadata': metadata})
274 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200275 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800276 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000277 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000278 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800279
280 def update_volume_metadata_item(self, volume_id, id, meta_item):
281 """Update metadata item for the volume."""
282 put_body = json.dumps({'meta': meta_item})
283 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200284 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800285 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000286 self.expected_success(200, resp.status)
John Warren6177c9e2015-08-19 20:00:17 +0000287 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800288
289 def delete_volume_metadata_item(self, volume_id, id):
290 """Delete metadata item for the volume."""
291 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200292 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000293 self.expected_success(200, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000294 return service_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800295
Ghanshyam58a9e872015-12-18 10:46:07 +0900296 def retype_volume(self, volume_id, **kwargs):
nayna-patel78f743e2015-01-09 10:52:51 +0000297 """Updates volume with new volume type."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900298 post_body = json.dumps({'os-retype': kwargs})
nayna-patel78f743e2015-01-09 10:52:51 +0000299 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
300 self.expected_success(202, resp.status)