
    Vhy#                     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: trunk
short_description: Add or delete trunks from an OpenStack cloud.
author: OpenStack Ansible SIG
description:
   - Add or delete trunk from an OpenStack cloud.
options:
    state:
        description:
          - Should the resource be present or absent.
        choices: [present, absent]
        default: present
        type: str
    name:
        description:
          - Name that has to be given to the trunk.
          - This port attribute cannot be updated.
        type: str
        required: true
    port:
        description:
          - The name or ID of the port for the trunk.
        type: str
        required: false
    sub_ports:
        description:
          - The sub ports on the trunk.
        type: list
        required: false
        elements: dict
        suboptions:
            port:
                description: The ID or name of the port.
                type: str
            segmentation_type:
                description: The segmentation type to use.
                type: str
            segmentation_id:
                description: The segmentation ID to use.
                type: int
extends_documentation_fragment:
- openstack.cloud.openstack
a  
# Create a trunk
- openstack.cloud.trunk:
    state: present
    auth:
      auth_url: https://identity.example.com
      username: admin
      password: admin
      project_name: admin
    name: trunk1
    port: port1

# Create a trunk with a subport
- openstack.cloud.trunk:
    state: present
    cloud: my-cloud
    name: trunk1
    port: port1
    sub_ports:
      - name: subport1
        segmentation_type: vlan
        segmentation_id: 123

# Remove a trunk
- openstack.cloud.trunk:
    state: absent
    auth:
      auth_url: https://identity.example.com
      username: admin
      password: admin
      project_name: admin
    name: trunk1
aA	  
trunk:
    description: Dictionary describing the trunk.
    type: dict
    returned: On success when I(state) is C(present).
    contains:
        created_at:
            description: Timestamp when the trunk was created.
            returned: success
            type: str
            sample: "2022-02-03T13:28:25Z"
        description:
            description: The trunk description.
            returned: success
            type: str
        id:
            description: The trunk ID.
            returned: success
            type: str
            sample: "3ec25c97-7052-4ab8-a8ba-92faf84148de"
        is_admin_state_up:
            description: |
                The administrative state of the trunk, which is up C(True) or
                down C(False).
            returned: success
            type: bool
            sample: true
        name:
            description: The trunk name.
            returned: success
            type: str
            sample: "trunk_name"
        port_id:
            description: The ID of the port for the trunk
            returned: success
            type: str
            sample: "5ec25c97-7052-4ab8-a8ba-92faf84148df"
        project_id:
            description: The ID of the project who owns the trunk.
            returned: success
            type: str
            sample: "aa1ede4f-3952-4131-aab6-3b8902268c7d"
        revision_number:
            description: The revision number of the resource.
            returned: success
            type: int
            sample: 0
        status:
            description: The trunk status. Value is C(ACTIVE) or C(DOWN).
            returned: success
            type: str
            sample: "ACTIVE"
        sub_ports:
            description: List of sub ports on the trunk.
            returned: success
            type: list
            sample: []
        tags:
            description: The list of tags on the resource.
            returned: success
            type: list
            sample: []
        tenant_id:
            description: Same as I(project_id). Deprecated.
            returned: success
            type: str
            sample: "51fce036d7984ba6af4f6c849f65ef00"
        updated_at:
            description: Timestamp when the trunk was last updated.
            returned: success
            type: str
            sample: "2022-02-03T13:28:25Z"
    )OpenStackModulec            	           e Zd Z e edddg       ed       e        edd      	      Z ed
gd      Zd Zd Zd Zd Z	d Z
d Zy)TrunkModulepresentabsent)defaultchoicesT)requiredlistdict)typeelements)statenameport	sub_ports)r   r   )r   )required_ifsupports_check_modec                    | j                   d   }| j                   d   }| j                   d   }d }|r'| j                  j                  j                  |d      }| j                  j                  j	                  |      }g }| j                   d   xs g }|D ]=  }| j                  j                  j                  |d   d      }	|j                  |	       ? | j                  j                  r#| j                  | j                  |||             |dk(  r8|s6| j                  ||      }| j                  d	|j                  d
             y |dk(  rU|rS| j                  ||      }
|
r| j                  ||
      }| j                  t        |
      |j                  d
             y |dk(  r&|r$| j                  |       | j                  d	       y |dk(  r|s| j                  d       y y y )Nr   r   r   F)ignore_missingr   )changedr   T)computed)r   trunkr   )paramsconnnetwork	find_port
find_trunkappendansible
check_mode	exit_json_will_change_createto_dict_build_update_updatebool_delete)selfport_name_or_id
name_or_idr   r   r   r   pspspsubportupdates              i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/trunk.pyrunzTrunkModule.run   s   ++f-[[(
G$99$$.. / 7D 		!!,,Z8	kk+&," 	&Bii''116
5 2 2GW%	&
 <<""NN4#4#4UE9#MNNIeLLT2ENN4!&!>  @iE''y9FUF3NN4<!&!>  @h5LLNN4N(huNN5N) (-    c                    g }g }|D ]i  }d}|d   D ]  }|d   |d   k(  sd} n |du s#| j                   d   xs g }|D ]/  }	|d   |	d   k(  s|d   |	d   |	d	   d
}
|j                  |
        i k |d   D ]5  }d}|D ]  }|d   |d   k(  sd} n |du s |j                  d|d   i       7 i }t        |      dkD  r||d<   t        |      dkD  r||d<   |S )NFr   port_ididTr   r   segmentation_typesegmentation_id)r5   r7   r8   r   add_sub_portsdel_sub_ports)r   r   len)r*   r   r   r9   r:   r.   foundtspr-   kspobjr0   s               r1   r&   zTrunkModule._build_update   sX    	BE[) y>RX- E ~kk+.4" A&zQvY.')$x123F1G/01B/C!
 &,,U3	$ % 	BCE d8s9~- E ~$$iY%@A	B }!&3F?#}!&3F?#r3   c                 z    i }||d<   |j                   |d<    | j                  j                  j                  di |S )Nr   r5    )r6   r   r   create_trunk)r*   r   r   argss       r1   r$   zTrunkModule._create  s=    V''Y-tyy  --555r3   c                    g }|d   D ]  }|j                  d|d   i        | j                  j                  j                  |j                  |       | j                  j                  j                  |j                         y )Nr   r5   )r   r   r   delete_trunk_subportsr6   delete_trunk)r*   r   r   r.   s       r1   r)   zTrunkModule._delete  sn    	$ 	9BiI78	9 			//)D		&&uxx0r3   c                 L   |j                  dd       r)| j                  j                  j                  ||d          |j                  dd       r)| j                  j                  j	                  ||d          | j                  j                  j                  |j                        S )Nr9   r:   )getr   r   add_trunk_subportsrE   r   r6   )r*   r   r0   s      r1   r'   zTrunkModule._update  s    ::ot,II00vo.0 ::ot,II33vo.0 yy  ++EHH55r3   c                 h    |dk(  r|sy|dk(  r|rt        | j                  ||            S |dk(  r|ryy)Nr   Tr   F)r(   r&   )r*   r   r   r   s       r1   r#   zTrunkModule._will_change!  sA    IeiE**5)<==h5r3   N)__name__
__module____qualname__r   argument_specmodule_kwargsr2   r&   r$   r)   r'   r#   rA   r3   r1   r   r      sk    9x.CD4 VFV4	M +
 !	M)*V'R61	6r3   r   c                  &    t               }  |         y )N)r   )modules    r1   mainrR   ,  s    ]F
Hr3   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rR   rK   rA   r3   r1   <module>rX      sL   +Z DH
T _E/ EP
 zF r3   