
    Vh#                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: restconf_config
author: Ganesh Nalawade (@ganeshrn)
short_description: Handles create, update, read and delete of configuration data on
  RESTCONF enabled devices.
description:
- RESTCONF is a standard mechanisms to allow web applications to configure and manage
  data. RESTCONF is a IETF standard and documented on RFC 8040.
- This module allows the user to configure data on RESTCONF enabled devices.
version_added: 1.0.0
options:
  path:
    description:
    - URI being used to execute API calls.
    required: true
    type: str
  content:
    description:
    - The configuration data in format as specififed in C(format) option. Required
      unless C(method) is I(delete).
    type: str
  method:
    description:
    - The RESTCONF method to manage the configuration change on device. The value
      I(post) is used to create a data resource or invoke an operation resource, I(put)
      is used to replace the target data resource, I(patch) is used to modify the
      target resource, and I(delete) is used to delete the target resource.
    required: false
    type: str
    default: post
    choices:
    - post
    - put
    - patch
    - delete
  format:
    description:
    - The format of the configuration provided as value of C(content). Accepted values
      are I(xml) and I(json) and the given configuration format should be supported
      by remote RESTCONF server.
    type: str
    default: json
    choices:
    - json
    - xml
notes:
- This module requires the RESTCONF system service be enabled on the remote device
  being managed.
- This module is supported with I(ansible_connection) value of I(ansible.netcommon.httpapi) and
  I(ansible_network_os) value of I(ansible.netcommon.restconf).
- This module is tested against Cisco IOSXE 16.12.02 version.
a  
- name: create l3vpn services
  ansible.netcommon.restconf_config:
    path: /config/ietf-l3vpn-svc:l3vpn-svc/vpn-services
    content: |
      {
        "vpn-service":[
                        {
                          "vpn-id": "red_vpn2",
                          "customer-name": "blue",
                          "vpn-service-topology": "ietf-l3vpn-svc:any-to-any"
                        },
                        {
                          "vpn-id": "blue_vpn1",
                          "customer-name": "red",
                          "vpn-service-topology": "ietf-l3vpn-svc:any-to-any"
                        }
                      ]
       }
a  
candidate:
  description: The configuration sent to the device.
  returned: When the method is not delete
  type: dict
  sample: |
        {
            "vpn-service": [
                {
                    "customer-name": "red",
                    "vpn-id": "blue_vpn1",
                    "vpn-service-topology": "ietf-l3vpn-svc:any-to-any"
                }
            ]
        }
running:
  description: The current running configuration on the device.
  returned: When the method is not delete
  type: dict
  sample: |
        {
            "vpn-service": [
                {
                  "vpn-id": "red_vpn2",
                  "customer-name": "blue",
                  "vpn-service-topology": "ietf-l3vpn-svc:any-to-any"
                },
                {
                  "vpn-id": "blue_vpn1",
                  "customer-name": "red",
                  "vpn-service-topology": "ietf-l3vpn-svc:any-to-any"
                }
            ]
        }

N)to_text)AnsibleModule)ConnectionError)string_types)	dict_diff)restconfc            	      \   t        t        d      t               t        g dd      t        ddgd            } d	dd
ggd	dd
ggd	dd
ggg}t        | |d      }|j                  d   }|j                  d
   }|j                  d	   }|j                  d   }t        |t              rt        j                  |      }t               }d|d}d}	|j                   }
	 t        j                  |||      }		 |dk(  r7|	r |
rt        j                  ||d       d|d<   nv|j!                  d|z         na|	rt#        |	|      }||d<   |	|d<   n|}|rD|j$                  r	|||	d|d<   |
r(t        j                  ||||j'                         |       d|d<    |j*                  di | y# t        $ rB}|j                  dk(  rd}	n&|j                  t        |      |j                         Y d}~d}~ww xY w# t        $ r0}|j                  t)        |      |j                         Y d}~d}~ww xY w) z entry point for module executionT)required)postputpatchdeleter   )choicesdefaultjsonxml)pathcontentmethodformatr   r   r   r   )argument_specrequired_ifsupports_check_moder   r   F)changedwarningsN)outputi  )msgcoder   DELETE)r   r   r   z3delete not executed as resource '%s' does not exist	candidaterunning)preparedbeforeafterdiff )dictr   params
isinstancer	   r   loadslist
check_moder   getr   r!   	fail_jsonr   edit_configappendr
   _diffupperstr	exit_json)r   r   moduler   r#   r   r   r   resultr$   commitexcr(   s                u/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/ansible/netcommon/plugins/modules/restconf_config.pymainr=      sA   4 >OVUOV<	M 
6I;'	59+&	7YK(K # F == Di(I]]8$F]]8$F)\*JJy)	vHH5FG"""F>,,vtF;#6X((d8L$(y! UX\ \] )4&/{#$+y! <<$("+!(&F6N ((! $%||~% %)y!
 FvW  >88s?GCHH=	>P  6SXCHH556s1   F$ 4BG2 $	G/-8G**G/2	H+;&H&&H+__main__)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils._textr   ansible.module_utils.basicr   ansible.module_utils.connectionr   ansible.module_utils.sixr	   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr
   Kansible_collections.ansible.netcommon.plugins.module_utils.network.restconfr   r=   __name__r)       r<   <module>rM      sc    A @ 3j*#
J  . 4 ; 1 aNb zF rL   