mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 06:13:13 +00:00
Merge "Update endpoint to new proxy layer"
This commit is contained in:
@@ -69,6 +69,7 @@
|
|||||||
client_config
|
client_config
|
||||||
dns
|
dns
|
||||||
dns_zone_info
|
dns_zone_info
|
||||||
|
endpoint
|
||||||
floating_ip_info
|
floating_ip_info
|
||||||
group
|
group
|
||||||
host_aggregate
|
host_aggregate
|
||||||
|
|||||||
65
ci/roles/endpoint/tasks/main.yml
Normal file
65
ci/roles/endpoint/tasks/main.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
- name: Create a service for compute
|
||||||
|
openstack.cloud.endpoint:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
service: nova
|
||||||
|
endpoint_interface: internal
|
||||||
|
url: http://controller:9292
|
||||||
|
region: RegionOne
|
||||||
|
state: present
|
||||||
|
register: endpoint_test
|
||||||
|
|
||||||
|
- name: Ensure service was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- endpoint_test.endpoint.id is defined
|
||||||
|
|
||||||
|
- name: Ensure service have the proper endpoint
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- endpoint_test.endpoint.url == "http://controller:9292"
|
||||||
|
|
||||||
|
- name: Create service for compute again
|
||||||
|
openstack.cloud.endpoint:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
service: nova
|
||||||
|
endpoint_interface: internal
|
||||||
|
url: http://controller:9292
|
||||||
|
region: RegionOne
|
||||||
|
state: present
|
||||||
|
register: endpoint_again
|
||||||
|
|
||||||
|
- name: Ensure changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not endpoint_again.changed
|
||||||
|
|
||||||
|
- name: Update endpoint url
|
||||||
|
openstack.cloud.endpoint:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
service: nova
|
||||||
|
endpoint_interface: internal
|
||||||
|
url: http://controller:9393
|
||||||
|
region: RegionOne
|
||||||
|
state: present
|
||||||
|
register: endpoint_updated
|
||||||
|
|
||||||
|
- name: Ensure endpoint was updated
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- endpoint_updated.endpoint.url == "http://controller:9393"
|
||||||
|
|
||||||
|
- name: Delete endpoint
|
||||||
|
openstack.cloud.endpoint:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
service: nova
|
||||||
|
endpoint_interface: internal
|
||||||
|
url: http://controller:9393
|
||||||
|
region: RegionOne
|
||||||
|
state: absent
|
||||||
|
register: endpoint_deleted
|
||||||
|
|
||||||
|
- name: Ensure endpoint was deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- endpoint_deleted.changed
|
||||||
@@ -16,8 +16,9 @@
|
|||||||
- role: dns
|
- role: dns
|
||||||
tags: dns
|
tags: dns
|
||||||
when: sdk_version is version(0.28, '>=')
|
when: sdk_version is version(0.28, '>=')
|
||||||
- { role: host_aggregate, tags: host_aggregate }
|
- { role: endpoint, tags: endpoint }
|
||||||
- { role: floating_ip_info, tags: floating_ip_info }
|
- { role: floating_ip_info, tags: floating_ip_info }
|
||||||
|
- { role: host_aggregate, tags: host_aggregate }
|
||||||
- { role: identity_domain_info, tags: identity_domain_info }
|
- { role: identity_domain_info, tags: identity_domain_info }
|
||||||
- { role: identity_group_info, tags: identity_group_info }
|
- { role: identity_group_info, tags: identity_group_info }
|
||||||
- { role: identity_user, tags: identity_user }
|
- { role: identity_user, tags: identity_user }
|
||||||
|
|||||||
@@ -75,32 +75,40 @@ RETURN = '''
|
|||||||
endpoint:
|
endpoint:
|
||||||
description: Dictionary describing the endpoint.
|
description: Dictionary describing the endpoint.
|
||||||
returned: On success when I(state) is C(present)
|
returned: On success when I(state) is C(present)
|
||||||
type: complex
|
type: dict
|
||||||
contains:
|
contains:
|
||||||
id:
|
id:
|
||||||
description: Endpoint ID.
|
description: Endpoint ID.
|
||||||
type: str
|
type: str
|
||||||
sample: 3292f020780b4d5baf27ff7e1d224c44
|
sample: 3292f020780b4d5baf27ff7e1d224c44
|
||||||
region:
|
interface:
|
||||||
description: Region Name.
|
description: Endpoint Interface.
|
||||||
|
type: str
|
||||||
|
sample: public
|
||||||
|
is_enabled:
|
||||||
|
description: Service status.
|
||||||
|
type: bool
|
||||||
|
sample: True
|
||||||
|
links:
|
||||||
|
description: Links for the endpoint
|
||||||
|
type: str
|
||||||
|
sample: http://controller/identity/v3/endpoints/123
|
||||||
|
name:
|
||||||
|
description: Name of the endpoint
|
||||||
|
type: str
|
||||||
|
sample: cinder
|
||||||
|
region_id:
|
||||||
|
description: Region ID.
|
||||||
type: str
|
type: str
|
||||||
sample: RegionOne
|
sample: RegionOne
|
||||||
service_id:
|
service_id:
|
||||||
description: Service ID.
|
description: Service ID.
|
||||||
type: str
|
type: str
|
||||||
sample: b91f1318f735494a825a55388ee118f3
|
sample: b91f1318f735494a825a55388ee118f3
|
||||||
interface:
|
|
||||||
description: Endpoint Interface.
|
|
||||||
type: str
|
|
||||||
sample: public
|
|
||||||
url:
|
url:
|
||||||
description: Service URL.
|
description: Service URL.
|
||||||
type: str
|
type: str
|
||||||
sample: http://controller:9292
|
sample: http://controller:9292
|
||||||
enabled:
|
|
||||||
description: Service status.
|
|
||||||
type: bool
|
|
||||||
sample: True
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
@@ -121,7 +129,7 @@ class IdentityEndpointModule(OpenStackModule):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _needs_update(self, endpoint):
|
def _needs_update(self, endpoint):
|
||||||
if endpoint.enabled != self.params['enabled']:
|
if endpoint.is_enabled != self.params['enabled']:
|
||||||
return True
|
return True
|
||||||
if endpoint.url != self.params['url']:
|
if endpoint.url != self.params['url']:
|
||||||
return True
|
return True
|
||||||
@@ -147,51 +155,53 @@ class IdentityEndpointModule(OpenStackModule):
|
|||||||
enabled = self.params['enabled']
|
enabled = self.params['enabled']
|
||||||
state = self.params['state']
|
state = self.params['state']
|
||||||
|
|
||||||
service = self.conn.get_service(service_name_or_id)
|
service = self.conn.identity.find_service(service_name_or_id)
|
||||||
|
|
||||||
if service is None and state == 'absent':
|
if service is None and state == 'absent':
|
||||||
self.exit_json(changed=False)
|
self.exit_json(changed=False)
|
||||||
|
|
||||||
elif service is None and state == 'present':
|
if service is None and state == 'present':
|
||||||
self.fail_json(msg='Service %s does not exist' % service_name_or_id)
|
self.fail_json(msg='Service %s does not exist' % service_name_or_id)
|
||||||
|
|
||||||
filters = dict(service_id=service.id, interface=interface)
|
filters = dict(service_id=service.id, interface=interface)
|
||||||
if region is not None:
|
if region is not None:
|
||||||
filters['region'] = region
|
filters['region_id'] = region
|
||||||
endpoints = self.conn.search_endpoints(filters=filters)
|
endpoints = list(self.conn.identity.endpoints(**filters))
|
||||||
|
|
||||||
|
endpoint = None
|
||||||
if len(endpoints) > 1:
|
if len(endpoints) > 1:
|
||||||
self.fail_json(msg='Service %s, interface %s and region %s are '
|
self.fail_json(msg='Service %s, interface %s and region %s are '
|
||||||
'not unique' %
|
'not unique' %
|
||||||
(service_name_or_id, interface, region))
|
(service_name_or_id, interface, region))
|
||||||
elif len(endpoints) == 1:
|
elif len(endpoints) == 1:
|
||||||
endpoint = endpoints[0]
|
endpoint = endpoints[0]
|
||||||
else:
|
|
||||||
endpoint = None
|
|
||||||
|
|
||||||
if self.ansible.check_mode:
|
if self.ansible.check_mode:
|
||||||
self.exit_json(changed=self._system_state_change(endpoint))
|
self.exit_json(changed=self._system_state_change(endpoint))
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if endpoint is None:
|
if endpoint is None:
|
||||||
result = self.conn.create_endpoint(
|
args = {'url': url, 'interface': interface,
|
||||||
service_name_or_id=service, url=url, interface=interface,
|
'service_id': service.id, 'enabled': enabled,
|
||||||
region=region, enabled=enabled)
|
'region_id': region}
|
||||||
endpoint = result[0]
|
endpoint = self.conn.identity.create_endpoint(**args)
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
if self._needs_update(endpoint):
|
if self._needs_update(endpoint):
|
||||||
endpoint = self.conn.update_endpoint(
|
endpoint = self.conn.identity.update_endpoint(
|
||||||
endpoint.id, url=url, enabled=enabled)
|
endpoint.id, url=url, enabled=enabled)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
self.exit_json(changed=changed, endpoint=endpoint)
|
self.exit_json(changed=changed,
|
||||||
|
endpoint=endpoint.to_dict(computed=False))
|
||||||
|
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
if endpoint is None:
|
if endpoint is None:
|
||||||
changed = False
|
changed = False
|
||||||
else:
|
else:
|
||||||
self.conn.delete_endpoint(endpoint.id)
|
self.conn.identity.delete_endpoint(endpoint.id)
|
||||||
changed = True
|
changed = True
|
||||||
self.exit_json(changed=changed)
|
self.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user