blob: 1edd1e98785039848ab5a7e5088a5720365748bd [file] [log] [blame]
Yuiko Takada420f2eb2014-04-02 19:53:38 +09001# 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
15import json
16import urllib
17
18from tempest.common import rest_client
19from tempest import config
20
21CONF = config.CONF
22
23
24class AgentsClientJSON(rest_client.RestClient):
25 """
26 Tests Agents API
27 """
28
29 def __init__(self, auth_provider):
30 super(AgentsClientJSON, self).__init__(auth_provider)
31 self.service = CONF.compute.catalog_type
32
33 def list_agents(self, params=None):
34 """List all agent builds."""
35 url = 'os-agents'
36 if params:
37 url += '?%s' % urllib.urlencode(params)
38 resp, body = self.get(url)
39 return resp, json.loads(body).get('agents')
40
41 def create_agent(self, **kwargs):
42 """Create an agent build."""
43 post_body = json.dumps({'agent': kwargs})
44 resp, body = self.post('os-agents', post_body)
45 return resp, self._parse_resp(body)
46
47 def delete_agent(self, agent_id):
48 """Delete an existing agent build."""
49 return self.delete('os-agents/%s' % str(agent_id))
50
51 def update_agent(self, agent_id, **kwargs):
52 """Update an agent build."""
53 put_body = json.dumps({'para': kwargs})
54 resp, body = self.put('os-agents/%s' % str(agent_id), put_body)
55 return resp, self._parse_resp(body)