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