
    VhU                     `    d dl mZmZmZ eZd dlmZ  edd      Z edd      Z	 G d d      Z
y	)
    )absolute_importdivisionprint_function)
namedtupleKVPairz	key valueItemzindex detailsc                       e Zd ZddZed        Zd ZddZddZddZ	ddZ
dd	Zdd
ZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZy)	MSOSchemaNc                    || _         || _        |rE|j                  |      \  | _        | _        | _        | j
                  j                  d      | _        n$|j                  |      \  | _        | _        | _        i | _        || _	        || _
        | j                  r| j                  | j                         n'| j                  r| j                  | j                         |r*| j                  r| j                  | j                  |       y y y )NdisplayName)msoschema_namequery_schema_by_ididpathschemagetquery_schemaschema_objectstemplate_idtemplate_nameset_template_from_idset_templateset_site)self
mso_moduler   r   	site_name	schema_idr   s          i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/mso/plugins/module_utils/schema.py__init__zMSOSchema.__init__   s    &.8.K.KI.V+DGTY#{{}=D.8.E.Ek.R+DGTY &*%%d&6&67d001++MM$,,i8 ,9    c                     d t        fdt        |       D        d      }| D cg c]$  }D ]  }|j                  |j                         & }}}||fS c c}}w )a  
        Get the first matched object from a list of mso object dictionaries.
        :param search_list: Objects to search through -> List.
        :param kv_list: Key/value pairs that should match in the object. -> List[KVPair(Str, Str)]
        :return: The index and details of the object. -> Item (Named Tuple)
                 Values of provided keys of all existing objects. -> List
        c                 ,    t        fd| D              S )Nc              3   n   K   | ],  }j                  |j                        |j                  k(   . y wN)r   keyvalue).0kvitems     r   	<genexpr>zCMSOSchema.get_object_from_list.<locals>.kv_match.<locals>.<genexpr>/   s'     C(BHH4Cs   25)all)kvsr*   s    `r   kv_matchz0MSOSchema.get_object_from_list.<locals>.kv_match.   s    CsCDDr!   c              3   P   K   | ]  \  }} |      st        ||        y wr%   )r   )r(   indexr*   kv_listr.   s      r   r+   z1MSOSchema.get_object_from_list.<locals>.<genexpr>1   s(     mKE4U]^egkUld5$'ms   &&N)next	enumerater   r&   )search_listr1   matchr*   r)   existingr.   s    `    @r   get_object_from_listzMSOSchema.get_object_from_list$   s`    	E m9[;Qmost1<OwODHHRVV$O$OOh Ps   )Ac                     |D ]W  }|| j                   j                         vs dj                  || j                        }| j                  j                  |       Y y)z
        Validate that attributes are set to a value that is not equal None.
        :param required_schema_objects: List of schema objects to verify. -> List
        :return: None
        zJRequired attribute '{0}' is not specified on schema instance with name {1}msgN)r   keysformatr   r   	fail_json)r   required_schema_objectsschema_objectr:   s       r   validate_schema_objects_presentz)MSOSchema.validate_schema_objects_present5   sd     5 	,MD$7$7$<$<$>>biijwy}  zJ  zJ  K""s"+	,r!   c                 Z   t        d|      g}| j                  | j                  j                  d      |      \  }}|s?|r=dj	                  |dj                  |            }| j                  j                  |       |j                  j                  d      | _	        || j                  d<   y)	a  
        Get template item that matches the name of a template.
        :param template_name: Name of the template to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template item. -> Item(Int, Dict) | None
        name	templatesz>Provided template '{0}' not matching existing template(s): {1}, r9   
