Ghanshyam | bbdb33b | 2016-01-08 11:51:07 +0900 | [diff] [blame] | 1 | # Copyright 2016 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | from tempest_lib.common import rest_client |
| 16 | |
| 17 | |
| 18 | class BaseMicroversionClient(rest_client.RestClient): |
| 19 | """Base class to support microversion in service clients |
| 20 | |
| 21 | This class is used to support microversion in service clients. |
| 22 | This provides feature to make API request with microversion. |
| 23 | Service clients derived from this class will be able to send API |
| 24 | request to server with or without microversion. |
| 25 | If api_microversion is not set on service client then API request will be |
| 26 | normal request without microversion. |
| 27 | |
| 28 | """ |
| 29 | def __init__(self, auth_provider, service, region, |
| 30 | api_microversion_header_name, **kwargs): |
| 31 | """Base Microversion Client __init__ |
| 32 | |
| 33 | :param auth_provider: an auth provider object used to wrap requests in |
| 34 | auth |
| 35 | :param str service: The service name to use for the catalog lookup |
| 36 | :param str region: The region to use for the catalog lookup |
| 37 | :param str api_microversion_header_name: The microversion header name |
| 38 | to use for sending API |
| 39 | request with microversion |
| 40 | :param kwargs: kwargs required by rest_client.RestClient |
| 41 | """ |
| 42 | super(BaseMicroversionClient, self).__init__( |
| 43 | auth_provider, service, region, **kwargs) |
| 44 | self.api_microversion_header_name = api_microversion_header_name |
| 45 | self.api_microversion = None |
| 46 | |
| 47 | def get_headers(self): |
| 48 | headers = super(BaseMicroversionClient, self).get_headers() |
| 49 | if self.api_microversion: |
| 50 | headers[self.api_microversion_header_name] = self.api_microversion |
| 51 | return headers |
| 52 | |
| 53 | def set_api_microversion(self, microversion): |
| 54 | self.api_microversion = microversion |