blob: b6dbe2802353376fd19de03a32ac0513856b94be [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# Copyright 2013 NEC Corporation
2# Copyright 2013 IBM Corp.
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
18from six.moves.urllib import parse as urllib
19
20from tempest.lib.api_schema.response.compute.v2_1 import services as schema
21from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090022from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050023
24
Ghanshyamee9af302016-02-25 06:12:43 +090025class ServicesClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050026
27 def list_services(self, **params):
Lv Fumei7e326332016-07-08 15:18:03 +080028 """Lists all running Compute services for a tenant.
29
30 Available params: see http://developer.openstack.org/
31 api-ref-compute-v2.1.html#listServices
32 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -050033 url = 'os-services'
34 if params:
35 url += '?%s' % urllib.urlencode(params)
36
37 resp, body = self.get(url)
38 body = json.loads(body)
39 self.validate_response(schema.list_services, resp, body)
40 return rest_client.ResponseBody(resp, body)
41
42 def enable_service(self, **kwargs):
43 """Enable service on a host.
44
45 Available params: see http://developer.openstack.org/
46 api-ref-compute-v2.1.html#enableScheduling
47 """
48 post_body = json.dumps(kwargs)
49 resp, body = self.put('os-services/enable', post_body)
50 body = json.loads(body)
51 self.validate_response(schema.enable_disable_service, resp, body)
52 return rest_client.ResponseBody(resp, body)
53
54 def disable_service(self, **kwargs):
55 """Disable service on a host.
56
57 Available params: see http://developer.openstack.org/
58 api-ref-compute-v2.1.html#disableScheduling
59 """
60 post_body = json.dumps(kwargs)
61 resp, body = self.put('os-services/disable', post_body)
62 body = json.loads(body)
63 self.validate_response(schema.enable_disable_service, resp, body)
64 return rest_client.ResponseBody(resp, body)