use domain_id of the service once present
This commit is contained in:
		@ -39,6 +39,8 @@ EXAMPLES = '''
 | 
			
		||||
'''
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
from openstack import resource
 | 
			
		||||
from openstack.identity.v3 import service
 | 
			
		||||
from urllib.parse import urlparse
 | 
			
		||||
 | 
			
		||||
from ansible_collections.opentelekomcloud.backend.plugins.module_utils.otc import (
 | 
			
		||||
@ -64,6 +66,10 @@ def _is_ep_update_necessary(current, url, is_enabled=True):
 | 
			
		||||
    return False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Service(service.Service):
 | 
			
		||||
    domain_id = resource.Body('domain_id')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ServiceCatalogModule(OTCModule):
 | 
			
		||||
    argument_spec = dict(
 | 
			
		||||
        services=dict(type='dict', required=True),
 | 
			
		||||
@ -102,11 +108,16 @@ class ServiceCatalogModule(OTCModule):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def _delete_service(self, current):
 | 
			
		||||
        if not hasattr(current, "domain_id") or not current.domain_id:
 | 
			
		||||
            conn = self.conn
 | 
			
		||||
        else:
 | 
			
		||||
            conn = self.conn.connect_as(domain_id=current.domain_id)
 | 
			
		||||
 | 
			
		||||
        _url = self.sdk.utils.urljoin(
 | 
			
		||||
            self.identity_ext_base,
 | 
			
		||||
            'OS-CATALOG', 'services', current.id
 | 
			
		||||
        )
 | 
			
		||||
        self.conn.identity.delete(_url)
 | 
			
		||||
        conn.identity.delete(_url)
 | 
			
		||||
 | 
			
		||||
    def _update_endpoint(self, current, url, is_enabled=True):
 | 
			
		||||
        _url = self.sdk.utils.urljoin(
 | 
			
		||||
@ -153,7 +164,7 @@ class ServiceCatalogModule(OTCModule):
 | 
			
		||||
        self._connect('dummy')
 | 
			
		||||
        changed = False
 | 
			
		||||
 | 
			
		||||
        existing_services = list(self.conn.identity.services())
 | 
			
		||||
        existing_services = list(self.conn.identity._list(Service))
 | 
			
		||||
        existing_service_per_type = {k.type: k for k in existing_services}
 | 
			
		||||
        _used_services = set()
 | 
			
		||||
        _used_eps = set()
 | 
			
		||||
@ -295,7 +306,7 @@ class ServiceCatalogModule(OTCModule):
 | 
			
		||||
                        'operation': 'delete',
 | 
			
		||||
                        'id': existing_ep.id,
 | 
			
		||||
                        'current_url': existing_ep.url,
 | 
			
		||||
                        'current_enabled': existing_ep.is_enabled
 | 
			
		||||
                        'current_enabled': existing_ep.is_enabled,
 | 
			
		||||
                    })
 | 
			
		||||
 | 
			
		||||
            # Cleanup of unused or duplicated entries
 | 
			
		||||
@ -310,7 +321,8 @@ class ServiceCatalogModule(OTCModule):
 | 
			
		||||
                        'id': srv.id,
 | 
			
		||||
                        'current_name': srv.name,
 | 
			
		||||
                        'current_description': srv.description,
 | 
			
		||||
                        'current_enabled': srv.is_enabled
 | 
			
		||||
                        'current_enabled': srv.is_enabled,
 | 
			
		||||
                        'x_domain_id': srv.domain_id
 | 
			
		||||
                    })
 | 
			
		||||
 | 
			
		||||
        return (results, changed)
 | 
			
		||||
 | 
			
		||||
@ -10,3 +10,8 @@
 | 
			
		||||
    environment: "production"
 | 
			
		||||
    services: "{{ config.services }}"
 | 
			
		||||
  check_mode: true
 | 
			
		||||
  register: sc_actions
 | 
			
		||||
 | 
			
		||||
- name: Debug
 | 
			
		||||
  ansible.builtin.debug:
 | 
			
		||||
    msg: "{{ sc_actions.changes.services }}"
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user