
    Vh4                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
Z
d d
lmZ d dlmZmZ d dlmZ d dlmZ d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zedk(  r e        y	y	)    )absolute_importdivisionprint_functionz1.1preview	community)metadata_versionstatussupported_byaL  
---
module: ndo_template
short_description: Manage Templates on Cisco Nexus Dashboard Orchestrator (NDO).
description:
- Manage Templates on Cisco Nexus Dashboard Orchestrator (NDO).
- This module is only supported on ND v3.1 (NDO v4.3) and later.
author:
- Akini Ross (@akinross)
options:
  template:
    description:
    - The name of the template.
    type: str
    aliases: [ name ]
  template_id:
    description:
    - The id of the template.
    - This parameter is required when the O(template) needs to be updated.
    type: str
    aliases: [ id ]
  template_type:
    description:
    - The type of the template.
    type: str
    aliases: [ type ]
    choices:
      - tenant
      - l3out
      - fabric_policy
      - fabric_resource
      - monitoring_tenant
      - monitoring_access
      - service_device
  tenant:
    description:
    - The name of the tenant attached to the template.
    - Required when O(type=tenant), O(type=l3out), 0(type=monitoring_tenant) or 0(type=service_device).
    type: str
  sites:
    description:
    - The list of sites attached to the template.
    - Required when O(type=l3out), O(type=monitoring_tenant) or O(type=monitoring_access).
    - Set to an empty list O(sites=[]) to remove all sites attached from the template.
    - Set to null O(sites=null) or do not provide O(sites) to avoid making changes to sites attached to the template.
    aliases: [ site ]
    type: list
    elements: dict
    suboptions:
      name:
        description:
        - The name of the site attached to the template.
        type: str
  state:
    description:
    - Use C(absent) for removing.
    - Use C(query) for listing an object or multiple objects.
    - Use C(present) for creating or updating.
    type: str
    choices: [ absent, query, present ]
    default: query
extends_documentation_fragment: cisco.mso.modules
a  
- name: Create a new tenant policy template
  cisco.mso.ndo_template:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    template: ansible_tenant_policy
    template_type: tenant
    tenant: ansible_test_tenant
    sites:
      - name: ansible_test_site
    state: present

- name: Create a new l3out policy template
  cisco.mso.ndo_template:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    template: ansible_l3out_policy_template
    template_type: l3out
    tenant: ansible_test_tenant
    sites:
      - name: ansible_test_site
    state: present

- name: Query a tenant policy template
  cisco.mso.ndo_template:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    template: ansible_tenant_policy
    template_type: tenant
    state: query
  register: query_new_tenant_policy_template

- name: Query all tenant policy templates
  cisco.mso.ndo_template:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    template_type: tenant
    state: query
  register: query_all

- name: Query all templates
  cisco.mso.ndo_template:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    state: query
  register: query_all

- name: Delete a tenant policy template
  cisco.mso.ndo_template:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    template: ansible_tenant_policy
    template_type: tenant
    state: absent

