blob: a3a4eb605115b916b01d914ea251918fa88da07f [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
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
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080024class BaseVolumesClient(rest_client.RestClient):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000025 """Base client class to send CRUD Volume API requests"""
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053026
Ken'ichi Ohmichia39d0be2014-12-17 08:46:11 +000027 create_resp = 200
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053028
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000029 def __init__(self, auth_provider, service, region,
30 default_volume_size=1, **kwargs):
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000031 super(BaseVolumesClient, self).__init__(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000032 auth_provider, service, region, **kwargs)
33 self.default_volume_size = default_volume_size
34
anju tiwari789449a2013-08-29 16:56:17 +053035 def get_attachment_from_volume(self, volume):
36 """Return the element 'attachment' from input volumes."""
37 return volume['attachments'][0]
38
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020039 def _prepare_params(self, params):
40 """Prepares params for use in get or _ext_get methods.
41
42 If params is a string it will be left as it is, but if it's not it will
43 be urlencoded.
44 """
45 if isinstance(params, six.string_types):
46 return params
47 return urllib.urlencode(params)
48
John Warren6177c9e2015-08-19 20:00:17 +000049 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020050 """List all the volumes created.
51
52 Params can be a string (must be urlencoded) or a dictionary.
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020053 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070054 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000055 if detail:
56 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050057 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020058 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053059
John Warren6177c9e2015-08-19 20:00:17 +000060 resp, body = self.get(url)
61 body = json.loads(body)
62 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080063 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053064
bkopilov1f161e52016-04-18 13:27:48 +030065 def show_pools(self, detail=False):
66 # List all the volumes pools (hosts)
67 url = 'scheduler-stats/get_pools'
68 if detail:
69 url += '?detail=True'
70
71 resp, body = self.get(url)
72 body = json.loads(body)
73 self.expected_success(200, resp.status)
74 return rest_client.ResponseBody(resp, body)
75
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000076 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050077 """Returns the details of a single volume."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070078 url = "volumes/%s" % str(volume_id)
Attila Fazekasb8aa7592013-01-26 01:25:45 +010079 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053080 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000081 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080082 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053083
Ghanshyam8fc0ed22015-12-18 10:25:14 +090084 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000085 """Creates a new Volume.
86
Ghanshyam8fc0ed22015-12-18 10:25:14 +090087 Available params: see http://developer.openstack.org/
88 api-ref-blockstorage-v2.html#createVolume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053089 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +090090 if 'size' not in kwargs:
91 kwargs['size'] = self.default_volume_size
92 post_body = json.dumps({'volume': kwargs})
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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080096 return rest_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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800104 return rest_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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800110 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530111
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900112 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200113 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900114 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +0200115 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200116 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200117 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000118 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800119 return rest_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200120
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900121 def attach_volume(self, volume_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500122 """Attaches a volume to a given instance on a given mountpoint."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900123 post_body = json.dumps({'os-attach': kwargs})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700124 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200125 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000126 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800127 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700128
Ghanshyam58a9e872015-12-18 10:46:07 +0900129 def set_bootable_volume(self, volume_id, **kwargs):
bkopilov8a657ae2015-05-11 11:45:23 +0300130 """set a bootable flag for a volume - true or false."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900131 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300132 url = 'volumes/%s/action' % (volume_id)
133 resp, body = self.post(url, post_body)
134 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800135 return rest_client.ResponseBody(resp, body)
bkopilov8a657ae2015-05-11 11:45:23 +0300136
Rohit Karajgia42fe442012-09-21 03:08:33 -0700137 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500138 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900139 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700140 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200141 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000142 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800143 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700144
zhangyanzi6b632432013-10-24 19:08:50 +0800145 def reserve_volume(self, volume_id):
146 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900147 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800148 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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800151 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800152
153 def unreserve_volume(self, volume_id):
154 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900155 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800156 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200157 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000158 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800159 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800160
David Kranz6aceb4a2012-06-05 14:05:45 -0400161 def is_resource_deleted(self, id):
162 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000163 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900164 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400165 return True
166 return False
wanghao5b981752013-10-22 11:41:41 +0800167
Matt Riedemannd2b96512014-10-13 10:18:16 -0700168 @property
169 def resource_type(self):
170 """Returns the primary type of resource this client works with."""
171 return 'volume'
172
Ghanshyam58a9e872015-12-18 10:46:07 +0900173 def extend_volume(self, volume_id, **kwargs):
wanghao5b981752013-10-22 11:41:41 +0800174 """Extend a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900175 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +0800176 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200177 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000178 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800179 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800180
Ghanshyam58a9e872015-12-18 10:46:07 +0900181 def reset_volume_status(self, volume_id, **kwargs):
wanghaoaa1f2f92013-10-10 11:30:37 +0800182 """Reset the Specified Volume's Status."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900183 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200184 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000185 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800186 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800187
188 def volume_begin_detaching(self, volume_id):
189 """Volume Begin Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000190 # ref cinder/api/contrib/volume_actions.py#L158
wanghaoaa1f2f92013-10-10 11:30:37 +0800191 post_body = json.dumps({'os-begin_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200192 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000193 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800194 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800195
196 def volume_roll_detaching(self, volume_id):
197 """Volume Roll Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000198 # cinder/api/contrib/volume_actions.py#L170
wanghaoaa1f2f92013-10-10 11:30:37 +0800199 post_body = json.dumps({'os-roll_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200200 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000201 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800202 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800203
Ghanshyam58a9e872015-12-18 10:46:07 +0900204 def create_volume_transfer(self, **kwargs):
wingwjcbd82dc2013-10-22 16:38:39 +0800205 """Create a volume transfer."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900206 post_body = json.dumps({'transfer': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200207 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800208 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000209 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800210 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800211
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000212 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800213 """Returns the details of a volume transfer."""
214 url = "os-volume-transfer/%s" % str(transfer_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200215 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800216 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000217 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800218 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800219
Ghanshyam58a9e872015-12-18 10:46:07 +0900220 def list_volume_transfers(self, **params):
wingwjcbd82dc2013-10-22 16:38:39 +0800221 """List all the volume transfers created."""
222 url = 'os-volume-transfer'
223 if params:
224 url += '?%s' % urllib.urlencode(params)
225 resp, body = self.get(url)
226 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000227 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800228 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800229
230 def delete_volume_transfer(self, transfer_id):
231 """Delete a volume transfer."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000232 resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id))
233 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800234 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800235
Ghanshyam58a9e872015-12-18 10:46:07 +0900236 def accept_volume_transfer(self, transfer_id, **kwargs):
wingwjcbd82dc2013-10-22 16:38:39 +0800237 """Accept a volume transfer."""
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})
263 url = "volumes/%s/metadata" % str(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."""
271 url = "volumes/%s/metadata" % str(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})
280 url = "volumes/%s/metadata" % str(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})
289 url = "volumes/%s/metadata/%s" % (str(volume_id), str(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."""
297 url = "volumes/%s/metadata/%s" % (str(volume_id), str(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
lkuchlan119b2f22016-06-20 20:59:41 +0300302 def update_volume_image_metadata(self, volume_id, **kwargs):
303 """Update image metadata for the volume."""
304 post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}})
305 url = "volumes/%s/action" % (volume_id)
306 resp, body = self.post(url, post_body)
307 body = json.loads(body)
308 self.expected_success(200, resp.status)
309 return rest_client.ResponseBody(resp, body)
310
311 def delete_volume_image_metadata(self, volume_id, key_name):
312 """Delete image metadata item for the volume."""
313 post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}})
314 url = "volumes/%s/action" % (volume_id)
315 resp, body = self.post(url, post_body)
316 self.expected_success(200, resp.status)
317 return rest_client.ResponseBody(resp, body)
318
Ghanshyam58a9e872015-12-18 10:46:07 +0900319 def retype_volume(self, volume_id, **kwargs):
nayna-patel78f743e2015-01-09 10:52:51 +0000320 """Updates volume with new volume type."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900321 post_body = json.dumps({'os-retype': kwargs})
nayna-patel78f743e2015-01-09 10:52:51 +0000322 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
323 self.expected_success(202, resp.status)