blob: 72823c02cda06ed874decd471543cea744a63c5b [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
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053024
lkuchlanf53947e2016-09-15 10:37:57 +030025class VolumesClient(rest_client.RestClient):
26 """Client class to send CRUD Volume V2 API requests"""
27 api_version = "v2"
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053028
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020029 def _prepare_params(self, params):
30 """Prepares params for use in get or _ext_get methods.
31
32 If params is a string it will be left as it is, but if it's not it will
33 be urlencoded.
34 """
35 if isinstance(params, six.string_types):
36 return params
37 return urllib.urlencode(params)
38
John Warren6177c9e2015-08-19 20:00:17 +000039 def list_volumes(self, detail=False, params=None):
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020040 """List all the volumes created.
41
42 Params can be a string (must be urlencoded) or a dictionary.
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020043 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070044 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000045 if detail:
46 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050047 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020048 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053049
John Warren6177c9e2015-08-19 20:00:17 +000050 resp, body = self.get(url)
51 body = json.loads(body)
52 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080053 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053054
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000055 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050056 """Returns the details of a single volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080057 url = "volumes/%s" % volume_id
Attila Fazekasb8aa7592013-01-26 01:25:45 +010058 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053059 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000060 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080061 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053062
Ghanshyam8fc0ed22015-12-18 10:25:14 +090063 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000064 """Creates a new Volume.
65
Dong Ma127887a2016-10-19 09:09:11 -070066 For a full list of available parameters, please refer to the official
67 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +010068 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053069 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +090070 post_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020071 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053072 body = json.loads(body)
lkuchlanf53947e2016-09-15 10:37:57 +030073 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080074 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053075
QingXin Meng611768a2013-09-18 00:51:33 -070076 def update_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +080077 """Updates the Specified Volume.
78
Dong Ma127887a2016-10-19 09:09:11 -070079 For a full list of available parameters, please refer to the official
80 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +010081 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume
guo xiand8bc1cd2016-06-23 12:35:43 +080082 """
QingXin Meng611768a2013-09-18 00:51:33 -070083 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020084 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -070085 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000086 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080087 return rest_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -070088
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053089 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050090 """Deletes the Specified Volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080091 resp, body = self.delete("volumes/%s" % volume_id)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000092 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080093 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053094
Ghanshyam8fc0ed22015-12-18 10:25:14 +090095 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +020096 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +090097 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +020098 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020099 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200100 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000101 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800102 return rest_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200103
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900104 def attach_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800105 """Attaches a volume to a given instance on a given mountpoint.
106
Dong Ma127887a2016-10-19 09:09:11 -0700107 For a full list of available parameters, please refer to the official
108 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800109 http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server
guo xiand8bc1cd2016-06-23 12:35:43 +0800110 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900111 post_body = json.dumps({'os-attach': kwargs})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700112 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200113 resp, body = self.post(url, post_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)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700116
Ghanshyam58a9e872015-12-18 10:46:07 +0900117 def set_bootable_volume(self, volume_id, **kwargs):
bkopilov8a657ae2015-05-11 11:45:23 +0300118 """set a bootable flag for a volume - true or false."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900119 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300120 url = 'volumes/%s/action' % (volume_id)
121 resp, body = self.post(url, post_body)
122 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800123 return rest_client.ResponseBody(resp, body)
bkopilov8a657ae2015-05-11 11:45:23 +0300124
Rohit Karajgia42fe442012-09-21 03:08:33 -0700125 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500126 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900127 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700128 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200129 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000130 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800131 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700132
zhangyanzi6b632432013-10-24 19:08:50 +0800133 def reserve_volume(self, volume_id):
134 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900135 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800136 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200137 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000138 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800139 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800140
141 def unreserve_volume(self, volume_id):
142 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900143 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800144 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200145 resp, body = self.post(url, post_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)
zhangyanzi6b632432013-10-24 19:08:50 +0800148
David Kranz6aceb4a2012-06-05 14:05:45 -0400149 def is_resource_deleted(self, id):
150 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000151 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900152 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400153 return True
154 return False
wanghao5b981752013-10-22 11:41:41 +0800155
Matt Riedemannd2b96512014-10-13 10:18:16 -0700156 @property
157 def resource_type(self):
158 """Returns the primary type of resource this client works with."""
159 return 'volume'
160
Ghanshyam58a9e872015-12-18 10:46:07 +0900161 def extend_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800162 """Extend a volume.
163
Dong Ma127887a2016-10-19 09:09:11 -0700164 For a full list of available parameters, please refer to the official
165 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800166 http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size
guo xiand8bc1cd2016-06-23 12:35:43 +0800167 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900168 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +0800169 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200170 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000171 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800172 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800173
Ghanshyam58a9e872015-12-18 10:46:07 +0900174 def reset_volume_status(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800175 """Reset the Specified Volume's Status.
176
Dong Ma127887a2016-10-19 09:09:11 -0700177 For a full list of available parameters, please refer to the official
178 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800179 http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses
guo xiand8bc1cd2016-06-23 12:35:43 +0800180 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900181 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200182 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000183 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800184 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800185
Ghanshyam58a9e872015-12-18 10:46:07 +0900186 def create_volume_transfer(self, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800187 """Create a volume transfer.
188
Dong Ma127887a2016-10-19 09:09:11 -0700189 For a full list of available parameters, please refer to the official
190 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +0100191 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-transfer
guo xiand8bc1cd2016-06-23 12:35:43 +0800192 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900193 post_body = json.dumps({'transfer': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200194 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800195 body = json.loads(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)
wingwjcbd82dc2013-10-22 16:38:39 +0800198
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000199 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800200 """Returns the details of a volume transfer."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800201 url = "os-volume-transfer/%s" % transfer_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200202 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800203 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000204 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800205 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800206
Ghanshyam58a9e872015-12-18 10:46:07 +0900207 def list_volume_transfers(self, **params):
guo xiand8bc1cd2016-06-23 12:35:43 +0800208 """List all the volume transfers created.
209
Dong Ma127887a2016-10-19 09:09:11 -0700210 For a full list of available parameters, please refer to the official
211 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +0100212 http://developer.openstack.org/api-ref/block-storage/v2/#list-volume-transfers
guo xiand8bc1cd2016-06-23 12:35:43 +0800213 """
wingwjcbd82dc2013-10-22 16:38:39 +0800214 url = 'os-volume-transfer'
215 if params:
216 url += '?%s' % urllib.urlencode(params)
217 resp, body = self.get(url)
218 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000219 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800220 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800221
222 def delete_volume_transfer(self, transfer_id):
223 """Delete a volume transfer."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800224 resp, body = self.delete("os-volume-transfer/%s" % transfer_id)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000225 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800226 return rest_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800227
Ghanshyam58a9e872015-12-18 10:46:07 +0900228 def accept_volume_transfer(self, transfer_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800229 """Accept a volume transfer.
230
Dong Ma127887a2016-10-19 09:09:11 -0700231 For a full list of available parameters, please refer to the official
232 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +0100233 http://developer.openstack.org/api-ref/block-storage/v2/#accept-volume-transfer
guo xiand8bc1cd2016-06-23 12:35:43 +0800234 """
wingwjcbd82dc2013-10-22 16:38:39 +0800235 url = 'os-volume-transfer/%s/accept' % transfer_id
Ghanshyam58a9e872015-12-18 10:46:07 +0900236 post_body = json.dumps({'accept': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200237 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800238 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000239 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800240 return rest_client.ResponseBody(resp, body)
zhangyanziaa180072013-11-21 12:31:26 +0800241
Ghanshyam58a9e872015-12-18 10:46:07 +0900242 def update_volume_readonly(self, volume_id, **kwargs):
zhangyanziaa180072013-11-21 12:31:26 +0800243 """Update the Specified Volume readonly."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900244 post_body = json.dumps({'os-update_readonly_flag': kwargs})
zhangyanziaa180072013-11-21 12:31:26 +0800245 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200246 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000247 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800248 return rest_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800249
250 def force_delete_volume(self, volume_id):
251 """Force Delete Volume."""
252 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200253 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000254 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800255 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800256
257 def create_volume_metadata(self, volume_id, metadata):
258 """Create metadata for the volume."""
259 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800260 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200261 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800262 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000263 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800264 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800265
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000266 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800267 """Get metadata of the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800268 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200269 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800270 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000271 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800272 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800273
274 def update_volume_metadata(self, volume_id, metadata):
275 """Update metadata for the volume."""
276 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800277 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200278 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800279 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000280 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800281 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800282
283 def update_volume_metadata_item(self, volume_id, id, meta_item):
284 """Update metadata item for the volume."""
285 put_body = json.dumps({'meta': meta_item})
guo yunxian6cdf0562016-08-17 16:21:52 +0800286 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200287 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800288 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000289 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800290 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800291
292 def delete_volume_metadata_item(self, volume_id, id):
293 """Delete metadata item for the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800294 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200295 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000296 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800297 return rest_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800298
Ghanshyam58a9e872015-12-18 10:46:07 +0900299 def retype_volume(self, volume_id, **kwargs):
nayna-patel78f743e2015-01-09 10:52:51 +0000300 """Updates volume with new volume type."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900301 post_body = json.dumps({'os-retype': kwargs})
nayna-patel78f743e2015-01-09 10:52:51 +0000302 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
303 self.expected_success(202, resp.status)
lkuchlanf53947e2016-09-15 10:37:57 +0300304
305 def update_volume_image_metadata(self, volume_id, **kwargs):
306 """Update image metadata for the volume.
307
Dong Ma127887a2016-10-19 09:09:11 -0700308 For a full list of available parameters, please refer to the official
309 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800310 http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume
lkuchlanf53947e2016-09-15 10:37:57 +0300311 """
312 post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}})
313 url = "volumes/%s/action" % (volume_id)
314 resp, body = self.post(url, post_body)
315 body = json.loads(body)
316 self.expected_success(200, resp.status)
317 return rest_client.ResponseBody(resp, body)
318
319 def delete_volume_image_metadata(self, volume_id, key_name):
320 """Delete image metadata item for the volume."""
321 post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}})
322 url = "volumes/%s/action" % (volume_id)
323 resp, body = self.post(url, post_body)
324 self.expected_success(200, resp.status)
325 return rest_client.ResponseBody(resp, body)
326
lkuchlan7bba16c2016-09-04 12:36:04 +0300327 @removals.remove(message="use show_pools from tempest.lib.services."
328 "volume.v2.scheduler_stats_client")
lkuchlanf53947e2016-09-15 10:37:57 +0300329 def show_pools(self, detail=False):
330 # List all the volumes pools (hosts)
331 url = 'scheduler-stats/get_pools'
332 if detail:
333 url += '?detail=True'
334
335 resp, body = self.get(url)
336 body = json.loads(body)
337 self.expected_success(200, resp.status)
338 return rest_client.ResponseBody(resp, body)
339
lkuchlan7bba16c2016-09-04 12:36:04 +0300340 @removals.remove(message="use show_backend_capabilities from tempest.lib."
341 "services.volume.v2.capabilities_client")
lkuchlanf53947e2016-09-15 10:37:57 +0300342 def show_backend_capabilities(self, host):
343 """Shows capabilities for a storage back end.
344
Dong Ma127887a2016-10-19 09:09:11 -0700345 For a full list of available parameters, please refer to the official
346 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800347 http://developer.openstack.org/api-ref/block-storage/v2/#show-back-end-capabilities
lkuchlanf53947e2016-09-15 10:37:57 +0300348 """
349 url = 'capabilities/%s' % host
350 resp, body = self.get(url)
351 body = json.loads(body)
352 self.expected_success(200, resp.status)
353 return rest_client.ResponseBody(resp, body)
jeremy.zhangf4fbf302017-03-22 11:25:53 +0800354
355 def unmanage_volume(self, volume_id):
356 """Unmanage volume.
357
358 For a full list of available parameters, please refer to the official
359 API reference:
360 https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume
361 """
362 post_body = json.dumps({'os-unmanage': {}})
363 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
364 self.expected_success(202, resp.status)
365 return rest_client.ResponseBody(resp, body)