
    Vh                     R    d Z dZdZddlmZ  G d de      Zd Zedk(  r e        y	y	)
a  
---
module: endpoint
short_description: Manage OpenStack Identity service endpoints
author: OpenStack Ansible SIG
description:
    - Create, update, or delete OpenStack Identity service endpoints. If a
      service with the same combination of I(service), I(interface) and
      I(region) exist, the I(url), I(enabled) and I(state) (C(present) or
      C(absent)) will be updated.
options:
   service:
     description:
        - Name or id of the service.
     required: true
     type: str
   endpoint_interface:
     description:
        - Interface of the service.
     choices: [admin, public, internal]
     required: true
     type: str
   url:
     description:
        - URL of the service.
     required: true
     type: str
   region:
     description:
        - ID of the region that the service belongs to.
          Note that I(region) is used for authentication.
     type: str
   enabled:
     description:
        - Is the service enabled.
     default: True
     type: bool
   state:
     description:
       - Should the resource be C(present) or C(absent).
     choices: [present, absent]
     default: present
     type: str
extends_documentation_fragment:
- openstack.cloud.openstack
a  
- name: Create a service for glance
  openstack.cloud.endpoint:
     cloud: mycloud
     service: glance
     endpoint_interface: public
     url: http://controller:9292
     region: RegionOne
     state: present

- name: Delete a service for nova
  openstack.cloud.endpoint:
     cloud: mycloud
     service: nova
     endpoint_interface: public
     region: RegionOne
     state: absent
aR  
endpoint:
    description: Dictionary describing the endpoint.
    returned: On success when I(state) is C(present)
    type: dict
    contains:
        id:
            description: Endpoint ID.
            type: str
            sample: 3292f020780b4d5baf27ff7e1d224c44
        interface:
            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
            sample: RegionOne
        service_id:
            description: Service ID.
            type: str
            sample: b91f1318f735494a825a55388ee118f3
        url:
            description: Service URL.
            type: str
            sample: http://controller:9292
    )OpenStackModulec                       e Zd Z e ed       edg d       ed       e        edd       edddg	      
      Z ed      Zd Zd Zd Zy)IdentityEndpointModuleT)required)adminpublicinternal)r   choicesbool)typedefaultpresentabsent)r   r
   )serviceendpoint_interfaceurlregionenabledstate)supports_check_modec                 x    |j                   | j                  d   k7  ry|j                  | j                  d   k7  ryy)Nr   Tr   F)
is_enabledparamsr   )selfendpoints     l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/endpoint.py_needs_updatez$IdentityEndpointModule._needs_update   s7    $++i"88<<4;;u--    c                 d    | j                   d   }|dk(  r|ry|dk(  r|y| j                  |      S y)Nr   r   Tr   F)r   r   )r   r   r   s      r   _system_state_changez+IdentityEndpointModule._system_state_change   sB    G$HI%%h//r   c           	         | j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                  j                  j                  |      }||dk(  r| j	                  d	       ||d
k(  r| j                  d|z         t        |j                  |      }|r||d<   t         | j                  j                  j                  di |      }	d }
t        |	      dkD  r| j                  d|d|d|d       nt        |	      dk(  r|	d   }
| j                  j                  r!| j	                  | j                  |
      	       d}|d
k(  r|
s;|||j                  ||d} | j                  j                  j                  di |}
d}nE| j                  |
      r4| j                  j                  j!                  |
j                  ||      }
d}| j	                  ||
j#                  d             n8|dk(  r3|
r1| j                  j                  j%                  |
j                         d}| j	                  |	       y )Nr   r   r   r   r   r   r   F)changedr   zService %s does not exist)msg)
service_id	interface	region_id   zService z, interface z and region z are not uniquer   )r   r%   r$   r   r&   T)r   r   )computed)r"   r    )r   connidentityfind_service	exit_json	fail_jsondictidlist	endpointslenansible
check_moder    create_endpointr   update_endpointto_dictdelete_endpoint)r   service_name_or_idr%   r   r&   r   r   r   filtersr2   r   r"   argss                r   runzIdentityEndpointModule.run   sI   ![[3KK 45	kk%  KK)	++i(G$))$$112DE?u0NN5N)?u	1NN:=OONP'**	B#,GK 5++55@@A	y>ANN.	9 FN G ^q  |H<<""NN4#<#<X#FNGI!*")**&!* >499--==EE##H-99--==KKS' > ;NN7$,$4$4e$4$D  F h8II..x{{;Gw'r   N)	__name__
__module____qualname__r/   argument_specmodule_kwargsr   r    r=   r)   r   r   r   r   t   sc    d#7VW$v&$/9x.CDM  M
;(r   r   c                  &    t               }  |         y )N)r   )modules    r   mainrE      s    #%F
Hr   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rE   r>   r)   r   r   <module>rK      sJ   -^&&
P _\(_ \(~
 zF r   