Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 1 | # Copyright 2014 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # 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, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | from oslo_serialization import jsonutils as json |
| 16 | from six.moves.urllib import parse as urllib |
| 17 | |
| 18 | from tempest.lib.api_schema.response.compute.v2_1 import agents as schema |
| 19 | from tempest.lib.common import rest_client |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 20 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 21 | |
| 22 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 23 | class AgentsClient(base_compute_client.BaseComputeClient): |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 24 | """Tests Agents API""" |
| 25 | |
| 26 | def list_agents(self, **params): |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 27 | """List all agent builds. |
| 28 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 29 | For a full list of available parameters, please refer to the official |
| 30 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 31 | https://developer.openstack.org/api-ref/compute/#list-agent-builds |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 32 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 33 | url = 'os-agents' |
| 34 | if params: |
| 35 | url += '?%s' % urllib.urlencode(params) |
| 36 | resp, body = self.get(url) |
| 37 | body = json.loads(body) |
| 38 | self.validate_response(schema.list_agents, resp, body) |
| 39 | return rest_client.ResponseBody(resp, body) |
| 40 | |
| 41 | def create_agent(self, **kwargs): |
| 42 | """Create an agent build. |
| 43 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 44 | For a full list of available parameters, please refer to the official |
| 45 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 46 | https://developer.openstack.org/api-ref/compute/#create-agent-build |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 47 | """ |
| 48 | post_body = json.dumps({'agent': kwargs}) |
| 49 | resp, body = self.post('os-agents', post_body) |
| 50 | body = json.loads(body) |
| 51 | self.validate_response(schema.create_agent, resp, body) |
| 52 | return rest_client.ResponseBody(resp, body) |
| 53 | |
| 54 | def delete_agent(self, agent_id): |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 55 | """Delete an existing agent build. |
| 56 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 57 | For a full list of available parameters, please refer to the official |
| 58 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 59 | https://developer.openstack.org/api-ref/compute/#delete-agent-build |
Lv Fumei | 7e32633 | 2016-07-08 15:18:03 +0800 | [diff] [blame] | 60 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 61 | resp, body = self.delete("os-agents/%s" % agent_id) |
| 62 | self.validate_response(schema.delete_agent, resp, body) |
| 63 | return rest_client.ResponseBody(resp, body) |
| 64 | |
| 65 | def update_agent(self, agent_id, **kwargs): |
| 66 | """Update an agent build. |
| 67 | |
Dong Ma | d12c233 | 2016-10-19 01:36:27 -0700 | [diff] [blame] | 68 | For a full list of available parameters, please refer to the official |
| 69 | API reference: |
zhufl | 8d4134b | 2017-03-08 15:04:20 +0800 | [diff] [blame] | 70 | https://developer.openstack.org/api-ref/compute/#update-agent-build |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 71 | """ |
| 72 | put_body = json.dumps({'para': kwargs}) |
| 73 | resp, body = self.put('os-agents/%s' % agent_id, put_body) |
| 74 | body = json.loads(body) |
| 75 | self.validate_response(schema.update_agent, resp, body) |
| 76 | return rest_client.ResponseBody(resp, body) |