N)AnsibleModule)	MSOModulemso_argument_spec)MSOTemplate)TEMPLATE_TYPESc                     t               } | j                  t        ddg      t        ddg      t        ddgt        t                    t        d      t        dd	d
gt        t        d                  t        ddg d             t        | dddddggddddggg      }t        |      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  |j                  j                  d            }|j                  j                  d      rH|j                  j                  dg       D cg c]"  }|j                  |j                  d            $ c}ng }|j                  j                  d      }	t        ||||      }
t        j                  |
j                        x|_        |_        |	dk(  r|r-t        |   d   s!|j#                  dj%                  |             |s-t        |   d   r!|j#                  dj%                  |             |s0t        |   d   dk(  r!|j#                  d j%                  |             t'        |      dkD  r0t        |   d   dk(  r!|j#                  d!j%                  |             |
j                  r|
j                  j                  d"      t        |   d   k7  r|j#                  d#       t        |   d   r8t)        |
j                  ||t        |   d$k7  rd%nd      r|j#                  d&       t        |   d   dk(  r-t)        |
j                  ||d'   d(      r|j#                  d)       g }|
j                  j                  d*      |k7  r,|j+                  t        d+d,|-             ||
j                  d*<   t        |   d   dkD  r=|j                  j                  d      "t-        |t        |   d.   |
j                  |       |j/                  |
j                         |j0                  s|r|j3                  |
j4                  d/|0       nd*|d"t        |   d   t        |   d.   i i}|dk(  rt7        ||||       nw|d1k(  rt9        ||||d'          n`|d2k(  rt;        |||       nM|d3k(  rt=        |||       n:|d4k(  rt?        ||||       n&|d5k(  rtA        |||       n|d6k(  rtC        ||||       |j0                  s2|j3                  |
jD                  d7|0      }|j                  d8      |d8<   |j/                  |       |jF                  |_        nA|	dk(  r<|j                   r)|j0                  s|j3                  |
j4                  d9:       i |_        |jI                          y c c}w );Nstrname)typealiasesidr   )r   r   choices)r   listdictsite)r   )r   elementsr   optionsquery)absentr   present)r   defaultr   )templatetemplate_idtemplate_typetenantsitesstateTr&   r   r!   r#   r   )argument_specsupports_check_moderequired_ifr"   r$   r%   z2Tenant cannot be attached to template of type {0}.)msgz1Tenant must be provided for template of type {0}.site_amount   z/Site must be provided for template of type {0}.z6Only one site can be attached to template of type {0}.templateTypez Template type cannot be changed.monitoring_accestenantIdzTenant cannot be changed.r   siteIdzSite cannot be changed.displayNamereplacez/displayNameoppathvaluetemplate_type_containerPATCH)methoddatal3outfabric_policyfabric_resourcemonitoring_tenantmonitoring_accessservice_devicePOST
templateIdDELETE)r9   )%r   updater   r   r   r   r   paramsgetlookup_tenantlookup_siter   copydeepcopyr!   existingprevious	fail_jsonformatlenchangedappendappend_site_config_to_opssanitize
check_moderequesttemplate_pathset_tenant_template_payloadset_l3out_template_payload"set_fabric_policy_template_payload$set_fabric_resource_template_payload&set_monitoring_tenant_template_payload%set_monitoring_acces_template_payload#set_service_device_template_payloadtemplates_pathproposed	exit_json)r'   modulemsor!   r"   r#   	tenant_idr   site_idsr&   mso_templateopspayloadresponses                 j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/mso/plugins/modules/ndo_template.pymainrj      se   %'M56(3edV4xnAUV&4UY_dUeKfgw8VW   # h_ =>i*o!>?
F F
C}}  ,H--##M2KMM%%o6M!!&--"3"3H"=>Iagananararsza{fmm>O>OPWY[>\]d 01]  BDHMMg&EsM8[IL"&--0E0E"FFCL3<	^M:8DMMRYYZghMi^M:8DMMQXXYfgMhN=9-HAMMMOVVWdeMfx=1!>}!MQR!RMMV]]^klMm  $$((8N=<YZi<jj"DEm,X67%%}i~^kOl  qC  PC  IQ< "=>m,];q@W\MbMbdqs{|}s~  AI  FJ";<C$$((78C

49>RS7?%%m4 m,];a?FMMDUDUV]D^Dj)#~m/LMf/giui~i~  AI  JLL../$$L66wSQ
 x} =o N}-.GH"G (+G]IxX')*7M9hWXkZ/127M8T"334WmXV"556wyZbc"555g}hW"223G]IW_`$$;;|'B'B6X_;`(0\(B%LL!||	(	<< 1 1KK228KDMMOo ^s   ''V>c                     | t         |   d      j                  dd|ii       | t         |   d      j                  d|D cg c]  }d|i c}i       y c c}w Nr7   r!   r/   r%   r0   r   rD   rg   r#   rc   rd   site_ids        ri   rW   rW   
  }    N=)*CDELLj[egpZqMrsN=)*CDELLg  |D  XEpwYacjXk  XE  NF  G  XE    A
