blob: 31314b7f46e4256b4a5070d6a0f6139890ae7c4c [file] [log] [blame]
YuikoTakada8a2ec112014-02-18 21:13:51 +00001# 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
Yuiko Takadabde91262014-04-17 10:43:41 +000018from tempest.api_schema.compute import agents as common_schema
Yuiko Takadac32a98b2014-04-02 20:18:24 +090019from tempest.api_schema.compute.v3 import agents as schema
YuikoTakada8a2ec112014-02-18 21:13:51 +000020from tempest.common import rest_client
21from tempest import config
22
23CONF = config.CONF
24
25
26class AgentsV3ClientJSON(rest_client.RestClient):
27
28 def __init__(self, auth_provider):
29 super(AgentsV3ClientJSON, self).__init__(auth_provider)
30 self.service = CONF.compute.catalog_v3_type
31
32 def list_agents(self, params=None):
33 """List all agent builds."""
34 url = 'os-agents'
35 if params:
36 url += '?%s' % urllib.urlencode(params)
37 resp, body = self.get(url)
Yuiko Takadabde91262014-04-17 10:43:41 +000038 body = json.loads(body)
39 self.validate_response(common_schema.list_agents, resp, body)
40 return resp, body['agents']
YuikoTakada8a2ec112014-02-18 21:13:51 +000041
42 def create_agent(self, **kwargs):
43 """Create an agent build."""
44 post_body = json.dumps({'agent': kwargs})
45 resp, body = self.post('os-agents', post_body)
Yuiko Takada34e98ad2014-04-01 14:13:05 +000046 body = json.loads(body)
47 self.validate_response(schema.create_agent, resp, body)
48 return resp, body['agent']
YuikoTakada8a2ec112014-02-18 21:13:51 +000049
50 def delete_agent(self, agent_id):
51 """Delete an existing agent build."""
Yuiko Takadac32a98b2014-04-02 20:18:24 +090052 resp, body = self.delete("os-agents/%s" % str(agent_id))
53 self.validate_response(schema.delete_agent, resp, body)
54 return resp, body
YuikoTakada8a2ec112014-02-18 21:13:51 +000055
56 def update_agent(self, agent_id, **kwargs):
57 """Update an agent build."""
58 put_body = json.dumps({'agent': kwargs})
59 resp, body = self.put('os-agents/%s' % str(agent_id), put_body)
60 return resp, self._parse_resp(body)