blob: 094e5674e20b5a6916a287eae70d75aeef75e266 [file] [log] [blame]
harika-vakadia92dd742013-02-19 20:41:22 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import json
harika-vakadia92dd742013-02-19 20:41:22 +053017
18from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
harika-vakadia92dd742013-02-19 20:41:22 +053022
23
24class ServiceClientJSON(RestClient):
25
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(ServiceClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.identity.catalog_type
harika-vakadia92dd742013-02-19 20:41:22 +053029 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000030 self.api_version = "v3"
harika-vakadia92dd742013-02-19 20:41:22 +053031
32 def update_service(self, service_id, **kwargs):
33 """Updates a service."""
34 resp, body = self.get_service(service_id)
35 name = kwargs.get('name', body['name'])
36 type = kwargs.get('type', body['type'])
37 desc = kwargs.get('description', body['description'])
38 patch_body = {
39 'description': desc,
40 'type': type,
41 'name': name
42 }
43 patch_body = json.dumps({'service': patch_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020044 resp, body = self.patch('services/%s' % service_id, patch_body)
harika-vakadia92dd742013-02-19 20:41:22 +053045 body = json.loads(body)
46 return resp, body['service']
47
48 def get_service(self, service_id):
49 """Get Service."""
50 url = 'services/%s' % service_id
51 resp, body = self.get(url)
52 body = json.loads(body)
53 return resp, body['service']