blob: 62b9992dd47e1be54fd4ff32c84d49462099c6a8 [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
ghanshyam59614b42017-02-24 16:32:02 +000016from debtcollector import moves
lkuchlan7bba16c2016-09-04 12:36:04 +030017from debtcollector import removals
Matthew Treinish21905512015-07-13 10:33:35 -040018from oslo_serialization import jsonutils as json
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020019import six
Matthew Treinish89128142015-04-23 10:44:30 -040020from six.moves.urllib import parse as urllib
Masayuki Igawabfa07602015-01-20 18:47:17 +090021
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080022from tempest.lib.common import rest_client
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050023from tempest.lib import exceptions as lib_exc
zhufl02736522017-06-19 13:57:28 +080024from tempest.lib.services.volume import base_client
ghanshyam59614b42017-02-24 16:32:02 +000025from tempest.lib.services.volume.v2 import transfers_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070026
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053027
zhufl02736522017-06-19 13:57:28 +080028class VolumesClient(base_client.BaseClient):
lkuchlanf53947e2016-09-15 10:37:57 +030029 """Client class to send CRUD Volume V2 API requests"""
30 api_version = "v2"
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053031
ghanshyam59614b42017-02-24 16:32:02 +000032 create_volume_transfer = moves.moved_function(
33 transfers_client.TransfersClient.create_volume_transfer,
34 'VolumesClient.create_volume_transfer', __name__,
35 message='Use create_volume_transfer from new location.',
36 version='Pike', removal_version='Queens')
37
38 show_volume_transfer = moves.moved_function(
39 transfers_client.TransfersClient.show_volume_transfer,
40 'VolumesClient.show_volume_transfer', __name__,
41 message='Use show_volume_transfer from new location.',
42 version='Pike', removal_version='Queens')
43
44 list_volume_transfers = moves.moved_function(
45 transfers_client.TransfersClient.list_volume_transfers,
46 'VolumesClient.list_volume_transfers', __name__,
47 message='Use list_volume_transfer from new location.',
48 version='Pike', removal_version='Queens')
49
50 delete_volume_transfer = moves.moved_function(
51 transfers_client.TransfersClient.delete_volume_transfer,
52 'VolumesClient.delete_volume_transfer', __name__,
53 message='Use delete_volume_transfer from new location.',
54 version='Pike', removal_version='Queens')
55
56 accept_volume_transfer = moves.moved_function(
57 transfers_client.TransfersClient.accept_volume_transfer,
58 'VolumesClient.accept_volume_transfer', __name__,
59 message='Use accept_volume_transfer from new location.',
60 version='Pike', removal_version='Queens')
61
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020062 def _prepare_params(self, params):
63 """Prepares params for use in get or _ext_get methods.
64
65 If params is a string it will be left as it is, but if it's not it will
66 be urlencoded.
67 """
68 if isinstance(params, six.string_types):
69 return params
70 return urllib.urlencode(params)
71
John Warren6177c9e2015-08-19 20:00:17 +000072 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020073 """List all the volumes created.
74
75 Params can be a string (must be urlencoded) or a dictionary.
jeremy.zhang83b3e552017-06-23 15:53:50 +080076 For a full list of available parameters, please refer to the official
77 API reference:
78 http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details
79 http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020080 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070081 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000082 if detail:
83 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050084 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020085 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053086
John Warren6177c9e2015-08-19 20:00:17 +000087 resp, body = self.get(url)
88 body = json.loads(body)
89 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080090 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053091
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000092 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050093 """Returns the details of a single volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080094 url = "volumes/%s" % volume_id
Attila Fazekasb8aa7592013-01-26 01:25:45 +010095 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053096 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000097 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080098 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053099
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900100 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000101 """Creates a new Volume.
102
Dong Ma127887a2016-10-19 09:09:11 -0700103 For a full list of available parameters, please refer to the official
104 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +0100105 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530106 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900107 post_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200108 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530109 body = json.loads(body)
lkuchlanf53947e2016-09-15 10:37:57 +0300110 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800111 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530112
QingXin Meng611768a2013-09-18 00:51:33 -0700113 def update_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800114 """Updates the Specified Volume.
115
Dong Ma127887a2016-10-19 09:09:11 -0700116 For a full list of available parameters, please refer to the official
117 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +0100118 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume
guo xiand8bc1cd2016-06-23 12:35:43 +0800119 """
QingXin Meng611768a2013-09-18 00:51:33 -0700120 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200121 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -0700122 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000123 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800124 return rest_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -0700125
Jordan Pittiercb5f6502017-04-10 14:27:39 +0200126 def delete_volume(self, volume_id, **params):
127 """Deletes the Specified Volume.
128
129 For a full list of available parameters, please refer to the official
130 API reference:
131 https://developer.openstack.org/api-ref/block-storage/v2/#delete-volume
132 """
lkuchlan0e3bbdf2016-07-11 12:06:51 +0300133 url = 'volumes/%s' % volume_id
Jordan Pittiercb5f6502017-04-10 14:27:39 +0200134 if params:
135 url += '?%s' % urllib.urlencode(params)
lkuchlan0e3bbdf2016-07-11 12:06:51 +0300136 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000137 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800138 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530139
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900140 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200141 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900142 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +0200143 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200144 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200145 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000146 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800147 return rest_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200148
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900149 def attach_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800150 """Attaches a volume to a given instance on a given mountpoint.
151
Dong Ma127887a2016-10-19 09:09:11 -0700152 For a full list of available parameters, please refer to the official
153 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800154 http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server
guo xiand8bc1cd2016-06-23 12:35:43 +0800155 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900156 post_body = json.dumps({'os-attach': kwargs})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700157 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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800160 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700161
Ghanshyam58a9e872015-12-18 10:46:07 +0900162 def set_bootable_volume(self, volume_id, **kwargs):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800163 """Set a bootable flag for a volume - true or false.
164
165 For a full list of available parameters, please refer to the official
166 API reference:
167 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-bootable-status
168 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900169 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300170 url = 'volumes/%s/action' % (volume_id)
171 resp, body = self.post(url, post_body)
172 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800173 return rest_client.ResponseBody(resp, body)
bkopilov8a657ae2015-05-11 11:45:23 +0300174
Rohit Karajgia42fe442012-09-21 03:08:33 -0700175 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500176 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900177 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700178 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200179 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000180 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800181 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700182
zhangyanzi6b632432013-10-24 19:08:50 +0800183 def reserve_volume(self, volume_id):
184 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900185 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800186 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200187 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000188 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800189 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800190
191 def unreserve_volume(self, volume_id):
192 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900193 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800194 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200195 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000196 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800197 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800198
David Kranz6aceb4a2012-06-05 14:05:45 -0400199 def is_resource_deleted(self, id):
200 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000201 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900202 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400203 return True
204 return False
wanghao5b981752013-10-22 11:41:41 +0800205
Matt Riedemannd2b96512014-10-13 10:18:16 -0700206 @property
207 def resource_type(self):
208 """Returns the primary type of resource this client works with."""
209 return 'volume'
210
Ghanshyam58a9e872015-12-18 10:46:07 +0900211 def extend_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800212 """Extend a volume.
213
Dong Ma127887a2016-10-19 09:09:11 -0700214 For a full list of available parameters, please refer to the official
215 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800216 http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size
guo xiand8bc1cd2016-06-23 12:35:43 +0800217 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900218 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +0800219 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200220 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000221 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800222 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800223
Ghanshyam58a9e872015-12-18 10:46:07 +0900224 def reset_volume_status(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800225 """Reset the Specified Volume's Status.
226
Dong Ma127887a2016-10-19 09:09:11 -0700227 For a full list of available parameters, please refer to the official
228 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800229 http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses
guo xiand8bc1cd2016-06-23 12:35:43 +0800230 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900231 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200232 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000233 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800234 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800235
Ghanshyam58a9e872015-12-18 10:46:07 +0900236 def update_volume_readonly(self, volume_id, **kwargs):
zhangyanziaa180072013-11-21 12:31:26 +0800237 """Update the Specified Volume readonly."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900238 post_body = json.dumps({'os-update_readonly_flag': kwargs})
zhangyanziaa180072013-11-21 12:31:26 +0800239 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200240 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000241 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800242 return rest_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800243
244 def force_delete_volume(self, volume_id):
245 """Force Delete Volume."""
246 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200247 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000248 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800249 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800250
251 def create_volume_metadata(self, volume_id, metadata):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800252 """Create metadata for the volume.
253
254 For a full list of available parameters, please refer to the official
255 API reference:
256 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-metadata
257 """
huangtianhua0ff41682013-12-16 14:49:31 +0800258 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800259 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200260 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800261 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000262 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800263 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800264
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000265 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800266 """Get metadata of the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800267 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200268 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800269 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000270 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800271 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800272
273 def update_volume_metadata(self, volume_id, metadata):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800274 """Update metadata for the volume.
275
276 For a full list of available parameters, please refer to the official
277 API reference:
278 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-metadata
279 """
huangtianhua0ff41682013-12-16 14:49:31 +0800280 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800281 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200282 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800283 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000284 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800285 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800286
jeremy.zhangb40cb192017-07-04 12:56:59 +0800287 def show_volume_metadata_item(self, volume_id, id):
288 """Show metadata item for the volume."""
289 url = "volumes/%s/metadata/%s" % (volume_id, id)
290 resp, body = self.get(url)
291 body = json.loads(body)
292 self.expected_success(200, resp.status)
293 return rest_client.ResponseBody(resp, body)
294
huangtianhua0ff41682013-12-16 14:49:31 +0800295 def update_volume_metadata_item(self, volume_id, id, meta_item):
296 """Update metadata item for the volume."""
297 put_body = json.dumps({'meta': meta_item})
guo yunxian6cdf0562016-08-17 16:21:52 +0800298 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200299 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800300 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000301 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800302 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800303
304 def delete_volume_metadata_item(self, volume_id, id):
305 """Delete metadata item for the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800306 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200307 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000308 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800309 return rest_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800310
Ghanshyam58a9e872015-12-18 10:46:07 +0900311 def retype_volume(self, volume_id, **kwargs):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800312 """Updates volume with new volume type.
313
314 For a full list of available parameters, please refer to the official
315 API reference:
316 https://developer.openstack.org/api-ref/block-storage/v2/#retype-volume
317 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900318 post_body = json.dumps({'os-retype': kwargs})
nayna-patel78f743e2015-01-09 10:52:51 +0000319 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
320 self.expected_success(202, resp.status)
raigax9d8508822017-07-12 18:31:39 -0400321 return rest_client.ResponseBody(resp, body)
lkuchlanf53947e2016-09-15 10:37:57 +0300322
jeremy.zhang7b0eaf82017-04-25 15:11:15 +0800323 def force_detach_volume(self, volume_id, **kwargs):
324 """Force detach a volume.
325
326 For a full list of available parameters, please refer to the official
327 API reference:
328 https://developer.openstack.org/api-ref/block-storage/v2/#force-detach-volume
329 """
330 post_body = json.dumps({'os-force_detach': kwargs})
331 url = 'volumes/%s/action' % volume_id
332 resp, body = self.post(url, post_body)
333 self.expected_success(202, resp.status)
334 return rest_client.ResponseBody(resp, body)
335
lkuchlanf53947e2016-09-15 10:37:57 +0300336 def update_volume_image_metadata(self, volume_id, **kwargs):
337 """Update image metadata for the volume.
338
Dong Ma127887a2016-10-19 09:09:11 -0700339 For a full list of available parameters, please refer to the official
340 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800341 http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume
lkuchlanf53947e2016-09-15 10:37:57 +0300342 """
343 post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}})
344 url = "volumes/%s/action" % (volume_id)
345 resp, body = self.post(url, post_body)
346 body = json.loads(body)
347 self.expected_success(200, resp.status)
348 return rest_client.ResponseBody(resp, body)
349
350 def delete_volume_image_metadata(self, volume_id, key_name):
351 """Delete image metadata item for the volume."""
352 post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}})
353 url = "volumes/%s/action" % (volume_id)
354 resp, body = self.post(url, post_body)
355 self.expected_success(200, resp.status)
356 return rest_client.ResponseBody(resp, body)
357
Masayuki Igawa2b960982017-06-05 11:16:59 +0900358 @removals.remove(message="use list_pools from tempest.lib.services."
lkuchlan7bba16c2016-09-04 12:36:04 +0300359 "volume.v2.scheduler_stats_client")
lkuchlanf53947e2016-09-15 10:37:57 +0300360 def show_pools(self, detail=False):
361 # List all the volumes pools (hosts)
362 url = 'scheduler-stats/get_pools'
363 if detail:
364 url += '?detail=True'
365
366 resp, body = self.get(url)
367 body = json.loads(body)
368 self.expected_success(200, resp.status)
369 return rest_client.ResponseBody(resp, body)
370
lkuchlan7bba16c2016-09-04 12:36:04 +0300371 @removals.remove(message="use show_backend_capabilities from tempest.lib."
372 "services.volume.v2.capabilities_client")
lkuchlanf53947e2016-09-15 10:37:57 +0300373 def show_backend_capabilities(self, host):
374 """Shows capabilities for a storage back end.
375
Dong Ma127887a2016-10-19 09:09:11 -0700376 For a full list of available parameters, please refer to the official
377 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800378 http://developer.openstack.org/api-ref/block-storage/v2/#show-back-end-capabilities
lkuchlanf53947e2016-09-15 10:37:57 +0300379 """
380 url = 'capabilities/%s' % host
381 resp, body = self.get(url)
382 body = json.loads(body)
383 self.expected_success(200, resp.status)
384 return rest_client.ResponseBody(resp, body)
jeremy.zhangf4fbf302017-03-22 11:25:53 +0800385
386 def unmanage_volume(self, volume_id):
387 """Unmanage volume.
388
389 For a full list of available parameters, please refer to the official
390 API reference:
391 https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume
392 """
393 post_body = json.dumps({'os-unmanage': {}})
394 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
395 self.expected_success(202, resp.status)
396 return rest_client.ResponseBody(resp, body)