blob: f572f95c2494195762a35690196fab6af6d83a64 [file] [log] [blame]
ghanshyamde676ba2018-02-19 06:20:00 +00001# Copyright 2012 OpenStack Foundation
2# 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
16from oslo_serialization import jsonutils as json
17from six.moves.urllib import parse as urllib
18
zhufl48a76db2018-10-09 17:34:19 +080019from tempest.lib.api_schema.response.volume import transfers as schema
ghanshyamde676ba2018-02-19 06:20:00 +000020from tempest.lib.common import rest_client
21
22
23class TransfersClient(rest_client.RestClient):
24 """Client class to send CRUD Volume Transfer API requests"""
25
26 def create_volume_transfer(self, **kwargs):
27 """Create a volume transfer.
28
29 For a full list of available parameters, please refer to the official
30 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020031 https://docs.openstack.org/api-ref/block-storage/v3/index.html#create-a-volume-transfer
ghanshyamde676ba2018-02-19 06:20:00 +000032 """
33 post_body = json.dumps({'transfer': kwargs})
34 resp, body = self.post('os-volume-transfer', post_body)
35 body = json.loads(body)
zhufl48a76db2018-10-09 17:34:19 +080036 self.validate_response(schema.create_volume_transfer, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000037 return rest_client.ResponseBody(resp, body)
38
39 def show_volume_transfer(self, transfer_id):
40 """Returns the details of a volume transfer."""
41 url = "os-volume-transfer/%s" % transfer_id
42 resp, body = self.get(url)
43 body = json.loads(body)
zhufl48a76db2018-10-09 17:34:19 +080044 self.validate_response(schema.show_volume_transfer, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000045 return rest_client.ResponseBody(resp, body)
46
47 def list_volume_transfers(self, detail=False, **params):
48 """List all the volume transfers created.
49
50 For a full list of available parameters, please refer to the official
51 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020052 https://docs.openstack.org/api-ref/block-storage/v3/index.html#list-volume-transfers-for-a-project
53 https://docs.openstack.org/api-ref/block-storage/v3/index.html#list-volume-transfers-and-details
ghanshyamde676ba2018-02-19 06:20:00 +000054 """
55 url = 'os-volume-transfer'
zhufl48a76db2018-10-09 17:34:19 +080056 schema_list_transfers = schema.list_volume_transfers_no_detail
ghanshyamde676ba2018-02-19 06:20:00 +000057 if detail:
58 url += '/detail'
zhufl48a76db2018-10-09 17:34:19 +080059 schema_list_transfers = schema.list_volume_transfers_with_detail
ghanshyamde676ba2018-02-19 06:20:00 +000060 if params:
61 url += '?%s' % urllib.urlencode(params)
62 resp, body = self.get(url)
63 body = json.loads(body)
zhufl48a76db2018-10-09 17:34:19 +080064 self.validate_response(schema_list_transfers, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000065 return rest_client.ResponseBody(resp, body)
66
67 def delete_volume_transfer(self, transfer_id):
68 """Delete a volume transfer."""
69 resp, body = self.delete("os-volume-transfer/%s" % transfer_id)
zhufl48a76db2018-10-09 17:34:19 +080070 self.validate_response(schema.delete_volume_transfer, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000071 return rest_client.ResponseBody(resp, body)
72
73 def accept_volume_transfer(self, transfer_id, **kwargs):
74 """Accept a volume transfer.
75
76 For a full list of available parameters, please refer to the official
77 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020078 https://docs.openstack.org/api-ref/block-storage/v3/index.html#accept-a-volume-transfer
ghanshyamde676ba2018-02-19 06:20:00 +000079 """
80 url = 'os-volume-transfer/%s/accept' % transfer_id
81 post_body = json.dumps({'accept': kwargs})
82 resp, body = self.post(url, post_body)
83 body = json.loads(body)
zhufl48a76db2018-10-09 17:34:19 +080084 self.validate_response(schema.accept_volume_transfer, resp, body)
ghanshyamde676ba2018-02-19 06:20:00 +000085 return rest_client.ResponseBody(resp, body)