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
This commit is contained in:
Andy McCrae 2017-03-10 17:02:22 +00:00 committed by Andy McCrae
parent 14d2727c04
commit 5822e29d41
2 changed files with 36 additions and 4 deletions

View File

@ -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(

View File

@ -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.