Ken'ichi Ohmichi | 7ca54b8 | 2015-07-07 01:10:26 +0000 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
| 2 | # Copyright 2013 Hewlett-Packard Development Company, L.P. |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import json |
| 18 | |
| 19 | from tempest.api_schema.response.compute.v2_1 import servers as schema |
| 20 | from tempest.common import service_client |
| 21 | |
| 22 | |
| 23 | class ServerGroupsClient(service_client.ServiceClient): |
| 24 | |
| 25 | def create_server_group(self, name, policies): |
| 26 | """ |
| 27 | Create the server group |
| 28 | name : Name of the server-group |
| 29 | policies : List of the policies - affinity/anti-affinity) |
| 30 | """ |
| 31 | post_body = { |
| 32 | 'name': name, |
| 33 | 'policies': policies, |
| 34 | } |
| 35 | |
| 36 | post_body = json.dumps({'server_group': post_body}) |
| 37 | resp, body = self.post('os-server-groups', post_body) |
| 38 | |
| 39 | body = json.loads(body) |
| 40 | self.validate_response(schema.create_get_server_group, resp, body) |
| 41 | return service_client.ResponseBody(resp, body['server_group']) |
| 42 | |
| 43 | def delete_server_group(self, server_group_id): |
| 44 | """Delete the given server-group.""" |
| 45 | resp, body = self.delete("os-server-groups/%s" % server_group_id) |
| 46 | self.validate_response(schema.delete_server_group, resp, body) |
| 47 | return service_client.ResponseBody(resp, body) |
| 48 | |
| 49 | def list_server_groups(self): |
| 50 | """List the server-groups.""" |
| 51 | resp, body = self.get("os-server-groups") |
| 52 | body = json.loads(body) |
| 53 | self.validate_response(schema.list_server_groups, resp, body) |
| 54 | return service_client.ResponseBodyList(resp, body['server_groups']) |
| 55 | |
| 56 | def get_server_group(self, server_group_id): |
| 57 | """Get the details of given server_group.""" |
| 58 | resp, body = self.get("os-server-groups/%s" % server_group_id) |
| 59 | body = json.loads(body) |
| 60 | self.validate_response(schema.create_get_server_group, resp, body) |
| 61 | return service_client.ResponseBody(resp, body['server_group']) |