blob: 4e3383fcd0176b2cd3366342d835a4180aaee5d7 [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
Felipe Monteirofe399fd2017-05-29 21:46:44 +010021from tempest.lib.api_schema.response.compute.v2_11 import services \
22 as schemav211
Felipe Monteiroc0348ee2018-07-07 16:14:13 -040023from tempest.lib.api_schema.response.compute.v2_53 import services \
24 as schemav253
Matthew Treinish9e26ca82016-02-23 11:43:20 -050025from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090026from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050027
28
Ghanshyamee9af302016-02-25 06:12:43 +090029class ServicesClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050030
Felipe Monteirofe399fd2017-05-29 21:46:44 +010031 schema_versions_info = [
32 {'min': None, 'max': '2.10', 'schema': schema},
Felipe Monteiroc0348ee2018-07-07 16:14:13 -040033 {'min': '2.11', 'max': '2.52', 'schema': schemav211},
34 {'min': '2.53', 'max': None, 'schema': schemav253}]
Felipe Monteirofe399fd2017-05-29 21:46:44 +010035
Matthew Treinish9e26ca82016-02-23 11:43:20 -050036 def list_services(self, **params):
Lv Fumei7e326332016-07-08 15:18:03 +080037 """Lists all running Compute services for a tenant.
38
Dong Mad12c2332016-10-19 01:36:27 -070039 For a full list of available parameters, please refer to the official
40 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020041 https://docs.openstack.org/api-ref/compute/#list-compute-services
Lv Fumei7e326332016-07-08 15:18:03 +080042 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -050043 url = 'os-services'
44 if params:
45 url += '?%s' % urllib.urlencode(params)
46
47 resp, body = self.get(url)
48 body = json.loads(body)
Felipe Monteirofe399fd2017-05-29 21:46:44 +010049 _schema = self.get_schema(self.schema_versions_info)
50 self.validate_response(_schema.list_services, resp, body)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050051 return rest_client.ResponseBody(resp, body)
52
Felipe Monteiroc0348ee2018-07-07 16:14:13 -040053 def update_service(self, service_id, **kwargs):
54 """Update a compute service.
55
56 Update a compute service to enable or disable scheduling, including
57 recording a reason why a compute service was disabled from scheduling.
58
59 This API is available starting with microversion 2.53.
60
61 For a full list of available parameters, please refer to the official
62 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020063 https://docs.openstack.org/api-ref/compute/#update-compute-service
Felipe Monteiroc0348ee2018-07-07 16:14:13 -040064 """
65 put_body = json.dumps(kwargs)
66 resp, body = self.put('os-services/%s' % service_id, put_body)
67 body = json.loads(body)
68 _schema = self.get_schema(self.schema_versions_info)
69 self.validate_response(_schema.update_service, resp, body)
70 return rest_client.ResponseBody(resp, body)
71
Matthew Treinish9e26ca82016-02-23 11:43:20 -050072 def enable_service(self, **kwargs):
73 """Enable service on a host.
74
Felipe Monteiroc0348ee2018-07-07 16:14:13 -040075 ``update_service`` supersedes this API starting with microversion 2.53.
76
Dong Mad12c2332016-10-19 01:36:27 -070077 For a full list of available parameters, please refer to the official
78 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020079 https://docs.openstack.org/api-ref/compute/#enable-scheduling-for-a-compute-service
Matthew Treinish9e26ca82016-02-23 11:43:20 -050080 """
81 post_body = json.dumps(kwargs)
82 resp, body = self.put('os-services/enable', post_body)
83 body = json.loads(body)
84 self.validate_response(schema.enable_disable_service, resp, body)
85 return rest_client.ResponseBody(resp, body)
86
87 def disable_service(self, **kwargs):
88 """Disable service on a host.
89
Felipe Monteiroc0348ee2018-07-07 16:14:13 -040090 ``update_service`` supersedes this API starting with microversion 2.53.
91
Dong Mad12c2332016-10-19 01:36:27 -070092 For a full list of available parameters, please refer to the official
93 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020094 https://docs.openstack.org/api-ref/compute/#disable-scheduling-for-a-compute-service
Matthew Treinish9e26ca82016-02-23 11:43:20 -050095 """
96 post_body = json.dumps(kwargs)
97 resp, body = self.put('os-services/disable', post_body)
98 body = json.loads(body)
99 self.validate_response(schema.enable_disable_service, resp, body)
100 return rest_client.ResponseBody(resp, body)
Felipe Monteirofe399fd2017-05-29 21:46:44 +0100101
102 def disable_log_reason(self, **kwargs):
103 """Disables scheduling for a Compute service and logs reason.
104
Felipe Monteiroc0348ee2018-07-07 16:14:13 -0400105 ``update_service`` supersedes this API starting with microversion 2.53.
106
Felipe Monteirofe399fd2017-05-29 21:46:44 +0100107 For a full list of available parameters, please refer to the official
108 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200109 https://docs.openstack.org/api-ref/compute/#disable-scheduling-for-a-compute-service-and-log-disabled-reason
Felipe Monteirofe399fd2017-05-29 21:46:44 +0100110 """
111 post_body = json.dumps(kwargs)
112 resp, body = self.put('os-services/disable-log-reason', post_body)
113 body = json.loads(body)
114 self.validate_response(schema.disable_log_reason, resp, body)
115 return rest_client.ResponseBody(resp, body)
116
117 def update_forced_down(self, **kwargs):
118 """Set or unset ``forced_down`` flag for the service.
119
Felipe Monteiroc0348ee2018-07-07 16:14:13 -0400120 ``update_service`` supersedes this API starting with microversion 2.53.
121
Felipe Monteirofe399fd2017-05-29 21:46:44 +0100122 For a full list of available parameters, please refer to the official
123 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +0200124 https://docs.openstack.org/api-ref/compute/#update-forced-down
Felipe Monteirofe399fd2017-05-29 21:46:44 +0100125 """
126 post_body = json.dumps(kwargs)
127 resp, body = self.put('os-services/force-down', post_body)
128 body = json.loads(body)
129 # NOTE: Use schemav211.update_forced_down directly because there is no
130 # update_forced_down schema for <2.11.
131 self.validate_response(schemav211.update_forced_down, resp, body)
132 return rest_client.ResponseBody(resp, body)