templateIDtemplateN)r   r7   r   r   r<   joinr   r=   detailsr   r   )r   r   fail_moduler1   r5   r6   r:   s          r   r   zMSOSchema.set_template@   s     &-0133DKKOOK4PRYZxRYYZgimirirs{i|}CHH3' ==,,\:*/J'r!   c                 Z   t        d|      g}| j                  | j                  j                  d      |      \  }}|s?|r=dj	                  |dj                  |            }| j                  j                  |       |j                  j                  d      | _	        || j                  d<   y)	a  
        Get template item that matches the id of a template.
        :param template_id: ID of the template to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template item. -> Item(Int, Dict) | None
        rE   rC   zAProvided template ID '{0}' not matching existing template(s): {1}rD   r9   rB   rF   N)r   r7   r   r   r<   rG   r   r=   rH   r   r   )r   r   rI   r1   r5   r6   r:   s          r   r   zMSOSchema.set_template_from_idP   s     ,4533DKKOOK4PRYZxU\\]hjnjsjst|j}~CHH3'"]]..v6*/J'r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a  
        Get template VRF item that matches the name of a VRF.
        :param vrf: Name of the VRF to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template VRF item. -> Item(Int, Dict) | None
        rF   rB   vrfsz4Provided VRF '{0}' not matching existing VRF(s): {1}rD   r9   template_vrfN