c                     | t         |   d      j                  d|i       | t         |   d      j                  d|i       y )Nr7   r/   r0   rm   )rg   r#   rc   ro   s       ri   rX   rX     sJ    N=)*CDELLjZcMdeN=)*CDELLhX_M`a    c                 n    | t         |   d      j                  d|D cg c]  }d|i c}i       y c c}w Nr7   r%   r0   rm   rg   r#   rd   ro   s       ri   rY   rY     S    N=)*CDELLg  |D  XEpwYacjXk  XE  NF  G  XE   2
c                 n    | t         |   d      j                  d|D cg c]  }d|i c}i       y c c}w ru   rm   rv   s       ri   rZ   rZ     rw   rx   c                     | t         |   d      j                  dd|di       | t         |   d      j                  d|D cg c]  }d|i c}i       y c c}w )Nr7   r!   r$   )mtTyper$   r%   r0   rm   rn   s        ri   r[   r[     s    N=)*CDELLjem  zC  [D  NE  FN=)*CDELLg  |D  XEpwYacjXk  XE  NF  G  XEs   A
c                     | t         |   d      j                  dddii       | t         |   d      j                  d|D cg c]  }d|i c}i       y c c}w )Nr7   r!   r{   accessr%   r0   rm   rv   s       ri   r\   r\   !  s}    N=)*CDELLj[cemZnMopN=)*CDELLg  |D  XEpwYacjXk  XE  NF  G  XErq   c                     | t         |   d      j                  dd|ii       | t         |   d      j                  d|D cg c]  }d|i c}i       y c c}w rl   rm   rn   s        ri   r]   r]   &  rp   rq   c                     t         |   d   r@| j                  t         |   d   i       j                  di       j                  |      }||k7  S | j                  t         |   d   i       j                  |      }||k7  S )Ntemplate_containerr7   r!   )r   rF   )configr#   r6   keyconfig_values        ri   rP   rP   +  s    m$%9:zz."?@Y"Z\^_ccdnprswwx{| 5   zz."?@Y"Z\^_ccdgh5  rs   c           
         |j                  |i       }|j                  dg       D cg c]  }|j                  d       }}t        |      D cg c]  \  }}||vs| }	}}|	rY|	j                  d       |	D ]B  }| j                  t	        ddj                  ||                   |d   j                  |       D |D cg c]	  }||vs| c}D ]\  }d|i}
| j                  t	        dd	j                  |      |

             |j                  d      g |d<   |d   j                  |
       ^ y c c}w c c}}w c c}w )Nr%   r0   T)reverseremovez/{0}/sites/{1})r4   r5   addz/{0}/sites/-r3   )rF   	enumeratesortrQ   r   rN   pop)rf   r7   r   rd   r   r   existing_site_idsindexro   
index_listrg   s              ri   rR   rR   3  sH   $;R@8J8N8NwXZ8[\(+\\.78I.JfNE7g]eNe%fJf% 	3EJJtx.>.E.EF]_d.efgw'++E2	3
 ,4XwFW7WGX 4W%

45~'<'<=T'U]def!!'*2*,w'7#**734 ]f Ys   D3D8D8	D>D>__main__)
__future__r   r   r   r   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNrI   ansible.module_utils.basicr   6ansible_collections.cisco.mso.plugins.module_utils.msor   r   ;ansible_collections.cisco.mso.plugins.module_utils.templater   <ansible_collections.cisco.mso.plugins.module_utils.constantsr   rj   rW   rX   rY   rZ   r[   r\   r]   rP   rR   __name__ rs   ri   <module>r      s    A @(-)Vab >@<|
  4 _ S WqhG
b
GGG
G
G
!42 zF rs   