| 1 |
# Copyright 2012-2015 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 |
|
| 16 |
|
| 17 |
class Manager: |
| 18 |
DEFAULT_HEADERS = { |
| 19 |
"Accept": "application/json", |
| 20 |
} |
| 21 |
|
| 22 |
def __init__(self, client): |
| 23 |
self.client = client |
| 24 |
|
| 25 |
def _set_default_headers(self, kwargs): |
| 26 |
headers = kwargs.get('headers', {}) |
| 27 |
for k, v in self.DEFAULT_HEADERS.items(): |
| 28 |
if k not in headers: |
| 29 |
headers[k] = v |
| 30 |
kwargs['headers'] = headers |
| 31 |
return kwargs |
| 32 |
|
| 33 |
def _get(self, *args, **kwargs): |
| 34 |
self._set_default_headers(kwargs) |
| 35 |
return self.client.api.get(*args, **kwargs) |
| 36 |
|
| 37 |
def _post(self, *args, **kwargs): |
| 38 |
self._set_default_headers(kwargs) |
| 39 |
return self.client.api.post(*args, **kwargs) |
| 40 |
|
| 41 |
def _put(self, *args, **kwargs): |
| 42 |
self._set_default_headers(kwargs) |
| 43 |
return self.client.api.put(*args, **kwargs) |
| 44 |
|
| 45 |
def _patch(self, *args, **kwargs): |
| 46 |
self._set_default_headers(kwargs) |
| 47 |
return self.client.api.patch(*args, **kwargs) |
| 48 |
|
| 49 |
def _delete(self, *args, **kwargs): |
| 50 |
self._set_default_headers(kwargs) |
| 51 |
return self.client.api.delete(*args, **kwargs) |