r@   r   r7   r   rH   r   r<   rG   r   r=   )r   vrfrI   r1   r5   r6   r:   s          r   set_template_vrfzMSOSchema.set_template_vrf_        	,,j\:&#&'33D4G4G
4S4[4[4_4_`f4gipqxHOOPSUYU^U^_gUhiCHH3'.3N+r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a  
        Get template VRF RP item that matches the ip of a VRF RP.
        :param ip: IP of the RP to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template VRF RP item. -> Item(Int, Dict) | None
        rM   	ipAddress	rpConfigsz2Provided IP '{0}' not matching existing IP(s): {1}rD   r9   template_vrf_rpNrN   )r   iprI   r1   r5   r6   r:   s          r   set_template_vrf_rpzMSOSchema.set_template_vrf_rpn   s     	,,n-=>+r*+33D4G4G4W4_4_4c4cdo4pryzxFMMbRVR[R[\dRefCHH3'16-.r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a  
        Get template bridge domain item that matches the name of a bd.
        :param bd: Name of the bd to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template bd item. -> Item(Int, Dict) | None
        rF   rB   bdsz2Provided BD '{0}' not matching existing bd(s): {1}rD   r9   template_bdNrN   )r   bdrI   r1   r5   r6   r:   s          r   set_template_bdzMSOSchema.set_template_bd}   s     	,,j\:&"%&33D4G4G
4S4[4[4_4_`e4fhopxFMMbRVR[R[\dRefCHH3'-2M*r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y	)
aQ  
        Get template bridge domain dhcp relay policy item that matches the name of a bd.
        :param relay_policy_ref: Reference of the relay policy to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template bd relay policy item. -> Item(Int, Dict) | None
        rF   refrZ   
dhcpLabelszZProvided Relay Policy Reference '{0}' not matching existing relay policy reference(s): {1}rD   r9   template_bd_dhcp_relay_policyNrN   )r   relay_policy_refrI   r1   r5   r6   r:   s          r   !set_template_bd_dhcp_relay_policyz+MSOSchema.set_template_bd_dhcp_relay_policy   s     	,,j\:%!12333D4G4G4V4^4^4b4bco4pryzxnuu  wG  IM  IR  IR  S[  I\  ]CHH3'?D;<r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a   
        Get template application profile item that matches the name of an anp.
        :param anp: Name of the anp to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template anp item. -> Item(Int, Dict) | None
        rF   rB   anpsz4Provided ANP '{0}' not matching existing anp(s): {1}rD   r9   template_anpNrN   )r   anprI   r1   r5   r6   r:   s          r   set_template_anpzMSOSchema.set_template_anp   rQ   r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a  
        Get template endpoint group item that matches the name of an epg.
        :param epg: Name of the epg to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template epg item. -> Item(Int, Dict) | None
        re   rB   epgsz4Provided EPG '{0}' not matching existing epg(s): {1}rD   r9   template_anp_epgNrN   )r   epgrI   r1   r5   r6   r:   s          r   set_template_anp_epgzMSOSchema.set_template_anp_epg   s     	,,n-=>&#&'33D4G4G4W4_4_4c4cdj4kmtuxHOOPSUYU^U^_gUhiCHH3'27./r!   c                 p   | j                  dg       t        d|      t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s@|r>dj                  ||dj                  |            }| j                  j                  |       || j                  d<   y	)
a  
        Get template endpoint group contract item that matches the reference and type of an contract.
        :param contract_ref: Reference of the contract to match. -> Str
        :param relation_type: Relation_type of the contract to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template epg item. -> Item(Int, Dict) | None
        rj   contractRefrelationshipTypecontractRelationshipszXProvided Contract Reference '{0}' with type '{1}' not matching existing contacts(s): {2}rD   r9   template_anp_epg_contractNrN   )r   contract_refrelation_typerI   r1   r5   r6   r:   s           r   set_template_anp_epg_contractz'MSOSchema.set_template_anp_epg_contract   s     	,,.@-AB-6?QS`8ab33D4G4GHZ4[4c4c4g4gh  5A  CJ  KxlssmTYYx-@C HH3';@78r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	aN  
        Get template endpoint group item that matches the name of an EPG uSeg Attribute.
        :param useg_attr: Name of the EPG uSeg Attribute to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template EPG uSeg Attribute item. -> Item(Int, Dict) | None
        rj   rB   	uSegAttrszPProvided uSeg Attribute '{0}' does not match the existing uSeg Attribute(s): {1}rD   r9   template_anp_epg_useg_attributeNrN   r   	useg_attrrI   r1   r5   r6   r:   s          r   set_template_anp_epg_useg_attrz(MSOSchema.set_template_anp_epg_useg_attr   s     	,,.@-AB&),-33D4G4GHZ4[4c4c4g4ghs4tv}~xdkkluw{  xA  xA  BJ  xK  LCHH3'AF=>r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	aF  
        Get template endpoint group annotation that matches the key of an EPG annotation.
        :param useg_attr: Key of the EPG Annotation to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template EPG Annotation item. -> Item(Int, Dict) | None
        rj   tagKeytagAnnotationszLProvided Annotation Key '{0}' does not match the existing Annotation(s): {1}rD   r9   template_anp_epg_annotationNrN   )r   annotation_keyrI   r1   r5   r6   r:   s          r   set_template_anp_epg_annotationz)MSOSchema.set_template_anp_epg_annotation   s     	,,.@-AB(N3433D4G4GHZ4[4c4c4g4ghx4y  |C  Dx`gghvx|  yB  yB  CK  yL  MCHH3'=B9:r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a  
        Get template external epg item that matches the name of an anp.
        :param anp: Name of the anp to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Template anp item. -> Item(Int, Dict) | None
        rF   rB   externalEpgszFProvided External EPG '{0}' not matching existing external_epg(s): {1}rD   r9   template_external_epgNrN   )r   external_epgrI   r1   r5   r6   r:   s          r   set_template_external_epgz#MSOSchema.set_template_external_epg   s     	,,j\:&,/033D4G4G
4S4[4[4_4_`n4oqxyxZaabnptpypy  {C  qD  ECHH3'7<34r!   c           
         | j                   j                  d      s7dj                  | j                        }| j                  j                  |       t        d| j                  j                  |            t        d|      g}| j                  | j                   j                  d      |      \  }}|sF|rDdj                  ||dj                  |dd	d
               }| j                  j                  |       || j                  d<   y	)aK  
        Get site item that matches the name of a site.
        :param template_name: Name of the template to match. -> Str
        :param site_name: Name of the site to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site item. -> Item(Int, Dict) | None
        siteszdNo sites associated with schema '{0}'. Associate the site with the schema using (M) mso_schema_site.r9   siteIdtemplateNamezjProvided site '{0}' not associated with template '{1}'. Site is currently associated with template(s): {2}rD      N   site)r   r   r<   r   r   r=   r   lookup_siter7   rG   r   )r   r   r   rI   r:   r1   r5   r6   s           r   r   zMSOSchema.set_site   s     {{w'x  AE  AQ  AQ  RCHH3'(DHH$8$8$CDf^]jFkl33DKKOOG4LgVx~  F  F=$))HQTTN*CC HH3'&+F#r!   c           	         | j                  ddg       t        d| j                  j                  | j                  | j
                  d   j                  j                  d      |            g}| j                  | j
                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |	       || j
                  d
