From 5822e29d4128421b6879496605a2987b0e128a8b Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Fri, 10 Mar 2017 17:02:22 +0000 Subject: [PATCH] Always update existing matching endpoints There is no usecase for having 2 endpoints that have the same Region, interface, service_name and service_type. The keystone module should default to update these endpoints if the url is different, but the Region, interface, service_name and service_type match. This will make the default behaviour of state "present" to match that of state "update". Change-Id: I0ade538e20f2a926b33c1637446c2d4f650cd13d --- library/keystone | 28 ++++++++++++++++--- ...lugin_default_update-c025bd5508069df3.yaml | 12 ++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/keystone_plugin_default_update-c025bd5508069df3.yaml diff --git a/library/keystone b/library/keystone index 823b456..a89a76f 100644 --- a/library/keystone +++ b/library/keystone @@ -200,7 +200,8 @@ options: default: True state: description: - - Ensuring the endpoint is either present, absent, or update + - Ensuring the endpoint is either present, absent. + - It always ensures endpoint is updated to latest url. required: False default: 'present' command: @@ -1118,9 +1119,24 @@ class ManageKeystone(object): ) if state == 'present': ''' Creating an endpoint for this url - (if it does not exist) + (if it does not exist) or updating + an existing endpoint that matches + the service type, name, interface + and region. ''' - if endpoint is None: + similar_endpoint = self._get_endpoint_by_details( + region=region, + service_id=service.id, + interface=interface + ) + if similar_endpoint is not None: + if similar_endpoint.url != url: + self.state_change = True + endpoint = self.keystone.endpoints.update( + endpoint=similar_endpoint, + url=url + ) + elif endpoint is None: self.state_change = True endpoint = self.keystone.endpoints.create( region=region, @@ -1128,10 +1144,13 @@ class ManageKeystone(object): url=url, interface=interface ) + # The update state is deprecated and should be removed in Q elif state == 'update': ''' Checking if there is a similar endpoint with a different url. Update it if there is one, create - if there is none. + if there is none. Update is deprecated and will + be removed in Q. "Present" achieves the same + result. ''' similar_endpoint = self._get_endpoint_by_details( region=region, @@ -1263,6 +1282,7 @@ class ManageKeystone(object): ) +# TODO(evrardjp): Deprecate state=update in Q. def main(): module = AnsibleModule( argument_spec=dict( diff --git a/releasenotes/notes/keystone_plugin_default_update-c025bd5508069df3.yaml b/releasenotes/notes/keystone_plugin_default_update-c025bd5508069df3.yaml new file mode 100644 index 0000000..69d5e71 --- /dev/null +++ b/releasenotes/notes/keystone_plugin_default_update-c025bd5508069df3.yaml @@ -0,0 +1,12 @@ +--- +features: + - The default behaviour of ``ensure_endpoint`` in the + keystone module has changed to update an existing + endpoint, if one exists that matches the service + name, type, region and interface. This ensures that + no duplicate service entries can exist per region. +deprecations: + - The ``update`` state for the ``ensure_endpoint`` + method of the ``keystone`` module is now deprecated, + and will be removed in the Queens cycle. Setting + state to ``present`` will achieve the same result.