Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [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 | from oslo_serialization import jsonutils as json |
| 18 | |
| 19 | from tempest.lib.api_schema.response.compute.v2_1 import servers as schema |
| 20 | from tempest.lib.common import rest_client |
| 21 | |
| 22 | |
| 23 | class ServerGroupsClient(rest_client.RestClient): |
| 24 | |
| 25 | def create_server_group(self, **kwargs): |
| 26 | """Create the server group. |
| 27 | |
| 28 | Available params: see http://developer.openstack.org/ |
| 29 | api-ref-compute-v2.1.html#createServerGroup |
| 30 | """ |
| 31 | post_body = json.dumps({'server_group': kwargs}) |
| 32 | resp, body = self.post('os-server-groups', post_body) |
| 33 | |
| 34 | body = json.loads(body) |
| 35 | self.validate_response(schema.create_show_server_group, resp, body) |
| 36 | return rest_client.ResponseBody(resp, body) |
| 37 | |
| 38 | def delete_server_group(self, server_group_id): |
| 39 | """Delete the given server-group.""" |
| 40 | resp, body = self.delete("os-server-groups/%s" % server_group_id) |
| 41 | self.validate_response(schema.delete_server_group, resp, body) |
| 42 | return rest_client.ResponseBody(resp, body) |
| 43 | |
| 44 | def list_server_groups(self): |
| 45 | """List the server-groups.""" |
| 46 | resp, body = self.get("os-server-groups") |
| 47 | body = json.loads(body) |
| 48 | self.validate_response(schema.list_server_groups, resp, body) |
| 49 | return rest_client.ResponseBody(resp, body) |
| 50 | |
| 51 | def show_server_group(self, server_group_id): |
| 52 | """Get the details of given server_group.""" |
| 53 | resp, body = self.get("os-server-groups/%s" % server_group_id) |
| 54 | body = json.loads(body) |
| 55 | self.validate_response(schema.create_show_server_group, resp, body) |
| 56 | return rest_client.ResponseBody(resp, body) |