<   y)a  
        Get site bridge domain item that matches the name of a bd.
        :param bd_name: Name of the bd to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site bd item. -> Item(Int, Dict) | None
        rF   r   bdRefrB   )r   rF   r[   rY   z7Provided BD '{0}' not matching existing site bd(s): {1}rD   r9   site_bdN)r@   r   r   bd_refr   r   rH   r   r7   r<   rG   r=   )r   bd_namerI   r1   r5   r6   r:   s          r   set_site_bdzMSOSchema.set_site_bd  s     	,,j&-AB'488??TWWtObObcmOnOvOvOzOz  |B  PC  HO?  $P  Q  R33D4G4G4O4W4W4[4[\a4bdklxKRRSZ\`\e\efn\opCHH3').I&r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a  
        Get site bridge domain subnet item that matches the ip of a subnet.
        :param subnet: Subnet (ip) to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site bd subnet item. -> Item(Int, Dict) | None
        r   rV   subnetszBProvided subnet '{0}' not matching existing site bd subnet(s): {1}rD   r9   site_bd_subnetNrN   )r   subnetrI   r1   r5   r6   r:   s          r   set_site_bd_subnetzMSOSchema.set_site_bd_subnet  s     	,,i[9$'(33D4G4G	4R4Z4Z4^4^_h4ikrsxV]]^dfjfofopxfyzCHH3'05,-r!   c                    | j                  ddg       t        d| j                  d   j                  j	                  d            g}| j                  | j                  d   j                  j	                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y	)
a  
        Get site application profile item that matches the name of a anp.
        :param anp_name: Name of the anp to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site anp item. -> Item(Int, Dict) | None
        re   r   anpRefrd   z9Provided ANP '{0}' not matching existing site anp(s): {1}rD   r9   site_anpN
r@   r   r   rH   r   r7   r<   rG   r   r=   )r   anp_namerI   r1   r5   r6   r:   s          r   set_site_anpzMSOSchema.set_site_anp+  s     	,,nf-EF(D$7$7$G$O$O$S$ST\$]^_33D4G4G4O4W4W4[4[\b4celmxMTTU]_c_h_hiq_rsCHH3'*/J'r!   c                    | j                  ddg       t        d| j                  d   j                  j	                  d            g}| j                  | j                  d   j                  j	                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y	)
z
        Get site anp epg item that matches the epgs.
        :param epg: epg to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site anp epg item. -> Item(Int, Dict) | None
        r   rj   epgRefri   z=Provided EPG '{0}' not matching existing site anp epg(s): {1}rD   r9   site_anp_epgNr   )r   epg_namerI   r1   r5   r6   r:   s          r   set_site_anp_epgzMSOSchema.set_site_anp_epg:  s     	,,j:L-MN(D$7$78J$K$S$S$W$WX`$abc33D4G4G
4S4[4[4_4_`f4gipqxQXXYacgclclmucvwCHH3'.3N+r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	aF  
        Get site endpoint group item that matches the name of an EPG uSeg Attribute.
        :param useg_attr: Name of the EPG uSeg Attribute to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site EPG uSeg Attribute item. -> Item(Int, Dict) | None
        r   rB   rv   zZProvided Site uSeg Attribute '{0}' does not match the existing Site uSeg Attribute(s): {1}rD   r9   site_anp_epg_useg_attributeNrN   rx   s          r   set_site_anp_epg_useg_attrz$MSOSchema.set_site_anp_epg_useg_attrI  s     	,,n-=>&),-33D4G4G4W4_4_4c4cdo4pryzxnuuv  BF  BK  BK  LT  BU  VCHH3'=B9:r!   c           	         | j                  ddg       t        d| j                  j                  | j                  | j
                  d   j                  j                  d      |            g}| j                  | j
                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |	       || j
                  d
