blob: 9ba8d38df07b9746de68a392e9cf9f9ffddcb08e [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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
17from oslo_serialization import jsonutils as json
18
19from tempest.lib.api_schema.response.compute.v2_1 import servers as schema
20from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090021from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050022
23
Ghanshyamee9af302016-02-25 06:12:43 +090024class ServerGroupsClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050025
26 def create_server_group(self, **kwargs):
27 """Create the server group.
28
Dong Mad12c2332016-10-19 01:36:27 -070029 For a full list of available parameters, please refer to the official
30 API reference:
31 http://developer.openstack.org/api-ref-compute-v2.1.html#createServerGroup
Matthew Treinish9e26ca82016-02-23 11:43:20 -050032 """
33 post_body = json.dumps({'server_group': kwargs})
34 resp, body = self.post('os-server-groups', post_body)
35
36 body = json.loads(body)
37 self.validate_response(schema.create_show_server_group, resp, body)
38 return rest_client.ResponseBody(resp, body)
39
40 def delete_server_group(self, server_group_id):
41 """Delete the given server-group."""
42 resp, body = self.delete("os-server-groups/%s" % server_group_id)
43 self.validate_response(schema.delete_server_group, resp, body)
44 return rest_client.ResponseBody(resp, body)
45
46 def list_server_groups(self):
47 """List the server-groups."""
48 resp, body = self.get("os-server-groups")
49 body = json.loads(body)
50 self.validate_response(schema.list_server_groups, resp, body)
51 return rest_client.ResponseBody(resp, body)
52
53 def show_server_group(self, server_group_id):
54 """Get the details of given server_group."""
55 resp, body = self.get("os-server-groups/%s" % server_group_id)
56 body = json.loads(body)
57 self.validate_response(schema.create_show_server_group, resp, body)
58 return rest_client.ResponseBody(resp, body)