Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 1 | # Copyright 2016 Red Hat, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | from oslo_serialization import jsonutils as json |
| 16 | from six.moves.urllib import parse as urllib |
| 17 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 18 | from tempest.lib.common import rest_client |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 19 | |
| 20 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 21 | class DomainsClient(rest_client.RestClient): |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 22 | api_version = "v3" |
| 23 | |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 24 | def create_domain(self, **kwargs): |
| 25 | """Creates a domain. |
| 26 | |
| 27 | For a full list of available parameters, please refer to the official |
| 28 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 29 | https://docs.openstack.org/api-ref/identity/v3/index.html#create-domain |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 30 | """ |
| 31 | post_body = json.dumps({'domain': kwargs}) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 32 | resp, body = self.post('domains', post_body) |
| 33 | self.expected_success(201, resp.status) |
| 34 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 35 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 36 | |
| 37 | def delete_domain(self, domain_id): |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 38 | """Deletes a domain. |
| 39 | |
| 40 | For APi details, please refer to the official API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 41 | https://docs.openstack.org/api-ref/identity/v3/index.html#delete-domain |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 42 | """ |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame] | 43 | resp, body = self.delete('domains/%s' % domain_id) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 44 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 45 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 46 | |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 47 | def list_domains(self, **params): |
| 48 | """List Domains. |
| 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/identity/v3/index.html#list-domains |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 53 | """ |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 54 | url = 'domains' |
| 55 | if params: |
| 56 | url += '?%s' % urllib.urlencode(params) |
| 57 | resp, body = self.get(url) |
| 58 | self.expected_success(200, resp.status) |
| 59 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 60 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 61 | |
| 62 | def update_domain(self, domain_id, **kwargs): |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 63 | """Updates a domain. |
| 64 | |
| 65 | For a full list of available parameters, please refer to the official |
| 66 | API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 67 | https://docs.openstack.org/api-ref/identity/v3/index.html#update-domain |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 68 | """ |
| 69 | post_body = json.dumps({'domain': kwargs}) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 70 | resp, body = self.patch('domains/%s' % domain_id, post_body) |
| 71 | self.expected_success(200, resp.status) |
| 72 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 73 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 74 | |
| 75 | def show_domain(self, domain_id): |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 76 | """Get Domain details. |
| 77 | |
| 78 | For API details, please refer to the official API reference: |
Andreas Jaeger | bf30ae7 | 2019-07-22 19:22:57 +0200 | [diff] [blame] | 79 | https://docs.openstack.org/api-ref/identity/v3/index.html#show-domain-details |
ghanshyam | 8af17d6 | 2016-08-01 16:19:42 +0900 | [diff] [blame] | 80 | """ |
Daniel Mellado | 91a26b6 | 2016-02-11 11:13:04 +0000 | [diff] [blame] | 81 | resp, body = self.get('domains/%s' % domain_id) |
| 82 | self.expected_success(200, resp.status) |
| 83 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 84 | return rest_client.ResponseBody(resp, body) |