<   y)a%  
        Get site contract item that matches the name of a contract.
        :param contract_name: Name of the contract to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site contract item. -> Item(Int, Dict) | None
        rF   r   rn   rB   )r   rF   contract	contractszCProvided Contract '{0}' not matching existing site contract(s): {1}rD   r9   site_contractN)r@   r   r   rr   r   r   rH   r   r7   r<   rG   r=   )r   contract_namerI   r1   r5   r6   r:   s          r   set_site_contractzMSOSchema.set_site_contractX  s     	,,j&-ABtxx44twwQUQdQdeoQpQxQxQ|Q|  ~D  RE  P]4   ^

 33D4G4G4O4W4W4[4[\g4hjqrxW^^_lnrnwnw  yA  oB  CCHH3'/4O,r!   c           	         | j                  ddg       t        d| j                  j                  | j                  | j
                  d   j                  j                  d      |            g}| j
                  d   j                  j                  d      }| j                  ||      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |	       || j
                  d
<   y)a+  
        Get site item that matches the name of a service graph.
        :param service_graph: Name of the service graph to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site service graph item. -> Item(Int, Dict) | None
        rF   r   serviceGraphRefrB   )r   rF   service_graphserviceGraphszRProvided Site Service Graph '{0}' not matching existing site service graph(s): {1}rD   r9   site_service_graphN)r@   r   r   service_graph_refr   r   rH   r   r7   r<   rG   r=   )r   r   rI   r1   r5   r6   r:   s          r   set_site_service_graphz MSOSchema.set_site_service_graphk  s    	,,j&-AB !**TWWtGZGZ[eGfGnGnGrGrsyGz  K]*  ^
 "008@@DD_U334FPxfmm  oA  CG  CL  CL  MU  CV  WCHH3'4901r!   c                 X   | j                  dg       t        d|      g}| j                  | j                  d   j                  j                  d      |      \  }}|s?|r=dj                  |dj                  |            }| j                  j                  |       || j                  d<   y)	a/  
        Get site anp epg static port path item that matches the path of Static Port.
        :param path: Path of the Static Port to match. -> Str
        :param fail_module: When match is not found fail the ansible module. -> Bool
        :return: Site anp epg item. -> Item(Int, Dict) | None
        r   r   staticPortszNProvided Static Port Path '{0}' not matching existing static port path(s): {1}rD   r9   site_anp_epg_static_portNrN   )r   r   rI   r1   r5   r6   r:   s          r   set_site_anp_epg_static_portz&MSOSchema.set_site_anp_epg_static_port  s     	,,n-=>&$'(33D4G4G4W4_4_4c4cdq4rt{|xbiijnptpypy  {C  qD  ECHH3':?67r!   )NNNN)T)__name__
__module____qualname__r    staticmethodr7   r@   r   r   rP   rW   r\   rb   rg   rl   rt   rz   r   r   r   r   r   r   r   r   r   r   r    r!   r   r
   r
      s    9$   	,0 0473E48A$GC=,*/604C5&:.@r!   r
   N)
__future__r   r   r   type__metaclass__collectionsr   r   r   r
   r   r!   r   <module>r      s<    A @ "	Hk	*&/*~@ ~@r!   