Merge "Bring delete and update functions to keystone module"
This commit is contained in:
commit
b9c74c197b
100
library/keystone
100
library/keystone
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
# (c) 2014, Kevin Carter <kevin.carter@rackspace.com>
|
# (c) 2014, Kevin Carter <kevin.carter@rackspace.com>
|
||||||
#
|
#
|
||||||
# Copyright 2014, Rackspace US, Inc.
|
# Copyright 2014, Rackspace US, Inc.
|
||||||
@ -197,6 +198,11 @@ options:
|
|||||||
- Name for a domain
|
- Name for a domain
|
||||||
required: False
|
required: False
|
||||||
default: True
|
default: True
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Ensuring the endpoint is either present, absent, or update
|
||||||
|
required: False
|
||||||
|
default: 'present'
|
||||||
command:
|
command:
|
||||||
description:
|
description:
|
||||||
- Indicate desired state of the resource
|
- Indicate desired state of the resource
|
||||||
@ -345,7 +351,8 @@ COMMAND_MAP = {
|
|||||||
'region_name',
|
'region_name',
|
||||||
'service_name',
|
'service_name',
|
||||||
'service_type',
|
'service_type',
|
||||||
'endpoint_list'
|
'endpoint_list',
|
||||||
|
'state'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'ensure_role': {
|
'ensure_role': {
|
||||||
@ -1016,7 +1023,35 @@ class ManageKeystone(object):
|
|||||||
|
|
||||||
return self._facts(facts={'id': service.id})
|
return self._facts(facts={'id': service.id})
|
||||||
|
|
||||||
|
def _get_endpoint_by_details(self, region, service_id, interface):
|
||||||
|
""" Getting endpoints per complete definition
|
||||||
|
|
||||||
|
Returns the endpoint details for an endpoint matching
|
||||||
|
region, service id and interface.
|
||||||
|
|
||||||
|
:param interface: ``str`` ‘public’, ‘admin’ or ‘internal’ network
|
||||||
|
interface
|
||||||
|
:param service_id: service to which the endpoint belongs
|
||||||
|
:param region: geographic location of the endpoint
|
||||||
|
|
||||||
|
"""
|
||||||
|
for entry in self.keystone.endpoints.list():
|
||||||
|
check = [
|
||||||
|
entry.region == region,
|
||||||
|
entry.service_id == service_id,
|
||||||
|
entry.interface == interface
|
||||||
|
]
|
||||||
|
if all(check):
|
||||||
|
return entry
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def _get_endpoint(self, region, url, interface):
|
def _get_endpoint(self, region, url, interface):
|
||||||
|
""" Getting endpoints per URL
|
||||||
|
Returns the endpoint details for an endpoint matching
|
||||||
|
URL, region and interface.
|
||||||
|
This interface should be deprecated in next release.
|
||||||
|
"""
|
||||||
for entry in self.keystone.endpoints.list():
|
for entry in self.keystone.endpoints.list():
|
||||||
check = [
|
check = [
|
||||||
entry.region == region,
|
entry.region == region,
|
||||||
@ -1029,7 +1064,8 @@ class ManageKeystone(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def ensure_endpoint(self, variables):
|
def ensure_endpoint(self, variables):
|
||||||
"""Create a new endpoint within Keystone if it does not exist.
|
"""Ensures the deletion/modification/addition of endpoints
|
||||||
|
within Keystone.
|
||||||
|
|
||||||
Returns the endpoint ID on a successful run.
|
Returns the endpoint ID on a successful run.
|
||||||
|
|
||||||
@ -1049,6 +1085,7 @@ class ManageKeystone(object):
|
|||||||
service_type = variables_dict.pop('service_type')
|
service_type = variables_dict.pop('service_type')
|
||||||
region = variables_dict.pop('region_name')
|
region = variables_dict.pop('region_name')
|
||||||
endpoint_list = variables_dict.pop('endpoint_list')
|
endpoint_list = variables_dict.pop('endpoint_list')
|
||||||
|
state = variables_dict.pop('state')
|
||||||
|
|
||||||
service = self._get_service(name=service_name, srv_type=service_type)
|
service = self._get_service(name=service_name, srv_type=service_type)
|
||||||
if service is None:
|
if service is None:
|
||||||
@ -1067,19 +1104,55 @@ class ManageKeystone(object):
|
|||||||
url=url,
|
url=url,
|
||||||
interface=interface
|
interface=interface
|
||||||
)
|
)
|
||||||
if endpoint is None:
|
if state == 'present':
|
||||||
self.state_change = True
|
''' Creating an endpoint for this url
|
||||||
endpoint = self.keystone.endpoints.create(
|
(if it does not exist)
|
||||||
|
'''
|
||||||
|
if endpoint is None:
|
||||||
|
self.state_change = True
|
||||||
|
endpoint = self.keystone.endpoints.create(
|
||||||
|
region=region,
|
||||||
|
service=service,
|
||||||
|
url=url,
|
||||||
|
interface=interface
|
||||||
|
)
|
||||||
|
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.
|
||||||
|
'''
|
||||||
|
similar_endpoint = self._get_endpoint_by_details(
|
||||||
region=region,
|
region=region,
|
||||||
service=service,
|
service_id=service.id,
|
||||||
url=url,
|
|
||||||
interface=interface
|
interface=interface
|
||||||
)
|
)
|
||||||
endpoints[interface] = endpoint
|
if similar_endpoint is None:
|
||||||
|
self.state_change = True
|
||||||
|
endpoint = self.keystone.endpoints.create(
|
||||||
|
region=region,
|
||||||
|
service=service,
|
||||||
|
url=url,
|
||||||
|
interface=interface
|
||||||
|
)
|
||||||
|
elif similar_endpoint.url != url:
|
||||||
|
self.state_change = True
|
||||||
|
endpoint = self.keystone.endpoints.update(
|
||||||
|
endpoint=similar_endpoint,
|
||||||
|
url=url
|
||||||
|
)
|
||||||
|
elif state == 'absent':
|
||||||
|
if endpoint is not None:
|
||||||
|
self.state_change = True
|
||||||
|
result = self.keystone.endpoints.delete(endpoint.id)
|
||||||
|
if result[0].status_code != 204:
|
||||||
|
module.fail()
|
||||||
|
|
||||||
return self._facts(
|
if state != 'absent':
|
||||||
facts={'%sid' % interface: endpoint.id
|
endpoints[interface] = endpoint
|
||||||
for interface, endpoint in endpoints.items()})
|
return self._facts({'%sid' % interface: endpoint.id
|
||||||
|
for interface, endpoint in endpoints.items()})
|
||||||
|
else:
|
||||||
|
return self._facts({})
|
||||||
|
|
||||||
def _ensure_generic(self, manager, required_vars, variables):
|
def _ensure_generic(self, manager, required_vars, variables):
|
||||||
"""Try and create a new 'thing' in keystone.
|
"""Try and create a new 'thing' in keystone.
|
||||||
@ -1305,6 +1378,11 @@ def main():
|
|||||||
type='bool',
|
type='bool',
|
||||||
required=False,
|
required=False,
|
||||||
default=True
|
default=True
|
||||||
|
),
|
||||||
|
state=dict(
|
||||||
|
choices=['present', 'absent', 'update'],
|
||||||
|
required=False,
|
||||||
|
default='present'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
supports_check_mode=False,
|
supports_check_mode=False,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user