Make sure we always requests JSON responses
This patch updates the client to make sure we are always requesting
JSON format responses. The osc_lib does not request JSON by default
for API calls.
If we don't request JSON responses, the Octavia API can return HTML
formated responses.
Change-Id: I7f64d0c1c74b67ab1097d00282e55b9ba1a4f5a7
Story: 2004283
Task: 27833
(cherry picked from commit 14875d44d4
)
This commit is contained in:
parent
7c25d5e85f
commit
64f64d504f
|
@ -12,6 +12,7 @@
|
|||
#
|
||||
|
||||
"""Octavia API Library"""
|
||||
import functools
|
||||
|
||||
from osc_lib.api import api
|
||||
|
||||
|
@ -50,6 +51,13 @@ class OctaviaAPI(api.BaseAPI):
|
|||
self.endpoint = self.endpoint.rstrip('/')
|
||||
self._build_url()
|
||||
|
||||
# Make sure we are always requesting JSON responses
|
||||
JSON_HEADER = {'Accept': 'application/json'}
|
||||
self._create = functools.partial(self.create, headers=JSON_HEADER)
|
||||
self._delete = functools.partial(self.delete, headers=JSON_HEADER)
|
||||
self._find = functools.partial(self.find, headers=JSON_HEADER)
|
||||
self._list = functools.partial(self.list, headers=JSON_HEADER)
|
||||
|
||||
def _build_url(self):
|
||||
if not self.endpoint.endswith(self._endpoint_suffix):
|
||||
self.endpoint += self._endpoint_suffix
|
||||
|
@ -63,7 +71,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
List of load balancers
|
||||
"""
|
||||
url = const.BASE_LOADBALANCER_URL
|
||||
response = self.list(url, **params)
|
||||
response = self._list(url, **params)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -75,7 +83,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
:return:
|
||||
A dict of the specified load balancer's settings
|
||||
"""
|
||||
response = self.find(path=const.BASE_LOADBALANCER_URL, value=lb_id)
|
||||
response = self._find(path=const.BASE_LOADBALANCER_URL, value=lb_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -89,7 +97,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the created load balancer's settings
|
||||
"""
|
||||
url = const.BASE_LOADBALANCER_URL
|
||||
response = self.create(url, **params)
|
||||
response = self._create(url, **params)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -105,7 +113,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_LB_URL.format(uuid=lb_id)
|
||||
response = self.delete(url, params=params)
|
||||
response = self._delete(url, params=params)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -121,7 +129,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from API
|
||||
"""
|
||||
url = const.BASE_SINGLE_LB_URL.format(uuid=lb_id)
|
||||
response = self.create(url, method='PUT', **params)
|
||||
response = self._create(url, method='PUT', **params)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -134,7 +142,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the specified load balancer's statistics
|
||||
"""
|
||||
url = const.BASE_LB_STATS_URL.format(uuid=lb_id)
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -148,7 +156,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_LOADBALANCER_FAILOVER_URL.format(uuid=lb_id)
|
||||
response = self.create(url, method='PUT')
|
||||
response = self._create(url, method='PUT')
|
||||
|
||||
return response
|
||||
|
||||
|
@ -161,7 +169,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
List of listeners
|
||||
"""
|
||||
url = const.BASE_LISTENER_URL
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -173,7 +181,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
:return:
|
||||
A dict of the specified listener's settings
|
||||
"""
|
||||
response = self.find(path=const.BASE_LISTENER_URL, value=listener_id)
|
||||
response = self._find(path=const.BASE_LISTENER_URL, value=listener_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -187,7 +195,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the created listener's settings
|
||||
"""
|
||||
url = const.BASE_LISTENER_URL
|
||||
response = self.create(url, **kwargs)
|
||||
response = self._create(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -201,7 +209,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_LISTENER_URL.format(uuid=listener_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -217,7 +225,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_LISTENER_URL.format(uuid=listener_id)
|
||||
response = self.create(url, method='PUT', **kwargs)
|
||||
response = self._create(url, method='PUT', **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -230,7 +238,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the specified listener's statistics
|
||||
"""
|
||||
url = const.BASE_LISTENER_STATS_URL.format(uuid=listener_id)
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -243,7 +251,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
List of pools
|
||||
"""
|
||||
url = const.BASE_POOL_URL
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -257,7 +265,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the created pool's settings
|
||||
"""
|
||||
url = const.BASE_POOL_URL
|
||||
response = self.create(url, **kwargs)
|
||||
response = self._create(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -271,7 +279,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_POOL_URL.format(pool_id=pool_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -283,7 +291,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
:return:
|
||||
Dict of the specified pool's settings
|
||||
"""
|
||||
response = self.find(path=const.BASE_POOL_URL, value=pool_id)
|
||||
response = self._find(path=const.BASE_POOL_URL, value=pool_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -299,7 +307,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_POOL_URL.format(pool_id=pool_id)
|
||||
response = self.create(url, method='PUT', **kwargs)
|
||||
response = self._create(url, method='PUT', **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -314,7 +322,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response list members
|
||||
"""
|
||||
url = const.BASE_MEMBER_URL.format(pool_id=pool_id)
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -331,7 +339,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response of member
|
||||
"""
|
||||
url = const.BASE_MEMBER_URL.format(pool_id=pool_id)
|
||||
response = self.find(path=url, value=member_id)
|
||||
response = self._find(path=url, value=member_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -347,7 +355,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A member details on successful creation
|
||||
"""
|
||||
url = const.BASE_MEMBER_URL.format(pool_id=pool_id)
|
||||
response = self.create(url, **kwargs)
|
||||
response = self._create(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -364,7 +372,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
"""
|
||||
url = const.BASE_SINGLE_MEMBER_URL.format(pool_id=pool_id,
|
||||
member_id=member_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -383,7 +391,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
"""
|
||||
url = const.BASE_SINGLE_MEMBER_URL.format(pool_id=pool_id,
|
||||
member_id=member_id)
|
||||
response = self.create(url, method='PUT', **kwargs)
|
||||
response = self._create(url, method='PUT', **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -396,7 +404,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
List of l7policies
|
||||
"""
|
||||
url = const.BASE_L7POLICY_URL
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -410,7 +418,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the created l7policy's settings
|
||||
"""
|
||||
url = const.BASE_L7POLICY_URL
|
||||
response = self.create(url, **kwargs)
|
||||
response = self._create(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -424,7 +432,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_L7POLICY_URL.format(policy_uuid=l7policy_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -436,7 +444,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
:return:
|
||||
Dict of the specified l7policy's settings
|
||||
"""
|
||||
response = self.find(path=const.BASE_L7POLICY_URL, value=l7policy_id)
|
||||
response = self._find(path=const.BASE_L7POLICY_URL, value=l7policy_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -452,7 +460,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Response Code from the API
|
||||
"""
|
||||
url = const.BASE_SINGLE_L7POLICY_URL.format(policy_uuid=l7policy_id)
|
||||
response = self.create(url, method='PUT', **kwargs)
|
||||
response = self._create(url, method='PUT', **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -465,7 +473,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
List of l7policies
|
||||
"""
|
||||
url = const.BASE_L7RULE_URL.format(policy_uuid=l7policy_id)
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -481,7 +489,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the created l7rule's settings
|
||||
"""
|
||||
url = const.BASE_L7RULE_URL.format(policy_uuid=l7policy_id)
|
||||
response = self.create(url, **kwargs)
|
||||
response = self._create(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -498,7 +506,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
"""
|
||||
url = const.BASE_SINGLE_L7RULE_URL.format(rule_uuid=l7rule_id,
|
||||
policy_uuid=l7policy_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -513,7 +521,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Dict of the specified l7rule's settings
|
||||
"""
|
||||
url = const.BASE_L7RULE_URL.format(policy_uuid=l7policy_id)
|
||||
response = self.find(path=url, value=l7rule_id)
|
||||
response = self._find(path=url, value=l7rule_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -532,7 +540,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
"""
|
||||
url = const.BASE_SINGLE_L7RULE_URL.format(rule_uuid=l7rule_id,
|
||||
policy_uuid=l7policy_id)
|
||||
response = self.create(url, method='PUT', **kwargs)
|
||||
response = self._create(url, method='PUT', **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -545,7 +553,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict containing a list of health monitors
|
||||
"""
|
||||
url = const.BASE_HEALTH_MONITOR_URL
|
||||
response = self.list(url, **kwargs)
|
||||
response = self._list(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -559,7 +567,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A dict of the created health monitor's settings
|
||||
"""
|
||||
url = const.BASE_HEALTH_MONITOR_URL
|
||||
response = self.create(url, **kwargs)
|
||||
response = self._create(url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -574,7 +582,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
"""
|
||||
url = const.BASE_SINGLE_HEALTH_MONITOR_URL.format(
|
||||
uuid=health_monitor_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -587,7 +595,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
Dict of the specified health monitor's settings
|
||||
"""
|
||||
url = const.BASE_HEALTH_MONITOR_URL
|
||||
response = self.find(path=url, value=health_monitor_id)
|
||||
response = self._find(path=url, value=health_monitor_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -604,7 +612,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
"""
|
||||
url = const.BASE_SINGLE_HEALTH_MONITOR_URL.format(
|
||||
uuid=health_monitor_id)
|
||||
response = self.create(url, method='PUT', **kwargs)
|
||||
response = self._create(url, method='PUT', **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -617,7 +625,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A ``dict`` representing a list of quotas for the project
|
||||
"""
|
||||
url = const.BASE_QUOTA_URL
|
||||
response = self.list(url, **params)
|
||||
response = self._list(url, **params)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -629,7 +637,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
:return:
|
||||
A ``dict`` representing the quota for the project
|
||||
"""
|
||||
response = self.find(path=const.BASE_QUOTA_URL, value=project_id)
|
||||
response = self._find(path=const.BASE_QUOTA_URL, value=project_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -643,7 +651,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
``None``
|
||||
"""
|
||||
url = const.BASE_SINGLE_QUOTA_URL.format(uuid=project_id)
|
||||
response = self.delete(url)
|
||||
response = self._delete(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -659,7 +667,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A ``dict`` representing the updated quota
|
||||
"""
|
||||
url = const.BASE_SINGLE_QUOTA_URL.format(uuid=project_id)
|
||||
response = self.create(url, method='PUT', **params)
|
||||
response = self._create(url, method='PUT', **params)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -670,7 +678,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A ``dict`` representing a list of quota defaults
|
||||
"""
|
||||
url = const.BASE_QUOTA_DEFAULT_URL
|
||||
response = self.list(url)
|
||||
response = self._list(url)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -683,7 +691,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A ``dict`` of the specified amphora's attributes
|
||||
"""
|
||||
url = const.BASE_AMPHORA_URL
|
||||
response = self.find(path=url, value=amphora_id)
|
||||
response = self._find(path=url, value=amphora_id)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -696,7 +704,7 @@ class OctaviaAPI(api.BaseAPI):
|
|||
A ``dict`` containing a list of amphorae
|
||||
"""
|
||||
url = const.BASE_AMPHORA_URL
|
||||
response = self.list(path=url, **kwargs)
|
||||
response = self._list(path=url, **kwargs)
|
||||
|
||||
return response
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
The client will now always ask for a JSON format response from the Octavia
|
||||
API. This resolves a client side bug should certain errors be returned
|
||||
by the API.
|
Loading…
Reference in New Issue