blob: da3f2b53aa8c60093a6f09e864e2cf46f21a6309 [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
zhufl02736522017-06-19 13:57:28 +080022from tempest.lib.services.volume import base_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053024
zhufl02736522017-06-19 13:57:28 +080025class VolumesClient(base_client.BaseClient):
lkuchlanf53947e2016-09-15 10:37:57 +030026 """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.
jeremy.zhang83b3e552017-06-23 15:53:50 +080043 For a full list of available parameters, please refer to the official
44 API reference:
45 http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes-with-details
46 http://developer.openstack.org/api-ref/block-storage/v2/#list-volumes
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020047 """
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070048 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000049 if detail:
50 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050051 if params:
Gorka Eguileor0ea58af2015-06-17 18:32:42 +020052 url += '?%s' % self._prepare_params(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053053
John Warren6177c9e2015-08-19 20:00:17 +000054 resp, body = self.get(url)
55 body = json.loads(body)
56 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080057 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053058
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000059 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050060 """Returns the details of a single volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +080061 url = "volumes/%s" % volume_id
Attila Fazekasb8aa7592013-01-26 01:25:45 +010062 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053063 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000064 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080065 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053066
Ghanshyam8fc0ed22015-12-18 10:25:14 +090067 def create_volume(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000068 """Creates a new Volume.
69
Dong Ma127887a2016-10-19 09:09:11 -070070 For a full list of available parameters, please refer to the official
71 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +010072 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053073 """
Ghanshyam8fc0ed22015-12-18 10:25:14 +090074 post_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020075 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053076 body = json.loads(body)
lkuchlanf53947e2016-09-15 10:37:57 +030077 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080078 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053079
QingXin Meng611768a2013-09-18 00:51:33 -070080 def update_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +080081 """Updates the Specified Volume.
82
Dong Ma127887a2016-10-19 09:09:11 -070083 For a full list of available parameters, please refer to the official
84 API reference:
Andrea Frittoli2715d222017-03-29 14:53:48 +010085 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume
guo xiand8bc1cd2016-06-23 12:35:43 +080086 """
QingXin Meng611768a2013-09-18 00:51:33 -070087 put_body = json.dumps({'volume': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020088 resp, body = self.put('volumes/%s' % volume_id, put_body)
QingXin Meng611768a2013-09-18 00:51:33 -070089 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000090 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -080091 return rest_client.ResponseBody(resp, body)
QingXin Meng611768a2013-09-18 00:51:33 -070092
Jordan Pittiercb5f6502017-04-10 14:27:39 +020093 def delete_volume(self, volume_id, **params):
94 """Deletes the Specified Volume.
95
96 For a full list of available parameters, please refer to the official
97 API reference:
98 https://developer.openstack.org/api-ref/block-storage/v2/#delete-volume
99 """
lkuchlan0e3bbdf2016-07-11 12:06:51 +0300100 url = 'volumes/%s' % volume_id
Jordan Pittiercb5f6502017-04-10 14:27:39 +0200101 if params:
102 url += '?%s' % urllib.urlencode(params)
lkuchlan0e3bbdf2016-07-11 12:06:51 +0300103 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000104 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800105 return rest_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530106
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900107 def upload_volume(self, volume_id, **kwargs):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200108 """Uploads a volume in Glance."""
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900109 post_body = json.dumps({'os-volume_upload_image': kwargs})
Giulio Fidente884e9da2013-06-21 17:25:42 +0200110 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200111 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200112 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000113 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800114 return rest_client.ResponseBody(resp, body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200115
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900116 def attach_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800117 """Attaches a volume to a given instance on a given mountpoint.
118
Dong Ma127887a2016-10-19 09:09:11 -0700119 For a full list of available parameters, please refer to the official
120 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800121 http://developer.openstack.org/api-ref/block-storage/v2/#attach-volume-to-server
guo xiand8bc1cd2016-06-23 12:35:43 +0800122 """
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):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800130 """Set a bootable flag for a volume - true or false.
131
132 For a full list of available parameters, please refer to the official
133 API reference:
134 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-bootable-status
135 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900136 post_body = json.dumps({'os-set_bootable': kwargs})
bkopilov8a657ae2015-05-11 11:45:23 +0300137 url = 'volumes/%s/action' % (volume_id)
138 resp, body = self.post(url, post_body)
139 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800140 return rest_client.ResponseBody(resp, body)
bkopilov8a657ae2015-05-11 11:45:23 +0300141
Rohit Karajgia42fe442012-09-21 03:08:33 -0700142 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500143 """Detaches a volume from an instance."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900144 post_body = json.dumps({'os-detach': {}})
Rohit Karajgia42fe442012-09-21 03:08:33 -0700145 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200146 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000147 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800148 return rest_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700149
zhangyanzi6b632432013-10-24 19:08:50 +0800150 def reserve_volume(self, volume_id):
151 """Reserves a volume."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900152 post_body = json.dumps({'os-reserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800153 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200154 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000155 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800156 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800157
158 def unreserve_volume(self, volume_id):
159 """Restore a reserved volume ."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900160 post_body = json.dumps({'os-unreserve': {}})
zhangyanzi6b632432013-10-24 19:08:50 +0800161 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200162 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000163 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800164 return rest_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800165
David Kranz6aceb4a2012-06-05 14:05:45 -0400166 def is_resource_deleted(self, id):
Ken'ichi Ohmichi4723fde2017-04-26 14:19:57 -0700167 """Check the specified resource is deleted or not.
168
169 :param id: A checked resource id
170 :raises lib_exc.DeleteErrorException: If the specified resource is on
171 the status the delete was failed.
172 """
David Kranz6aceb4a2012-06-05 14:05:45 -0400173 try:
Ken'ichi Ohmichi4723fde2017-04-26 14:19:57 -0700174 volume = self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900175 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400176 return True
Ken'ichi Ohmichi4723fde2017-04-26 14:19:57 -0700177 if volume["volume"]["status"] == "error_deleting":
178 raise lib_exc.DeleteErrorException(resource_id=id)
David Kranz6aceb4a2012-06-05 14:05:45 -0400179 return False
wanghao5b981752013-10-22 11:41:41 +0800180
Matt Riedemannd2b96512014-10-13 10:18:16 -0700181 @property
182 def resource_type(self):
183 """Returns the primary type of resource this client works with."""
184 return 'volume'
185
Ghanshyam58a9e872015-12-18 10:46:07 +0900186 def extend_volume(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800187 """Extend a volume.
188
Dong Ma127887a2016-10-19 09:09:11 -0700189 For a full list of available parameters, please refer to the official
190 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800191 http://developer.openstack.org/api-ref/block-storage/v2/#extend-volume-size
guo xiand8bc1cd2016-06-23 12:35:43 +0800192 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900193 post_body = json.dumps({'os-extend': kwargs})
wanghao5b981752013-10-22 11:41:41 +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)
wanghaoaa1f2f92013-10-10 11:30:37 +0800198
Ghanshyam58a9e872015-12-18 10:46:07 +0900199 def reset_volume_status(self, volume_id, **kwargs):
guo xiand8bc1cd2016-06-23 12:35:43 +0800200 """Reset the Specified Volume's Status.
201
Dong Ma127887a2016-10-19 09:09:11 -0700202 For a full list of available parameters, please refer to the official
203 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800204 http://developer.openstack.org/api-ref/block-storage/v2/#reset-volume-statuses
guo xiand8bc1cd2016-06-23 12:35:43 +0800205 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900206 post_body = json.dumps({'os-reset_status': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200207 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000208 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800209 return rest_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800210
Ghanshyam58a9e872015-12-18 10:46:07 +0900211 def update_volume_readonly(self, volume_id, **kwargs):
zhangyanziaa180072013-11-21 12:31:26 +0800212 """Update the Specified Volume readonly."""
Ghanshyam58a9e872015-12-18 10:46:07 +0900213 post_body = json.dumps({'os-update_readonly_flag': kwargs})
zhangyanziaa180072013-11-21 12:31:26 +0800214 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200215 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000216 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800217 return rest_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800218
219 def force_delete_volume(self, volume_id):
220 """Force Delete Volume."""
221 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200222 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000223 self.expected_success(202, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800224 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800225
226 def create_volume_metadata(self, volume_id, metadata):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800227 """Create metadata for the volume.
228
229 For a full list of available parameters, please refer to the official
230 API reference:
231 http://developer.openstack.org/api-ref/block-storage/v2/#create-volume-metadata
232 """
huangtianhua0ff41682013-12-16 14:49:31 +0800233 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800234 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200235 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800236 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000237 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800238 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800239
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000240 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800241 """Get metadata of the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800242 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200243 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800244 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000245 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800246 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800247
248 def update_volume_metadata(self, volume_id, metadata):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800249 """Update metadata for the volume.
250
251 For a full list of available parameters, please refer to the official
252 API reference:
253 http://developer.openstack.org/api-ref/block-storage/v2/#update-volume-metadata
254 """
huangtianhua0ff41682013-12-16 14:49:31 +0800255 put_body = json.dumps({'metadata': metadata})
guo yunxian6cdf0562016-08-17 16:21:52 +0800256 url = "volumes/%s/metadata" % volume_id
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200257 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800258 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000259 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800260 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800261
jeremy.zhangb40cb192017-07-04 12:56:59 +0800262 def show_volume_metadata_item(self, volume_id, id):
263 """Show metadata item for the volume."""
264 url = "volumes/%s/metadata/%s" % (volume_id, id)
265 resp, body = self.get(url)
266 body = json.loads(body)
267 self.expected_success(200, resp.status)
268 return rest_client.ResponseBody(resp, body)
269
huangtianhua0ff41682013-12-16 14:49:31 +0800270 def update_volume_metadata_item(self, volume_id, id, meta_item):
271 """Update metadata item for the volume."""
272 put_body = json.dumps({'meta': meta_item})
guo yunxian6cdf0562016-08-17 16:21:52 +0800273 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200274 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800275 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000276 self.expected_success(200, resp.status)
Ken'ichi Ohmichi90d446a2016-03-02 10:17:38 -0800277 return rest_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800278
279 def delete_volume_metadata_item(self, volume_id, id):
280 """Delete metadata item for the volume."""
guo yunxian6cdf0562016-08-17 16:21:52 +0800281 url = "volumes/%s/metadata/%s" % (volume_id, id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200282 resp, body = self.delete(url)
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)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800285
Ghanshyam58a9e872015-12-18 10:46:07 +0900286 def retype_volume(self, volume_id, **kwargs):
jeremy.zhang83b3e552017-06-23 15:53:50 +0800287 """Updates volume with new volume type.
288
289 For a full list of available parameters, please refer to the official
290 API reference:
291 https://developer.openstack.org/api-ref/block-storage/v2/#retype-volume
292 """
Ghanshyam58a9e872015-12-18 10:46:07 +0900293 post_body = json.dumps({'os-retype': kwargs})
nayna-patel78f743e2015-01-09 10:52:51 +0000294 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
295 self.expected_success(202, resp.status)
raigax9d8508822017-07-12 18:31:39 -0400296 return rest_client.ResponseBody(resp, body)
lkuchlanf53947e2016-09-15 10:37:57 +0300297
jeremy.zhang7b0eaf82017-04-25 15:11:15 +0800298 def force_detach_volume(self, volume_id, **kwargs):
299 """Force detach a volume.
300
301 For a full list of available parameters, please refer to the official
302 API reference:
303 https://developer.openstack.org/api-ref/block-storage/v2/#force-detach-volume
304 """
305 post_body = json.dumps({'os-force_detach': kwargs})
306 url = 'volumes/%s/action' % volume_id
307 resp, body = self.post(url, post_body)
308 self.expected_success(202, resp.status)
309 return rest_client.ResponseBody(resp, body)
310
lkuchlanf53947e2016-09-15 10:37:57 +0300311 def update_volume_image_metadata(self, volume_id, **kwargs):
312 """Update image metadata for the volume.
313
Dong Ma127887a2016-10-19 09:09:11 -0700314 For a full list of available parameters, please refer to the official
315 API reference:
zhuflccd9d652017-03-30 15:01:49 +0800316 http://developer.openstack.org/api-ref/block-storage/v2/#set-image-metadata-for-volume
lkuchlanf53947e2016-09-15 10:37:57 +0300317 """
318 post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}})
319 url = "volumes/%s/action" % (volume_id)
320 resp, body = self.post(url, post_body)
321 body = json.loads(body)
322 self.expected_success(200, resp.status)
323 return rest_client.ResponseBody(resp, body)
324
325 def delete_volume_image_metadata(self, volume_id, key_name):
326 """Delete image metadata item for the volume."""
327 post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}})
328 url = "volumes/%s/action" % (volume_id)
329 resp, body = self.post(url, post_body)
330 self.expected_success(200, resp.status)
331 return rest_client.ResponseBody(resp, body)
332
jeremy.zhangf0599b12017-08-03 20:02:51 +0800333 def show_volume_image_metadata(self, volume_id):
334 """Show image metadata for the volume."""
335 post_body = json.dumps({'os-show_image_metadata': {}})
336 url = "volumes/%s/action" % volume_id
337 resp, body = self.post(url, post_body)
338 body = json.loads(body)
339 self.expected_success(200, resp.status)
340 return rest_client.ResponseBody(resp, body)
341
jeremy.zhangf4fbf302017-03-22 11:25:53 +0800342 def unmanage_volume(self, volume_id):
343 """Unmanage volume.
344
345 For a full list of available parameters, please refer to the official
346 API reference:
347 https://developer.openstack.org/api-ref/block-storage/v2/#unmanage-volume
348 """
349 post_body = json.dumps({'os-unmanage': {}})
350 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
351 self.expected_success(202, resp.status)
352 return rest_client.ResponseBody(resp, body)