
    VhR0                     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: subnet_pool
short_description: Create, update or delete a subnet pool from OpenStack
author: OpenStack Ansible SIG
description:
   - Create, update or delete a subnet pool from OpenStack.
options:
   address_scope:
     description:
        - ID or name of the address scope associated with this subnet pool.
     type: str
   default_prefix_length:
     description:
        - The prefix length to allocate when the cidr or prefixlen attributes
          are omitted when creating a subnet.
     type: int
   default_quota:
     description:
        - A per-project quota on the prefix space that can be allocated
          from the subnet pool for project subnets.
     type: int
   description:
     description: The subnet pool description.
     type: str
   extra_specs:
     description:
        - Dictionary with extra key/value pairs passed to the API.
     type: dict
   is_default:
     description:
        - Whether this subnet pool is the default.
     type: bool
   is_shared:
     description:
        - Whether this subnet pool is shared or not.
        - This attribute cannot be updated.
     type: bool
     aliases: ['shared']
   maximum_prefix_length:
     description:
        - The maximum prefix length that can be allocated from the subnet pool.
     type: int
   minimum_prefix_length:
     description:
        - The minimum prefix length that can be allocated from the subnet pool.
     type: int
   name:
     description:
        - Name to be give to the subnet pool.
        - This attribute cannot be updated.
     required: true
     type: str
   prefixes:
     description:
        - Subnet pool prefixes in CIDR notation.
     type: list
     elements: str
   project:
     description:
        - Name or ID of the project.
     type: str
   state:
     description:
        - Whether the subnet pool should be C(present) or C(absent).
     choices: ['present', 'absent']
     default: present
     type: str
extends_documentation_fragment:
- openstack.cloud.openstack
as  
- name: Create an subnet pool.
  openstack.cloud.subnet_pool:
    cloud: mycloud
    state: present
    name: my_subnet_pool
    prefixes:
        - 10.10.10.0/24

- name: Create a subnet pool for a given project.
  openstack.cloud.subnet_pool:
    cloud: mycloud
    state: present
    name: my_subnet_pool
    project: myproj
    prefixes:
        - 10.10.10.0/24

- name: Create a shared and default subnet pool in existing address scope
  openstack.cloud.subnet_pool:
    cloud: mycloud
    state: present
    name: my_subnet_pool
    address_scope: my_adress_scope
    is_default: True
    default_quota: 10
    maximum_prefix_length: 32
    minimum_prefix_length: 8
    default_prefix_length: 24
    is_shared: True
    prefixes:
        - 10.10.10.0/8

- name: Delete subnet poool.
  openstack.cloud.subnet_pool:
    cloud: mycloud
    state: absent
    name: my_subnet_pool
a  
subnet_pool:
    description: Dictionary describing the subnet pool.
    returned: On success when I(state) is C(present).
    type: dict
    contains:
        address_scope_id:
            description: The address scope ID.
            type: str
            sample: "861174b82b43463c9edc5202aadc60ef"
        created_at:
            description: Timestamp when the subnet pool was created.
            type: str
            sample: ""
        default_prefix_length:
            description: The length of the prefix to allocate when the cidr or
                         prefixlen attributes are omitted when creating a
                         subnet.
            type: int
            sample: 32
        default_quota:
            description: The per-project quota on the prefix space that can be
                         allocated from the subnet pool for project subnets.
            type: int
            sample: 22
        description:
            description: The subnet pool description.
            type: str
            sample: "My test subnet pool."
        id:
            description: Subnet Pool ID.
            type: str
            sample: "474acfe5-be34-494c-b339-50f06aa143e4"
        ip_version:
            description: The IP version of the subnet pool 4 or 6.
            type: int
            sample: 4
        is_default:
            description: Indicates whether this is the default subnet pool.
            type: bool
            sample: false
        is_shared:
            description: Indicates whether this subnet pool is shared across
                         all projects.
            type: bool
            sample: false
        maximum_prefix_length:
            description: The maximum prefix length that can be allocated from
                         the subnet pool.
            type: int
            sample: 22
        minimum_prefix_length:
            description: The minimum prefix length that can be allocated from
                         the subnet pool.
            type: int
            sample: 8
        name:
            description: Subnet Pool name.
            type: str
            sample: "my_subnet_pool"
        prefixes:
            description: A list of subnet prefixes that are assigned to the
                         subnet pool.
            type: list
            sample: ['10.10.20.0/24', '10.20.10.0/24']
        project_id:
            description: The ID of the project.
            type: str
            sample: "861174b82b43463c9edc5202aadc60ef"
        revision_number:
            description: Revision number of the subnet pool.
            type: int
            sample: 5
        tags:
            description:  A list of associated tags.
            returned: success
            type: list
        tenant_id:
            description: The ID of the project. Deprecated.
            type: str
            sample: "861174b82b43463c9edc5202aadc60ef"
        updated_at:
            description: Timestamp when the subnet pool was last updated.
            type: str
            sample:
    )OpenStackModulec                      e Zd Z e e        ed       ed       e        ed       ed       eddg       ed       ed       ed       ed	d
       e        edddg            Zd Zd Zd Zd Zd Z	d Z
