Add support for bodyless commits

Add a flag that can be used for things like the load balancer action
objects that don't have a body but are just a URL that needs to be
hit.

Change-Id: I32b3f6a92b7ee67d7092ce833f881613d6d46867
This commit is contained in:
Monty Taylor 2019-02-02 13:36:56 +00:00 committed by Michael Johnson
parent 1249d5fd26
commit 96c823c99f
3 changed files with 20 additions and 46 deletions

View File

@ -87,6 +87,7 @@ class AmphoraConfig(resource.Resource):
allow_commit = True
allow_delete = False
allow_list = False
allow_empty_commit = True
requires_id = False
@ -94,23 +95,11 @@ class AmphoraConfig(resource.Resource):
#: The ID of the amphora.
amphora_id = resource.URI('amphora_id')
# The parent commit method assumes there is a header or body change,
# which we do not have here. The default _update code path also has no
# The default _update code path also has no
# way to pass has_body into this function, so overriding the method here.
def commit(self, session, base_path=None):
kwargs = {}
request = self._prepare_request(prepend_key=False,
base_path=base_path,
**kwargs)
session = self._get_session(session)
kwargs = {}
microversion = self._get_microversion_for(session, 'commit')
response = session.put(request.url, json=request.body,
headers=request.headers,
microversion=microversion, **kwargs)
self.microversion = microversion
self._translate_response(response, has_body=False)
return self
return super(AmphoraConfig, self).commit(
session, base_path=base_path, has_body=False)
class AmphoraFailover(resource.Resource):
@ -122,6 +111,7 @@ class AmphoraFailover(resource.Resource):
allow_commit = True
allow_delete = False
allow_list = False
allow_empty_commit = True
requires_id = False
@ -129,20 +119,8 @@ class AmphoraFailover(resource.Resource):
#: The ID of the amphora.
amphora_id = resource.URI('amphora_id')
# The parent commit method assumes there is a header or body change,
# which we do not have here. The default _update code path also has no
# The default _update code path also has no
# way to pass has_body into this function, so overriding the method here.
def commit(self, session, base_path=None):
kwargs = {}
request = self._prepare_request(prepend_key=False,
base_path=base_path,
**kwargs)
session = self._get_session(session)
kwargs = {}
microversion = self._get_microversion_for(session, 'commit')
response = session.put(request.url, json=request.body,
headers=request.headers,
microversion=microversion, **kwargs)
self.microversion = microversion
self._translate_response(response, has_body=False)
return self
return super(AmphoraFailover, self).commit(
session, base_path=base_path, has_body=False)

View File

@ -124,6 +124,7 @@ class LoadBalancerFailover(resource.Resource):
allow_commit = True
allow_delete = False
allow_list = False
allow_empty_commit = True
requires_id = False
@ -131,20 +132,8 @@ class LoadBalancerFailover(resource.Resource):
#: The ID of the load balancer.
lb_id = resource.URI('lb_id')
# The parent commit method assumes there is a header or body change,
# which we do not have here. The default _update code path also has no
# The default _update code path also has no
# way to pass has_body into this function, so overriding the method here.
def commit(self, session, base_path=None):
kwargs = {}
request = self._prepare_request(prepend_key=False,
base_path=base_path,
**kwargs)
session = self._get_session(session)
kwargs = {}
microversion = self._get_microversion_for(session, 'commit')
response = session.put(request.url, json=request.body,
headers=request.headers,
microversion=microversion, **kwargs)
self.microversion = microversion
self._translate_response(response, has_body=False)
return self
return super(LoadBalancerFailover, self).commit(
session, base_path=base_path, has_body=False)

View File

@ -392,6 +392,9 @@ class Resource(dict):
# OSC no longer checks for allow_get
allow_get = True
#: Commits happen without header or body being dirty.
allow_empty_commit = False
#: Method for committing a resource (PUT, PATCH, POST)
commit_method = "PUT"
#: Method for creating a resource (POST, PUT)
@ -1176,7 +1179,11 @@ class Resource(dict):
self._body._dirty.discard("id")
# Only try to update if we actually have anything to commit.
if not any([self._body.dirty, self._header.dirty]):
if not any([
self._body.dirty,
self._header.dirty,
self.allow_empty_commit,
]):
return self
if not self.allow_commit: