Repository: libcloud Updated Branches: refs/heads/trunk 763236f36 -> b016fa224
Override request method in the OpenStackBaseConnection and send a default "Content-Type" header if "default_content_type" attribute is set. This way, all the connection classes which inherit from this class don't need to duplicate the logic and override request themselves. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/b016fa22 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b016fa22 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b016fa22 Branch: refs/heads/trunk Commit: b016fa224750fb70f2c0a18bffa4fc61ded96666 Parents: 763236f Author: Tomaz Muraus <[email protected]> Authored: Thu Aug 7 11:22:56 2014 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Thu Aug 7 11:29:54 2014 +0200 ---------------------------------------------------------------------- libcloud/common/openstack.py | 17 +++++++++++++++++ libcloud/compute/drivers/openstack.py | 15 --------------- 2 files changed, 17 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/b016fa22/libcloud/common/openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py index ac5d5ac..2d3b9d2 100644 --- a/libcloud/common/openstack.py +++ b/libcloud/common/openstack.py @@ -575,6 +575,23 @@ class OpenStackBaseConnection(ConnectionUserAndKey): timeout=self.timeout) self._osa = osa + def request(self, action, params=None, data='', headers=None, + method='GET', raw=False): + headers = headers or {} + params = params or {} + + # Include default content-type for POST and PUT request (if available) + default_content_type = getattr(self, 'default_content_type', None) + if method.upper() in ['POST', 'PUT'] and default_content_type: + headers = {'Content-Type': default_content_type} + + return super(OpenStackBaseConnection, self).request(action=action, + params=params, + data=data, + method=method, + headers=headers, + raw=raw) + def _get_auth_url(self): """ Retrieve auth url for this instance using either "ex_force_auth_url" http://git-wip-us.apache.org/repos/asf/libcloud/blob/b016fa22/libcloud/compute/drivers/openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index edad98a..93834dc 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -73,21 +73,6 @@ class OpenStackComputeConnection(OpenStackBaseConnection): service_name = 'nova' service_region = 'RegionOne' - def request(self, action, params=None, data='', headers=None, - method='GET'): - if not headers: - headers = {} - if not params: - params = {} - - if method in ("POST", "PUT"): - headers = {'Content-Type': self.default_content_type} - - return super(OpenStackComputeConnection, self).request( - action=action, - params=params, data=data, - method=method, headers=headers) - class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin): """
