blob: 8b11e642bc5dd4194798c15c65c50053a4468ebe [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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
15from oslo_serialization import jsonutils as json
16from six.moves.urllib import parse as urllib
17
18from tempest.lib.api_schema.response.compute.v2_1 import agents as schema
19from tempest.lib.common import rest_client
20
21
22class AgentsClient(rest_client.RestClient):
23 """Tests Agents API"""
24
25 def list_agents(self, **params):
26 """List all agent builds."""
27 url = 'os-agents'
28 if params:
29 url += '?%s' % urllib.urlencode(params)
30 resp, body = self.get(url)
31 body = json.loads(body)
32 self.validate_response(schema.list_agents, resp, body)
33 return rest_client.ResponseBody(resp, body)
34
35 def create_agent(self, **kwargs):
36 """Create an agent build.
37
38 Available params: see http://developer.openstack.org/
39 api-ref-compute-v2.1.html#agentbuild
40 """
41 post_body = json.dumps({'agent': kwargs})
42 resp, body = self.post('os-agents', post_body)
43 body = json.loads(body)
44 self.validate_response(schema.create_agent, resp, body)
45 return rest_client.ResponseBody(resp, body)
46
47 def delete_agent(self, agent_id):
48 """Delete an existing agent build."""
49 resp, body = self.delete("os-agents/%s" % agent_id)
50 self.validate_response(schema.delete_agent, resp, body)
51 return rest_client.ResponseBody(resp, body)
52
53 def update_agent(self, agent_id, **kwargs):
54 """Update an agent build.
55
56 Available params: see http://developer.openstack.org/
57 api-ref-compute-v2.1.html#updatebuild
58 """
59 put_body = json.dumps({'para': kwargs})
60 resp, body = self.put('os-agents/%s' % agent_id, put_body)
61 body = json.loads(body)
62 self.validate_response(schema.update_agent, resp, body)
63 return rest_client.ResponseBody(resp, body)