blob: 97c559756a8c5464dbcf05a9a18e559498fc56c5 [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
19from tempest.lib.common import rest_client
20
21
22class TransfersClient(rest_client.RestClient):
23 """Client class to send CRUD Volume Transfer API requests"""
24
25 def create_volume_transfer(self, **kwargs):
26 """Create a volume transfer.
27
28 For a full list of available parameters, please refer to the official
29 API reference:
30 https://developer.openstack.org/api-ref/block-storage/v3/index.html#create-a-volume-transfer
31 """
32 post_body = json.dumps({'transfer': kwargs})
33 resp, body = self.post('os-volume-transfer', post_body)
34 body = json.loads(body)
35 self.expected_success(202, resp.status)
36 return rest_client.ResponseBody(resp, body)
37
38 def show_volume_transfer(self, transfer_id):
39 """Returns the details of a volume transfer."""
40 url = "os-volume-transfer/%s" % transfer_id
41 resp, body = self.get(url)
42 body = json.loads(body)
43 self.expected_success(200, resp.status)
44 return rest_client.ResponseBody(resp, body)
45
46 def list_volume_transfers(self, detail=False, **params):
47 """List all the volume transfers created.
48
49 For a full list of available parameters, please refer to the official
50 API reference:
51 https://developer.openstack.org/api-ref/block-storage/v3/index.html#list-volume-transfers-for-a-project
52 https://developer.openstack.org/api-ref/block-storage/v3/index.html#list-volume-transfers-and-details
53 """
54 url = 'os-volume-transfer'
55 if detail:
56 url += '/detail'
57 if params:
58 url += '?%s' % urllib.urlencode(params)
59 resp, body = self.get(url)
60 body = json.loads(body)
61 self.expected_success(200, resp.status)
62 return rest_client.ResponseBody(resp, body)
63
64 def delete_volume_transfer(self, transfer_id):
65 """Delete a volume transfer."""
66 resp, body = self.delete("os-volume-transfer/%s" % transfer_id)
67 self.expected_success(202, resp.status)
68 return rest_client.ResponseBody(resp, body)
69
70 def accept_volume_transfer(self, transfer_id, **kwargs):
71 """Accept a volume transfer.
72
73 For a full list of available parameters, please refer to the official
74 API reference:
75 https://developer.openstack.org/api-ref/block-storage/v3/index.html#accept-a-volume-transfer
76 """
77 url = 'os-volume-transfer/%s/accept' % transfer_id
78 post_body = json.dumps({'accept': kwargs})
79 resp, body = self.post(url, post_body)
80 body = json.loads(body)
81 self.expected_success(202, resp.status)
82 return rest_client.ResponseBody(resp, body)