y)SubnetPoolModuleint)typedictboolshared)r   aliasesT)requiredliststr)r   elementspresentabsent)defaultchoices)address_scopedefault_prefix_lengthdefault_quotadescriptionextra_specs
is_default	is_sharedmaximum_prefix_lengthminimum_prefix_lengthnameprefixesprojectstatec                    | j                   d   }| j                   d   }| j                  j                  j                  |      }| j                  j
                  r"| j                  | j                  ||             |dk(  r6|s4| j                         }| j                  d|j                  d             y |dk(  rT|rR| 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   )changedr   TF)computed)r"   subnet_poolr   )paramsconnnetworkfind_subnet_poolansible
check_mode	exit_json_will_change_createto_dict_build_update_updater	   _delete)selfr    r   r$   updates        o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/subnet_pool.pyrunzSubnetPoolModule.run   s8   G${{6"ii''88><<""NN4#4#4UK#HNIIk,,.KNN4'2':':E':'J  L iK''4F"ll;?NN4<'2':':E':'J  L h;LL%NN4N(h{NN5N) (3    c           	          i }t         fddD              }dD ]L  } j                  |   t         j                  |         t        |         k7  s; j                  |   ||<   N  j                  d   }|H j                  j                  j                  |d      }d   |j                  k7  r|j                  |d<    j                  d   }|H j                  j                  j                  |d      }d	   |j                  k7  r|j                  |d	<    j                  d
   }	|	rt        |j                               t        |	j                               z  }
|
r2t        dj                  dj                  t        |
                        |	j                         D ]  \  }}||   k7  s|||<    |r||d<   |S )Nc              3      K   | ]9  }j                   |   (j                   |   |   k7  r|j                   |   f ; y wNr%   ).0kr2   r$   s     r4   	<genexpr>z1SubnetPoolModule._build_update.<locals>.<genexpr>  sL      @ "[[^7"kk!nA> dkk!n- @s   ?A)r   r   r   r   r   r   )r   r   Fignore_missing
project_idr   address_scope_idr   $Duplicate key(s) in extra_specs: {0}, 
attributes)r   r%   setr&   identityfind_projectidr'   find_address_scopekeys
ValueErrorformatjoinr   items)r2   r$   r3   rD   r<   project_name_or_idr   address_scope_name_or_idr   r   duplicate_keysvs   ``          r4   r/   zSubnetPoolModule._build_update  s    @$=@ @
  	/A{{1~)t{{1~&#k!n*== $A
1	/
 "[[3)ii((556HEJ 6 LG<(GJJ6+2::
<(#';;#? #/ II--@@( A @M-.-2B2BB1>1A1A
-.kk-0 !23c+:J:J:L6MMN !G"(&43G)H"IK K#))+ &1A&$%JqM& #-F< r6   c           	          t         fddD              } j                  d   }|6 j                  j                  j	                  |d      }|j
                  |d<    j                  d   }|6 j                  j                  j                  |d      }|j
                  |d<    j                  d	   }|rst        |j                               t        |j                               z  }|r2t        d
j                  dj                  t        |                        t        |fi |}  j                  j                  j                  di |S )Nc              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr9   r:   )r;   r<   r2   s     r4   r=   z+SubnetPoolModule._create.<locals>.<genexpr>1  s6      5 Q3 $++a.) 5s   *-)	r   r   r   r   r   r   r   r   r   r   Fr>   r@   r   rA   r   rB   rC    )r   r%   r&   rF   rG   rH   r'   rI   rE   rJ   rK   rL   rM   r   create_subnet_pool)r2   kwargsrO   r   rP   r   r   rQ   s   `       r4   r-   zSubnetPoolModule._create0  sD    5 M5 5 "[[3)ii((556HEJ 6 LG#*::F< #';;#? #/ II--@@( A @M)6)9)9F%&kk-0 /#k6F6F6H2IIN !G"(&43G)H"IK K&0K0F3tyy  33=f==r6   c                 b    | j                   j                  j                  |j                         y r9   )r&   r'   delete_subnet_poolrH   )r2   r$   s     r4   r1   zSubnetPoolModule._deleteN  s    		,,[^^<r6   c                     |j                  d      }|r1 | j                  j                  j                  |j                  fi |}|S )NrD   )getr&   r'   update_subnet_poolrH   )r2   r$   r3   rD   s       r4   r0   zSubnetPoolModule._updateQ  sG    ZZ-
>$))++>>{~~ MAKMK r6   c                 f    |dk(  r|sy|dk(  r|rt        | j                  |            S |dk(  r|ryy)Nr   Tr   F)r	   r/   )r2   r    r$   s      r4   r,   zSubnetPoolModule._will_changeY  sA    IkiK**;788h; r6   N)__name__
__module____qualname__r   argument_specr5   r/   r-   r1   r0   r,   rU   r6   r4   r   r      s    f".&Ff%V$FXJ7".".4 6E29x.CDM *B+Z><=	r6   r   c                  &    t               }  |         y r9   )r   )modules    r4   mainrd   e  s    F
Hr6   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rd   r^   rU   r6   r4   <module>rj      sM   FP&PU
n _Q Qh
 zF r6   