
    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: address_scope
short_description: Create or delete address scopes from OpenStack
author: OpenStack Ansible SIG
description:
   - Create or Delete address scopes from OpenStack.
options:
   state:
     description:
        - Indicate desired state of the resource
     choices: ['present', 'absent']
     default: present
     type: str
   name:
     description:
        - Name to be give to the address scope
        - This option cannot be updated.
     required: true
     type: str
   project:
     description:
        - Unique name or ID of the project.
        - This option cannot be updated.
     type: str
   ip_version:
     description:
        - The IP version of the subnet 4 or 6.
        - This option cannot be updated.
     default: '4'
     type: str
     choices: ['4', '6']
   is_shared:
     description:
        - Whether this address scope is shared or not.
     type: bool
     default: 'false'
     aliases: ['shared']
   extra_specs:
     description:
        - Dictionary with extra key/value pairs passed to the API
     default: {}
     type: dict
extends_documentation_fragment:
- openstack.cloud.openstack
a  
# Create an IPv4 address scope.
- openstack.cloud.address_scope:
    cloud: mycloud
    state: present
    name: my_adress_scope

# Create a shared IPv6 address scope for a given project.
- openstack.cloud.address_scope:
    cloud: mycloud
    state: present
    ip_version: 6
    name: ipv6_address_scope
    project: myproj

# Delete address scope.
- openstack.cloud.address_scope:
    cloud: mycloud
    state: absent
    name: my_adress_scope
a  
address_scope:
    description: Dictionary describing the address scope.
    returned: On success when I(state) is 'present'
    type: dict
    contains:
        id:
            description: Address Scope ID.
            type: str
            sample: "474acfe5-be34-494c-b339-50f06aa143e4"
        ip_version:
            description: The IP version of the subnet 4 or 6.
            type: str
            sample: "4"
        is_shared:
            description: Indicates whether this address scope is shared across
                         all tenants.
            type: bool
            sample: false
        name:
            description: Address Scope name.
            type: str
            sample: "my_address_scope"
        project_id:
            description: The project ID
            type: str
            sample: "474acfe5-be34-494c-b339-50f06aa143e4"
        tenant_id:
            description: The tenant ID.
            type: str
            sample: "861174b82b43463c9edc5202aadc60ef"
    )OpenStackModulec                       e Zd Z e edddg       ed       edddg	       ed
d
dg       e        ed e                   Zd Zd Zd Zy)AddressScopeModulepresentabsent)defaultchoicesT)requiredFboolshared)r   typealiases46dict)r   r   )statename	is_shared
ip_versionprojectextra_specsc                 0    |d   | j                   d   k7  ryy)z;Decide if the given address_scope needs an update.
        r   TF)params)selfaddress_scopes     q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/address_scope.py_needs_updatez AddressScopeModule._needs_updatez   s      %[)AA    c                 d    | j                   d   }|dk(  r|ry|dk(  r|sy| j                  |      S y)z+Check if the system state would be changed.r   r   Tr   F)r   r   )r   r   r   s      r   _system_state_changez'AddressScopeModule._system_state_change   s?    G$HI %%m44r   c                    | j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }|+| j                  j                  j                  |d      d	   }n$| j                  j                  j                         }| j                  j                  j                  ||
      }| j                  j                  r!| j                  | j                  |             |dk(  rd}	|st        ||||      }
t        |
j                               t        |j                               z  }|r#t        dj!                  t#        |                  t        |
fi |}
 | j                  j                  j$                  di |
}d}	n=| j'                  |      r,| j                  j                  j)                  |d	   |      }d}	| j                  |	|j+                  d             y |dk(  rP|s| j                  d       y | j                  j                  j-                  |d	          | j                  d       y y )Nr   r   r   r   r   r   F)ignore_missingid)
name_or_id
project_id)changedr   )r   r   r   r%   z#Duplicate key(s) {0} in extra_specsT)r   )computed)r&   r   r    )r   connidentityfind_projectsessionget_project_idnetworkfind_address_scopeansible
check_mode	exit_jsonr    r   setkeys
ValueErrorformatlistcreate_address_scoper   update_address_scopeto_dictdelete_address_scope)r   r   r   r   r   project_name_or_idr   r%   r   r&   kwargsdup_argss               r   runzAddressScopeModule.run   sE   G${{6"KK,	[[.
![[3kk-0)++88"5 9 ::>@J **99;J		))<<
 = 4<<""NN11-@   IG )')	+
 v{{}-K4D4D4F0GG$%J&,fT(^&<> >f44:DII%%::DVD ##M2 $		 1 1 F F!$'9 !G !>NN7)6)>)>)>)N  P h u-		!!66}T7JKt, r   N)__name__
__module____qualname__r   argument_specr   r    r?   r(   r   r   r   r   p   s_    9x.CD4 u6H:Fc3Z8fdf5M	5-r   r   c                  &    t               }  |         y )N)r   )modules    r   mainrF      s    !F
Hr   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rF   r@   r(   r   r   <module>rL      sJ   -^,
B _Q- Q-h
 zF r   