Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation. |
| 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 | |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 18 | from tempest.lib.api_schema.response.compute.v2_1 \ |
| 19 | import aggregates as schema |
| 20 | from tempest.lib.api_schema.response.compute.v2_41 \ |
| 21 | import aggregates as schemav241 |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 22 | from tempest.lib.common import rest_client |
| 23 | from tempest.lib import exceptions as lib_exc |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 24 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 25 | |
| 26 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 27 | class AggregatesClient(base_compute_client.BaseComputeClient): |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 28 | |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 29 | schema_versions_info = [ |
| 30 | {'min': None, 'max': '2.40', 'schema': schema}, |
| 31 | {'min': '2.41', 'max': None, 'schema': schemav241}] |
| 32 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 33 | def list_aggregates(self): |
| 34 | """Get aggregate list.""" |
| 35 | resp, body = self.get("os-aggregates") |
| 36 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 37 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 38 | self.validate_response(schema.list_aggregates, resp, body) |
| 39 | return rest_client.ResponseBody(resp, body) |
| 40 | |
| 41 | def show_aggregate(self, aggregate_id): |
| 42 | """Get details of the given aggregate.""" |
| 43 | resp, body = self.get("os-aggregates/%s" % aggregate_id) |
| 44 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 45 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 46 | self.validate_response(schema.get_aggregate, resp, body) |
| 47 | return rest_client.ResponseBody(resp, body) |
| 48 | |
| 49 | def create_aggregate(self, **kwargs): |
| 50 | """Create a new aggregate. |
| 51 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 52 | For a full list of available parameters, please refer to the official |
| 53 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 54 | https://developer.openstack.org/api-ref/compute/#create-aggregate |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 55 | """ |
| 56 | post_body = json.dumps({'aggregate': kwargs}) |
| 57 | resp, body = self.post('os-aggregates', post_body) |
| 58 | |
| 59 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 60 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 61 | self.validate_response(schema.create_aggregate, resp, body) |
| 62 | return rest_client.ResponseBody(resp, body) |
| 63 | |
| 64 | def update_aggregate(self, aggregate_id, **kwargs): |
| 65 | """Update an aggregate. |
| 66 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 67 | For a full list of available parameters, please refer to the official |
| 68 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 69 | https://developer.openstack.org/api-ref/compute/#update-aggregate |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 70 | """ |
| 71 | put_body = json.dumps({'aggregate': kwargs}) |
| 72 | resp, body = self.put('os-aggregates/%s' % aggregate_id, put_body) |
| 73 | |
| 74 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 75 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 76 | self.validate_response(schema.update_aggregate, resp, body) |
| 77 | return rest_client.ResponseBody(resp, body) |
| 78 | |
| 79 | def delete_aggregate(self, aggregate_id): |
| 80 | """Delete the given aggregate.""" |
| 81 | resp, body = self.delete("os-aggregates/%s" % aggregate_id) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 82 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 83 | self.validate_response(schema.delete_aggregate, resp, body) |
| 84 | return rest_client.ResponseBody(resp, body) |
| 85 | |
| 86 | def is_resource_deleted(self, id): |
| 87 | try: |
| 88 | self.show_aggregate(id) |
| 89 | except lib_exc.NotFound: |
| 90 | return True |
| 91 | return False |
| 92 | |
| 93 | @property |
| 94 | def resource_type(self): |
| 95 | """Return the primary type of resource this client works with.""" |
| 96 | return 'aggregate' |
| 97 | |
| 98 | def add_host(self, aggregate_id, **kwargs): |
| 99 | """Add a host to the given aggregate. |
| 100 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 101 | For a full list of available parameters, please refer to the official |
| 102 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 103 | https://developer.openstack.org/api-ref/compute/#add-host |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 104 | """ |
| 105 | post_body = json.dumps({'add_host': kwargs}) |
| 106 | resp, body = self.post('os-aggregates/%s/action' % aggregate_id, |
| 107 | post_body) |
| 108 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 109 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 110 | self.validate_response(schema.aggregate_add_remove_host, resp, body) |
| 111 | return rest_client.ResponseBody(resp, body) |
| 112 | |
| 113 | def remove_host(self, aggregate_id, **kwargs): |
| 114 | """Remove a host from the given aggregate. |
| 115 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 116 | For a full list of available parameters, please refer to the official |
| 117 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 118 | https://developer.openstack.org/api-ref/compute/#remove-host |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 119 | """ |
| 120 | post_body = json.dumps({'remove_host': kwargs}) |
| 121 | resp, body = self.post('os-aggregates/%s/action' % aggregate_id, |
| 122 | post_body) |
| 123 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 124 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 125 | self.validate_response(schema.aggregate_add_remove_host, resp, body) |
| 126 | return rest_client.ResponseBody(resp, body) |
| 127 | |
| 128 | def set_metadata(self, aggregate_id, **kwargs): |
caojinlan | ed34885 | 2016-06-21 11:59:55 +0800 | [diff] [blame] | 129 | """Replace the aggregate's existing metadata with new metadata. |
| 130 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 131 | For a full list of available parameters, please refer to the official |
| 132 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 133 | https://developer.openstack.org/api-ref/compute/#create-or-update-aggregate-metadata |
caojinlan | ed34885 | 2016-06-21 11:59:55 +0800 | [diff] [blame] | 134 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 135 | post_body = json.dumps({'set_metadata': kwargs}) |
| 136 | resp, body = self.post('os-aggregates/%s/action' % aggregate_id, |
| 137 | post_body) |
| 138 | body = json.loads(body) |
zhufl | 4af2c82 | 2018-08-06 14:38:53 +0800 | [diff] [blame] | 139 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 140 | self.validate_response(schema.aggregate_set_metadata, resp, body) |
| 141 | return rest_client.ResponseBody(resp, body) |