blob: 79973ee14ea593632bb24176a0d5be42921580d5 [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
lkuchlan7bba16c2016-09-04 12:36:04 +030016from debtcollector import removals
Matthew Treinish21905512015-07-13 10:33:35 -040017from oslo_serialization import jsonutils as json
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020018import six
Matthew Treinish89128142015-04-23 10:44:30 -040019from six.moves.urllib import parse as urllib
Masayuki Igawabfa07602015-01-20 18:47:17 +090020
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080021from tempest.lib.common import rest_client
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050022from tempest.lib import exceptions as lib_exc
zhufl02736522017-06-19 13:57:28 +080023from tempest.lib.services.volume import base_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070024
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053025
zhufl02736522017-06-19 13:57:28 +080026class VolumesClient(base_client.BaseClient):
lkuchlanf53947e2016-09-15 10:37:57 +030027 """Client class to send CRUD Volume V2 API requests"""
28 api_version = "v2"
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053029
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020030 def _prepare_params(self, params):
31 """Prepares params for use in get or _ext_get methods.
32
33 If params is a string it will be left as it is, but if it's not it will
34 be urlencoded.
35 """
36 if isinstance(params, six.string_types):
37 return params
38 return urllib.urlencode(params)
39
John Warren6177c9e2015-08-19 20:00:17 +000040 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020041 """List all the volumes created.
42
43 Params can be a string (must be urlencoded) or a dictionary.
jeremy.zhang83b3e552017-06-23 15:53:50 +080044 For a full list of available parameters, please refer to the official
45 API reference:
46 http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details
47 http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020048 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070049 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000050 if detail:
51 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050052 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020053 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053054
John Warren6177c9e2015-08-19 20:00:17 +000055 resp, body = self.get(url)
56 body = json.loads(body)
57 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080058 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053059
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000060 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050061 """Returns the details of a single volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080062 url = "volumes/%s" % volume_id
Attila Fazekasb8aa7592013-01-26 01:25:45 +010063 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053064 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000065 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080066 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053067
Ghanshyam8fc0ed22015-12-18 10:25:14 +090068 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000069 """Creates a new Volume.
70
Dong Ma127887a2016-10-19 09:09:11 -070071 For a full list of available parameters, please refer to the official
72 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +010073 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053074 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +090075 post_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020076 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053077 body = json.loads(body)
lkuchlanf53947e2016-09-15 10:37:57 +030078 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080079 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053080
QingXin Meng611768a2013-09-18 00:51:33 -070081 def update_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +080082 """Updates the Specified Volume.
83
Dong Ma127887a2016-10-19 09:09:11 -070084 For a full list of available parameters, please refer to the official
85 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +010086 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume
guo xiand8bc1cd2016-06-23 12:35:43 +080087 """
QingXin Meng611768a2013-09-18 00:51:33 -070088 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020089 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -070090 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000091 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080092 return rest_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -070093
Jordan Pittiercb5f6502017-04-10 14:27:39 +020094 def delete_volume(self, volume_id, **params):
95 """Deletes the Specified Volume.
96
97 For a full list of available parameters, please refer to the official
98 API reference:
99 https://developer.openstack.org/api-ref/block-storage/v2/#delete-volume
100 """
lkuchlan0e3bbdf2016-07-11 12:06:51 +0300101 url = 'volumes/%s' % volume_id
Jordan Pittiercb5f6502017-04-10 14:27:39 +0200102 if params:
103 url += '?%s' % urllib.urlencode(params)
lkuchlan0e3bbdf2016-07-11 12:06:51 +0300104 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000105 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800106 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530107
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900108 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900110 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +0200111 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200112 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200113 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000114 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800115 return rest_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200116
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900117 def attach_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800118 """Attaches a volume to a given instance on a given mountpoint.
119
Dong Ma127887a2016-10-19 09:09:11 -0700120 For a full list of available parameters, please refer to the official
121 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800122 http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server
guo xiand8bc1cd2016-06-23 12:35:43 +0800123 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900124 post_body = json.dumps({'os-attach': kwargs})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700125 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200126 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000127 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800128 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700129
Ghanshyam58a9e872015-12-18 10:46:07 +0900130 def set_bootable_volume(self, volume_id, **kwargs):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800131 """Set a bootable flag for a volume - true or false.
132
133 For a full list of available parameters, please refer to the official
134 API reference:
135 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-bootable-status
136 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900137 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300138 url = 'volumes/%s/action' % (volume_id)
139 resp, body = self.post(url, post_body)
140 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800141 return rest_client.ResponseBody(resp, body)
bkopilov8a657ae2015-05-11 11:45:23 +0300142
Rohit Karajgia42fe442012-09-21 03:08:33 -0700143 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500144 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900145 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700146 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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800149 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700150
zhangyanzi6b632432013-10-24 19:08:50 +0800151 def reserve_volume(self, volume_id):
152 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900153 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800154 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200155 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000156 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800157 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800158
159 def unreserve_volume(self, volume_id):
160 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900161 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800162 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200163 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000164 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800165 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800166
David Kranz6aceb4a2012-06-05 14:05:45 -0400167 def is_resource_deleted(self, id):
Ken'ichi Ohmichi4723fde2017-04-26 14:19:57 -0700168 """Check the specified resource is deleted or not.
169
170 :param id: A checked resource id
171 :raises lib_exc.DeleteErrorException: If the specified resource is on
172 the status the delete was failed.
173 """
David Kranz6aceb4a2012-06-05 14:05:45 -0400174 try:
Ken'ichi Ohmichi4723fde2017-04-26 14:19:57 -0700175 volume = self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900176 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400177 return True
Ken'ichi Ohmichi4723fde2017-04-26 14:19:57 -0700178 if volume["volume"]["status"] == "error_deleting":
179 raise lib_exc.DeleteErrorException(resource_id=id)
David Kranz6aceb4a2012-06-05 14:05:45 -0400180 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
Ghanshyam58a9e872015-12-18 10:46:07 +0900187 def extend_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800188 """Extend a volume.
189
Dong Ma127887a2016-10-19 09:09:11 -0700190 For a full list of available parameters, please refer to the official
191 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800192 http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size
guo xiand8bc1cd2016-06-23 12:35:43 +0800193 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900194 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +0800195 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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800198 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800199
Ghanshyam58a9e872015-12-18 10:46:07 +0900200 def reset_volume_status(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800201 """Reset the Specified Volume's Status.
202
Dong Ma127887a2016-10-19 09:09:11 -0700203 For a full list of available parameters, please refer to the official
204 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800205 http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses
guo xiand8bc1cd2016-06-23 12:35:43 +0800206 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900207 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200208 resp, body = self.post('volumes/%s/action' % volume_id, post_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)
wanghaoaa1f2f92013-10-10 11:30:37 +0800211
Ghanshyam58a9e872015-12-18 10:46:07 +0900212 def update_volume_readonly(self, volume_id, **kwargs):
zhangyanziaa180072013-11-21 12:31:26 +0800213 """Update the Specified Volume readonly."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900214 post_body = json.dumps({'os-update_readonly_flag': kwargs})
zhangyanziaa180072013-11-21 12:31:26 +0800215 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200216 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000217 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800218 return rest_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800219
220 def force_delete_volume(self, volume_id):
221 """Force Delete Volume."""
222 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200223 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000224 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800225 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800226
227 def create_volume_metadata(self, volume_id, metadata):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800228 """Create metadata for the volume.
229
230 For a full list of available parameters, please refer to the official
231 API reference:
232 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-metadata
233 """
huangtianhua0ff41682013-12-16 14:49:31 +0800234 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800235 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200236 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800237 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000238 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800239 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800240
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000241 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800242 """Get metadata of the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800243 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200244 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800245 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000246 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800247 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800248
249 def update_volume_metadata(self, volume_id, metadata):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800250 """Update metadata for the volume.
251
252 For a full list of available parameters, please refer to the official
253 API reference:
254 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-metadata
255 """
huangtianhua0ff41682013-12-16 14:49:31 +0800256 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800257 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200258 resp, body = self.put(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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800261 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800262
jeremy.zhangb40cb192017-07-04 12:56:59 +0800263 def show_volume_metadata_item(self, volume_id, id):
264 """Show metadata item for the volume."""
265 url = "volumes/%s/metadata/%s" % (volume_id, id)
266 resp, body = self.get(url)
267 body = json.loads(body)
268 self.expected_success(200, resp.status)
269 return rest_client.ResponseBody(resp, body)
270
huangtianhua0ff41682013-12-16 14:49:31 +0800271 def update_volume_metadata_item(self, volume_id, id, meta_item):
272 """Update metadata item for the volume."""
273 put_body = json.dumps({'meta': meta_item})
guo yunxian6cdf0562016-08-17 16:21:52 +0800274 url = "volumes/%s/metadata/%s" % (volume_id, 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)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800278 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800279
280 def delete_volume_metadata_item(self, volume_id, id):
281 """Delete metadata item for the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800282 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200283 resp, body = self.delete(url)
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)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800286
Ghanshyam58a9e872015-12-18 10:46:07 +0900287 def retype_volume(self, volume_id, **kwargs):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800288 """Updates volume with new volume type.
289
290 For a full list of available parameters, please refer to the official
291 API reference:
292 https://developer.openstack.org/api-ref/block-storage/v2/#retype-volume
293 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900294 post_body = json.dumps({'os-retype': kwargs})
nayna-patel78f743e2015-01-09 10:52:51 +0000295 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
296 self.expected_success(202, resp.status)
raigax9d8508822017-07-12 18:31:39 -0400297 return rest_client.ResponseBody(resp, body)
lkuchlanf53947e2016-09-15 10:37:57 +0300298
jeremy.zhang7b0eaf82017-04-25 15:11:15 +0800299 def force_detach_volume(self, volume_id, **kwargs):
300 """Force detach a volume.
301
302 For a full list of available parameters, please refer to the official
303 API reference:
304 https://developer.openstack.org/api-ref/block-storage/v2/#force-detach-volume
305 """
306 post_body = json.dumps({'os-force_detach': kwargs})
307 url = 'volumes/%s/action' % volume_id
308 resp, body = self.post(url, post_body)
309 self.expected_success(202, resp.status)
310 return rest_client.ResponseBody(resp, body)
311
lkuchlanf53947e2016-09-15 10:37:57 +0300312 def update_volume_image_metadata(self, volume_id, **kwargs):
313 """Update image metadata for the volume.
314
Dong Ma127887a2016-10-19 09:09:11 -0700315 For a full list of available parameters, please refer to the official
316 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800317 http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume
lkuchlanf53947e2016-09-15 10:37:57 +0300318 """
319 post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}})
320 url = "volumes/%s/action" % (volume_id)
321 resp, body = self.post(url, post_body)
322 body = json.loads(body)
323 self.expected_success(200, resp.status)
324 return rest_client.ResponseBody(resp, body)
325
326 def delete_volume_image_metadata(self, volume_id, key_name):
327 """Delete image metadata item for the volume."""
328 post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}})
329 url = "volumes/%s/action" % (volume_id)
330 resp, body = self.post(url, post_body)
331 self.expected_success(200, resp.status)
332 return rest_client.ResponseBody(resp, body)
333
jeremy.zhangf0599b12017-08-03 20:02:51 +0800334 def show_volume_image_metadata(self, volume_id):
335 """Show image metadata for the volume."""
336 post_body = json.dumps({'os-show_image_metadata': {}})
337 url = "volumes/%s/action" % volume_id
338 resp, body = self.post(url, post_body)
339 body = json.loads(body)
340 self.expected_success(200, resp.status)
341 return rest_client.ResponseBody(resp, body)
342
Masayuki Igawa2b960982017-06-05 11:16:59 +0900343 @removals.remove(message="use list_pools from tempest.lib.services."
lkuchlan7bba16c2016-09-04 12:36:04 +0300344 "volume.v2.scheduler_stats_client")
lkuchlanf53947e2016-09-15 10:37:57 +0300345 def show_pools(self, detail=False):
346 # List all the volumes pools (hosts)
347 url = 'scheduler-stats/get_pools'
348 if detail:
349 url += '?detail=True'
350
351 resp, body = self.get(url)
352 body = json.loads(body)
353 self.expected_success(200, resp.status)
354 return rest_client.ResponseBody(resp, body)
355
lkuchlan7bba16c2016-09-04 12:36:04 +0300356 @removals.remove(message="use show_backend_capabilities from tempest.lib."
357 "services.volume.v2.capabilities_client")
lkuchlanf53947e2016-09-15 10:37:57 +0300358 def show_backend_capabilities(self, host):
359 """Shows capabilities for a storage back end.
360
Dong Ma127887a2016-10-19 09:09:11 -0700361 For a full list of available parameters, please refer to the official
362 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800363 http://developer.openstack.org/api-ref/block-storage/v2/#show-back-end-capabilities
lkuchlanf53947e2016-09-15 10:37:57 +0300364 """
365 url = 'capabilities/%s' % host
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)
jeremy.zhangf4fbf302017-03-22 11:25:53 +0800370
371 def unmanage_volume(self, volume_id):
372 """Unmanage volume.
373
374 For a full list of available parameters, please refer to the official
375 API reference:
376 https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume
377 """
378 post_body = json.dumps({'os-unmanage': {}})
379 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
380 self.expected_success(202, resp.status)
381 return rest_client.ResponseBody(resp, body)