blob: 1f8548e9ff6a638ca3d19905a74a57c2987c7d27 [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
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053016import json
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053017import time
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053018
Matthew Treinish89128142015-04-23 10:44:30 -040019from six.moves.urllib import parse as urllib
Masayuki Igawabfa07602015-01-20 18:47:17 +090020from tempest_lib import exceptions as lib_exc
21
Joseph Lanoux6809bab2014-12-18 14:57:18 +000022from tempest.common import service_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023from tempest import exceptions
24
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053025
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000026class BaseVolumesClient(service_client.ServiceClient):
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070027 """
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080028 Base client class to send CRUD Volume API requests to a Cinder endpoint
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070029 """
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053030
Ken'ichi Ohmichia39d0be2014-12-17 08:46:11 +000031 create_resp = 200
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053032
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000033 def __init__(self, auth_provider, service, region,
34 default_volume_size=1, **kwargs):
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000035 super(BaseVolumesClient, self).__init__(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000036 auth_provider, service, region, **kwargs)
37 self.default_volume_size = default_volume_size
38
anju tiwari789449a2013-08-29 16:56:17 +053039 def get_attachment_from_volume(self, volume):
40 """Return the element 'attachment' from input volumes."""
41 return volume['attachments'][0]
42
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000043 def list_volumes(self, detail=False, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -050044 """List all the volumes created."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070045 url = 'volumes'
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000046 if detail:
47 url += '/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050048 if params:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000049 url += '?%s' % urllib.urlencode(params)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053050
chris fattarsi5098fa22012-04-17 13:27:00 -070051 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053052 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000053 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000054 return service_client.ResponseBodyList(resp, body['volumes'])
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053055
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000056 def show_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050057 """Returns the details of a single volume."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070058 url = "volumes/%s" % str(volume_id)
Attila Fazekasb8aa7592013-01-26 01:25:45 +010059 resp, body = self.get(url)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053060 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000061 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000062 return service_client.ResponseBody(resp, body['volume'])
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053063
Jerry Cai9733d0e2014-03-19 15:50:49 +080064 def create_volume(self, size=None, **kwargs):
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053065 """
66 Creates a new Volume.
Jerry Cai9733d0e2014-03-19 15:50:49 +080067 size: Size of volume in GB.
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053068 Following optional keyword arguments are accepted:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080069 display_name: Optional Volume Name(only for V1).
70 name: Optional Volume Name(only for V2).
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053071 metadata: A dictionary of values to be used as metadata.
Rohan Rhishikesh Kanadec316f0a2012-12-04 05:44:39 -080072 volume_type: Optional Name of volume_type for the volume
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010073 snapshot_id: When specified the volume is created from this snapshot
Giulio Fidente36836c42013-04-05 15:43:51 +020074 imageRef: When specified the volume is created from this image
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053075 """
Jerry Cai9733d0e2014-03-19 15:50:49 +080076 if size is None:
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +000077 size = self.default_volume_size
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010078 post_body = {'size': size}
79 post_body.update(kwargs)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053080 post_body = json.dumps({'volume': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020081 resp, body = self.post('volumes', post_body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053082 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000083 self.expected_success(self.create_resp, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000084 return service_client.ResponseBody(resp, body['volume'])
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053085
QingXin Meng611768a2013-09-18 00:51:33 -070086 def update_volume(self, volume_id, **kwargs):
87 """Updates the Specified Volume."""
88 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)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000092 return service_client.ResponseBody(resp, body['volume'])
QingXin Meng611768a2013-09-18 00:51:33 -070093
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053094 def delete_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050095 """Deletes the Specified Volume."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000096 resp, body = self.delete("volumes/%s" % str(volume_id))
97 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +000098 return service_client.ResponseBody(resp, body)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +053099
Ryan Hsua67f4632013-08-29 16:03:06 -0700100 def upload_volume(self, volume_id, image_name, disk_format):
Giulio Fidente884e9da2013-06-21 17:25:42 +0200101 """Uploads a volume in Glance."""
102 post_body = {
103 'image_name': image_name,
Ryan Hsua67f4632013-08-29 16:03:06 -0700104 'disk_format': disk_format
Giulio Fidente884e9da2013-06-21 17:25:42 +0200105 }
106 post_body = json.dumps({'os-volume_upload_image': post_body})
107 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200108 resp, body = self.post(url, post_body)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200109 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000110 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000111 return service_client.ResponseBody(resp,
112 body['os-volume_upload_image'])
Giulio Fidente884e9da2013-06-21 17:25:42 +0200113
Rohit Karajgia42fe442012-09-21 03:08:33 -0700114 def attach_volume(self, volume_id, instance_uuid, mountpoint):
Sean Daguef237ccb2013-01-04 15:19:14 -0500115 """Attaches a volume to a given instance on a given mountpoint."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700116 post_body = {
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900117 'instance_uuid': instance_uuid,
118 'mountpoint': mountpoint,
119 }
Rohit Karajgia42fe442012-09-21 03:08:33 -0700120 post_body = json.dumps({'os-attach': post_body})
121 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200122 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000123 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000124 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700125
bkopilov8a657ae2015-05-11 11:45:23 +0300126 def set_bootable_volume(self, volume_id, bootable):
127 """set a bootable flag for a volume - true or false."""
128 post_body = {"bootable": bootable}
129 post_body = json.dumps({'os-set_bootable': post_body})
130 url = 'volumes/%s/action' % (volume_id)
131 resp, body = self.post(url, post_body)
132 self.expected_success(200, resp.status)
133 return service_client.ResponseBody(resp, body)
134
Rohit Karajgia42fe442012-09-21 03:08:33 -0700135 def detach_volume(self, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500136 """Detaches a volume from an instance."""
Rohit Karajgia42fe442012-09-21 03:08:33 -0700137 post_body = {}
138 post_body = json.dumps({'os-detach': post_body})
139 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200140 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000141 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000142 return service_client.ResponseBody(resp, body)
Rohit Karajgia42fe442012-09-21 03:08:33 -0700143
zhangyanzi6b632432013-10-24 19:08:50 +0800144 def reserve_volume(self, volume_id):
145 """Reserves a volume."""
146 post_body = {}
147 post_body = json.dumps({'os-reserve': post_body})
148 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200149 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000150 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000151 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800152
153 def unreserve_volume(self, volume_id):
154 """Restore a reserved volume ."""
155 post_body = {}
156 post_body = json.dumps({'os-unreserve': post_body})
157 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)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000160 return service_client.ResponseBody(resp, body)
zhangyanzi6b632432013-10-24 19:08:50 +0800161
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530162 def wait_for_volume_status(self, volume_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500163 """Waits for a Volume to reach a given status."""
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000164 body = self.show_volume(volume_id)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530165 volume_status = body['status']
166 start = int(time.time())
167
168 while volume_status != status:
169 time.sleep(self.build_interval)
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000170 body = self.show_volume(volume_id)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530171 volume_status = body['status']
172 if volume_status == 'error':
rajalakshmi-ganesane3bb58f2012-05-16 12:01:15 +0530173 raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530174
175 if int(time.time()) - start >= self.build_timeout:
Martin Pavlasek1102c3a2014-10-20 17:17:55 +0200176 message = ('Volume %s failed to reach %s status (current: %s) '
177 'within the required time '
178 '(%s s).' % (volume_id,
179 status,
180 volume_status,
181 self.build_timeout))
rajalakshmi-ganesanb4465572012-03-22 01:22:50 +0530182 raise exceptions.TimeoutException(message)
David Kranz6aceb4a2012-06-05 14:05:45 -0400183
184 def is_resource_deleted(self, id):
185 try:
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000186 self.show_volume(id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900187 except lib_exc.NotFound:
David Kranz6aceb4a2012-06-05 14:05:45 -0400188 return True
189 return False
wanghao5b981752013-10-22 11:41:41 +0800190
Matt Riedemannd2b96512014-10-13 10:18:16 -0700191 @property
192 def resource_type(self):
193 """Returns the primary type of resource this client works with."""
194 return 'volume'
195
wanghao5b981752013-10-22 11:41:41 +0800196 def extend_volume(self, volume_id, extend_size):
197 """Extend a volume."""
198 post_body = {
199 'new_size': extend_size
200 }
201 post_body = json.dumps({'os-extend': post_body})
202 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200203 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000204 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000205 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800206
207 def reset_volume_status(self, volume_id, status):
208 """Reset the Specified Volume's Status."""
209 post_body = json.dumps({'os-reset_status': {"status": status}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200210 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000211 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000212 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800213
214 def volume_begin_detaching(self, volume_id):
215 """Volume Begin Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000216 # ref cinder/api/contrib/volume_actions.py#L158
wanghaoaa1f2f92013-10-10 11:30:37 +0800217 post_body = json.dumps({'os-begin_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200218 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000219 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000220 return service_client.ResponseBody(resp, body)
wanghaoaa1f2f92013-10-10 11:30:37 +0800221
222 def volume_roll_detaching(self, volume_id):
223 """Volume Roll Detaching."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000224 # cinder/api/contrib/volume_actions.py#L170
wanghaoaa1f2f92013-10-10 11:30:37 +0800225 post_body = json.dumps({'os-roll_detaching': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200226 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000227 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000228 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800229
230 def create_volume_transfer(self, vol_id, display_name=None):
231 """Create a volume transfer."""
232 post_body = {
233 'volume_id': vol_id
234 }
235 if display_name:
236 post_body['name'] = display_name
237 post_body = json.dumps({'transfer': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200238 resp, body = self.post('os-volume-transfer', post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800239 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000240 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000241 return service_client.ResponseBody(resp, body['transfer'])
wingwjcbd82dc2013-10-22 16:38:39 +0800242
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000243 def show_volume_transfer(self, transfer_id):
wingwjcbd82dc2013-10-22 16:38:39 +0800244 """Returns the details of a volume transfer."""
245 url = "os-volume-transfer/%s" % str(transfer_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200246 resp, body = self.get(url)
wingwjcbd82dc2013-10-22 16:38:39 +0800247 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000248 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000249 return service_client.ResponseBody(resp, body['transfer'])
wingwjcbd82dc2013-10-22 16:38:39 +0800250
251 def list_volume_transfers(self, params=None):
252 """List all the volume transfers created."""
253 url = 'os-volume-transfer'
254 if params:
255 url += '?%s' % urllib.urlencode(params)
256 resp, body = self.get(url)
257 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000258 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000259 return service_client.ResponseBodyList(resp, body['transfers'])
wingwjcbd82dc2013-10-22 16:38:39 +0800260
261 def delete_volume_transfer(self, transfer_id):
262 """Delete a volume transfer."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000263 resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id))
264 self.expected_success(202, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000265 return service_client.ResponseBody(resp, body)
wingwjcbd82dc2013-10-22 16:38:39 +0800266
267 def accept_volume_transfer(self, transfer_id, transfer_auth_key):
268 """Accept a volume transfer."""
269 post_body = {
270 'auth_key': transfer_auth_key,
271 }
272 url = 'os-volume-transfer/%s/accept' % transfer_id
273 post_body = json.dumps({'accept': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200274 resp, body = self.post(url, post_body)
wingwjcbd82dc2013-10-22 16:38:39 +0800275 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000276 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000277 return service_client.ResponseBody(resp, body['transfer'])
zhangyanziaa180072013-11-21 12:31:26 +0800278
279 def update_volume_readonly(self, volume_id, readonly):
280 """Update the Specified Volume readonly."""
281 post_body = {
282 'readonly': readonly
283 }
284 post_body = json.dumps({'os-update_readonly_flag': post_body})
285 url = 'volumes/%s/action' % (volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200286 resp, body = self.post(url, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000287 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000288 return service_client.ResponseBody(resp, body)
wanghao9d3d6cb2013-11-12 15:10:10 +0800289
290 def force_delete_volume(self, volume_id):
291 """Force Delete Volume."""
292 post_body = json.dumps({'os-force_delete': {}})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200293 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000294 self.expected_success(202, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000295 return service_client.ResponseBody(resp, body)
huangtianhua0ff41682013-12-16 14:49:31 +0800296
297 def create_volume_metadata(self, volume_id, metadata):
298 """Create metadata for the volume."""
299 put_body = json.dumps({'metadata': metadata})
300 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200301 resp, body = self.post(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800302 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000303 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000304 return service_client.ResponseBody(resp, body['metadata'])
huangtianhua0ff41682013-12-16 14:49:31 +0800305
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000306 def show_volume_metadata(self, volume_id):
huangtianhua0ff41682013-12-16 14:49:31 +0800307 """Get metadata of the volume."""
308 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200309 resp, body = self.get(url)
huangtianhua0ff41682013-12-16 14:49:31 +0800310 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000311 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000312 return service_client.ResponseBody(resp, body['metadata'])
huangtianhua0ff41682013-12-16 14:49:31 +0800313
314 def update_volume_metadata(self, volume_id, metadata):
315 """Update metadata for the volume."""
316 put_body = json.dumps({'metadata': metadata})
317 url = "volumes/%s/metadata" % str(volume_id)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200318 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800319 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000320 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000321 return service_client.ResponseBody(resp, body['metadata'])
huangtianhua0ff41682013-12-16 14:49:31 +0800322
323 def update_volume_metadata_item(self, volume_id, id, meta_item):
324 """Update metadata item for the volume."""
325 put_body = json.dumps({'meta': meta_item})
326 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200327 resp, body = self.put(url, put_body)
huangtianhua0ff41682013-12-16 14:49:31 +0800328 body = json.loads(body)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000329 self.expected_success(200, resp.status)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000330 return service_client.ResponseBody(resp, body['meta'])
huangtianhua0ff41682013-12-16 14:49:31 +0800331
332 def delete_volume_metadata_item(self, volume_id, id):
333 """Delete metadata item for the volume."""
334 url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +0200335 resp, body = self.delete(url)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000336 self.expected_success(200, resp.status)
Joseph Lanoux2cdd5502015-01-16 14:46:51 +0000337 return service_client.ResponseBody(resp, body)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800338
nayna-patel78f743e2015-01-09 10:52:51 +0000339 def retype_volume(self, volume_id, volume_type, **kwargs):
340 """Updates volume with new volume type."""
341 post_body = {'new_type': volume_type}
342 post_body.update(kwargs)
343 post_body = json.dumps({'os-retype': post_body})
344 resp, body = self.post('volumes/%s/action' % volume_id, post_body)
345 self.expected_success(202, resp.status)
346
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800347
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +0000348class VolumesClient(BaseVolumesClient):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800349 """
350 Client class to send CRUD Volume V1 API requests to a Cinder endpoint
351 """