
    Vh                         d dl mZmZmZ eZdZdZdZd dl	m
Z
mZ d dlmZ 	 d dlmZ d dlmZ d d	lmZ d
Zd Zd Zd Zd Zedk(  r e        yy# e$ r dZY #w xY w)    )absolute_importdivisionprint_functiona  
module: oci_vcn
short_description: Manage Virtual Cloud Networks(VCN) in OCI
description:
  - This module allows the user to create, delete and update virtual cloud networks(VCNs) in OCI. The complete Oracle Cloud
    Infrastructure Ansible Modules can be downloaded from U(https://github.com/oracle/oci-ansible-modules/releases).
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  cidr_block:
    description: The CIDR IP address block of the VCN. Required when creating a VCN with O(state=present).
    type: str
    required: false
  compartment_id:
    description: The OCID of the compartment to contain the VCN. Required when creating a VCN with O(state=present). This
      option is mutually exclusive with O(vcn_id).
    type: str
  display_name:
    description: A user-friendly name. Does not have to be unique, and it is changeable.
    type: str
    aliases: ['name']
  dns_label:
    description: A DNS label for the VCN, used in conjunction with the VNIC's hostname and subnet's DNS label to form a fully
      qualified domain name (FQDN) for each VNIC within this subnet (for example, V(bminstance-1.subnet123.vcn1.oraclevcn.com)).
      Not required to be unique, but it is a best practice to set unique DNS labels for VCNs in your tenancy. Must be an alphanumeric
      string that begins with a letter. The value cannot be changed.
    type: str
  state:
    description: Create or update a VCN with O(state=present). Use O(state=absent) to delete a VCN.
    type: str
    default: present
    choices: ['present', 'absent']
  vcn_id:
    description: The OCID of the VCN. Required when deleting a VCN with O(state=absent) or updating a VCN with O(state=present).
      This option is mutually exclusive with O(compartment_id).
    type: str
    aliases: ['id']
author: "Rohit Chaware (@rohitChaware)"
extends_documentation_fragment:
  - community.general.oracle
  - community.general.oracle_creatable_resource
  - community.general.oracle_wait_options
  - community.general.oracle_tags
  - community.general.attributes
a  
- name: Create a VCN
  community.general.oci_vcn:
    cidr_block: '10.0.0.0/16'
    compartment_id: 'ocid1.compartment.oc1..xxxxxEXAMPLExxxxx'
    display_name: my_vcn
    dns_label: ansiblevcn

- name: Updates the specified VCN's display name
  community.general.oci_vcn:
    vcn_id: ocid1.vcn.oc1.phx.xxxxxEXAMPLExxxxx
    display_name: ansible_vcn

- name: Delete the specified VCN
  community.general.oci_vcn:
    vcn_id: ocid1.vcn.oc1.phx.xxxxxEXAMPLExxxxx
    state: absent
a  
vcn:
  description: Information about the VCN.
  returned: On successful create and update operation
  type: dict
  sample:
    {
      "cidr_block": "10.0.0.0/16",
      "compartment_id\"": "ocid1.compartment.oc1..xxxxxEXAMPLExxxxx",
      "default_dhcp_options_id": "ocid1.dhcpoptions.oc1.phx.xxxxxEXAMPLExxxxx",
      "default_route_table_id": "ocid1.routetable.oc1.phx.xxxxxEXAMPLExxxxx",
      "default_security_list_id": "ocid1.securitylist.oc1.phx.xxxxxEXAMPLExxxxx",
      "display_name": "ansible_vcn",
      "dns_label": "ansiblevcn",
      "id": "ocid1.vcn.oc1.phx.xxxxxEXAMPLExxxxx",
      "lifecycle_state": "AVAILABLE",
      "time_created": "2017-11-13T20:22:40.626000+00:00",
      "vcn_domain_name": "ansiblevcn.oraclevcn.com"
    }
)AnsibleModulemissing_required_lib)	oci_utils)VirtualNetworkClient)CreateVcnDetails)UpdateVcnDetailsTFc           
          t        j                  d| | j                  d|j                  d   i| j                  d|j                  d   i|      }|S )Nvcnvcn_id)resource_typeclientget_fn
kwargs_get	delete_fnkwargs_deletemodule)r   delete_and_waitget_vcnparams
delete_vcnvirtual_network_clientr   results      m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/oci_vcn.pyr   r   q   sV    &&%%--fmmH56(33x!89F M    c                     t        j                  d| | j                  d|j                  d   i| j                  dgt
        di|t        t               j                  j                               	      }|S )Nr   r   update_vcn_details)	r   r   r   r   	update_fnprimitive_params_updatekwargs_non_primitive_updater   update_attributes)	r   check_and_update_resourcer   r   
update_vcnr   listattribute_mapkeysr   s      r   r&   r&   ~   sn    00%%--fmmH56(33!)
%57K$L/1??DDFG
F Mr   c           	         t               }|j                  j                         D ]+  }||j                  v st	        |||j                  |          - t        j                  d| j                  d|i| | j                  d|      }|S )Nr   create_vcn_detailsr   )r   	create_fnkwargs_creater   r   	get_paramr   )	r
   r(   r)   r   setattrr   create_and_wait
create_vcnr   )r   r   r+   	attributer   s        r   r1   r1      s    )+'55::< M	%&	6==3KLM &&(33+-?@%%--F Mr   c                     t        j                  dd      } | j                  t        t        dd      t        dd      t        dddg      t        dd      t        dddd	dg
      t        dddg                   t	        | dddgg      }t
        s|j                  t        d             t        j                  |t              }ddd}|j                  d   }|j                  d   }|d	k(  r"|t        ||      }ng|j                  d       nT|t        ||      }nEt        j                  dt        ||d|j                  d|j                  d   i|t!               |      } |j"                  di  y )NT)supports_createsupports_waitstrF)typerequiredname)r7   r8   aliasespresentabsent)r7   r8   defaultchoicesid)
cidr_blockcompartment_iddisplay_name	dns_labelstater   rA   r   )argument_specsupports_check_modemutually_exclusiveoci)msg)rB   rC   rD   z6Specify vcn_id with state as 'absent' to delete a VCN.r   )r   r   )r   r,   r-   list_fnkwargs_listr   modelexclude_attributes )r   get_taggable_arg_specupdatedictr   HAS_OCI_PY_SDK	fail_jsonr   create_service_clientr	   r   r   r&   check_and_create_resourcer1   	list_vcnsr
   	exit_json)module_argsr   r   rM   rD   r   r   s          r   mainrY      s   11DK 7UU;556(K6!!9-	 UUTFC	
  !!-x89F 1%89&<<$ +/TBMM'"E]]8$F 6?FL  
  6?F88#$.D$ /88-v}}=M/NO&(#5F Fvr   __main__N)
__future__r   r   r   r7   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r   Aansible_collections.community.general.plugins.module_utils.oracler   oci.core.virtual_network_clientr	   oci.core.modelsr
   r   rR   ImportErrorr   r&   r1   rY   __name__rN   r   r   <module>rf      s    A @/b&
* K WD00N

$?D zF i  Ns   A AA