YuikoTakada | 8a2ec11 | 2014-02-18 21:13:51 +0000 | [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 | import json |
| 16 | import urllib |
| 17 | |
Yuiko Takada | bde9126 | 2014-04-17 10:43:41 +0000 | [diff] [blame] | 18 | from tempest.api_schema.compute import agents as common_schema |
Yuiko Takada | c32a98b | 2014-04-02 20:18:24 +0900 | [diff] [blame] | 19 | from tempest.api_schema.compute.v3 import agents as schema |
YuikoTakada | 8a2ec11 | 2014-02-18 21:13:51 +0000 | [diff] [blame] | 20 | from tempest.common import rest_client |
| 21 | from tempest import config |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
| 26 | class 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 Takada | bde9126 | 2014-04-17 10:43:41 +0000 | [diff] [blame] | 38 | body = json.loads(body) |
| 39 | self.validate_response(common_schema.list_agents, resp, body) |
| 40 | return resp, body['agents'] |
YuikoTakada | 8a2ec11 | 2014-02-18 21:13:51 +0000 | [diff] [blame] | 41 | |
| 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) |
| 46 | return resp, self._parse_resp(body) |
| 47 | |
| 48 | def delete_agent(self, agent_id): |
| 49 | """Delete an existing agent build.""" |
Yuiko Takada | c32a98b | 2014-04-02 20:18:24 +0900 | [diff] [blame] | 50 | resp, body = self.delete("os-agents/%s" % str(agent_id)) |
| 51 | self.validate_response(schema.delete_agent, resp, body) |
| 52 | return resp, body |
YuikoTakada | 8a2ec11 | 2014-02-18 21:13:51 +0000 | [diff] [blame] | 53 | |
| 54 | def update_agent(self, agent_id, **kwargs): |
| 55 | """Update an agent build.""" |
| 56 | put_body = json.dumps({'agent': kwargs}) |
| 57 | resp, body = self.put('os-agents/%s' % str(agent_id), put_body) |
| 58 | return resp, self._parse_resp(body) |