blob: 6893af23c2d11742133cbb2752e66307c7347b6a [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
18from tempest.common import rest_client
19from tempest import config
20
21CONF = config.CONF
22
23
24class AgentsV3ClientJSON(rest_client.RestClient):
25
26 def __init__(self, auth_provider):
27 super(AgentsV3ClientJSON, self).__init__(auth_provider)
28 self.service = CONF.compute.catalog_v3_type
29
30 def list_agents(self, params=None):
31 """List all agent builds."""
32 url = 'os-agents'
33 if params:
34 url += '?%s' % urllib.urlencode(params)
35 resp, body = self.get(url)
36 return resp, self._parse_resp(body)
37
38 def create_agent(self, **kwargs):
39 """Create an agent build."""
40 post_body = json.dumps({'agent': kwargs})
41 resp, body = self.post('os-agents', post_body)
42 return resp, self._parse_resp(body)
43
44 def delete_agent(self, agent_id):
45 """Delete an existing agent build."""
46 return self.delete('os-agents/%s' % str(agent_id))
47
48 def update_agent(self, agent_id, **kwargs):
49 """Update an agent build."""
50 put_body = json.dumps({'agent': kwargs})
51 resp, body = self.put('os-agents/%s' % str(agent_id), put_body)
52 return resp, self._parse_resp(body)