ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 1 | # 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 | |
| 16 | from oslo_serialization import jsonutils as json |
| 17 | from six.moves.urllib import parse as urllib |
| 18 | |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 19 | from tempest.lib.api_schema.response.volume import transfers as schema |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 20 | from tempest.lib.common import rest_client |
| 21 | |
| 22 | |
| 23 | class 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 31 | https://docs.openstack.org/api-ref/block-storage/v3/index.html#create-a-volume-transfer |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 32 | """ |
| 33 | post_body = json.dumps({'transfer': kwargs}) |
| 34 | resp, body = self.post('os-volume-transfer', post_body) |
| 35 | body = json.loads(body) |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 36 | self.validate_response(schema.create_volume_transfer, resp, body) |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 37 | 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) |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 44 | self.validate_response(schema.show_volume_transfer, resp, body) |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 45 | 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 52 | 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 |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 54 | """ |
| 55 | url = 'os-volume-transfer' |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 56 | schema_list_transfers = schema.list_volume_transfers_no_detail |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 57 | if detail: |
| 58 | url += '/detail' |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 59 | schema_list_transfers = schema.list_volume_transfers_with_detail |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 60 | if params: |
| 61 | url += '?%s' % urllib.urlencode(params) |
| 62 | resp, body = self.get(url) |
| 63 | body = json.loads(body) |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 64 | self.validate_response(schema_list_transfers, resp, body) |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 65 | 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) |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 70 | self.validate_response(schema.delete_volume_transfer, resp, body) |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 71 | 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 Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 78 | https://docs.openstack.org/api-ref/block-storage/v3/index.html#accept-a-volume-transfer |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 79 | """ |
| 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) |
zhufl | 48a76db | 2018-10-09 17:34:19 +0800 | [diff] [blame] | 84 | self.validate_response(schema.accept_volume_transfer, resp, body) |
ghanshyam | de676ba | 2018-02-19 06:20:00 +0000 | [diff] [blame] | 85 | return rest_client.ResponseBody(resp, body) |