
    Vh4                        d dl mZmZmZ eZd dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZ 	 d dlmZmZmZ d	Z	 d dlmZmZ d dlmZ d dlm Z  d	Z!	 d dl"Z#d	Z$	 d dl%m&Z& d	Z'	 d dl(m)Z) d	Z*d Z,d Z-d Z.d Z/d Z0d Z1d Z2d&dZ3d Z4d Z5d Z6d Z7d Z8d Z9d Z:d Z;d  Z<d! Z=d" Z>d# Z? G d$ d%e@      ZAy# e$ r d
ZY w xY w# e$ r d
Z!Y xw xY w# e$ r d
Z$Y ~w xY w# e$ r d
Z'Y w xY w# e+$ r d
Z*Y w xY w)'    )absolute_importdivisionprint_functionN)deepcopy)	fetch_url)to_bytes	to_native)env_fallback)
Connection)FILETYPE_PEMload_privatekeysignTF)serializationhashes)padding)default_backend)cobra)urlparsec                  \   t        t        ddgt        dgf      t        ddt        dgf      t        dd	gt        d
dgf      t        ddt        ddgf      t        ddgdt        ddgf      t        ddgt        dgf      t        ddg dt        dgf      t        dt        dgf      t        dt        dgf      t        dt        dgf      t        dt        dgf      t        dt        d gf      t        dg d!t        d"gf      t        dd#d$gt        d%gf      &      S )'NstrhostnameACI_HOST)typealiasesfallbackintFACI_PORT)r   requiredr   userACI_USERNAMEANSIBLE_NET_USERNAMETACI_PASSWORDANSIBLE_NET_PASSWORDr   no_logr   cert_keyACI_PRIVATE_KEYANSIBLE_NET_SSH_KEYFILE)r   r   r%   r   	cert_nameACI_CERTIFICATE_NAMEnormal)debuginfor+   ACI_OUTPUT_LEVEL)r   defaultchoicesr   ACI_TIMEOUTr   r   boolACI_USE_PROXYACI_USE_SSLACI_VALIDATE_CERTSACI_OUTPUT_PATH)no_verification	no_verifysuppress_verifyignore_verifyignore_verificationACI_SUPPRESS_VERIFICATIONno_previousignore_previousACI_SUPPRESS_PREVIOUS)hostportusernamepasswordprivate_keycertificate_nameoutput_leveltimeout	use_proxyuse_sslvalidate_certsoutput_pathsuppress_verificationsuppress_previousdictr
        f/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/aci/plugins/module_utils/aci.pyaci_argument_specrT   a   s   L"ZL1

 uuzl7STH"^5K$LM

 "^5K$LM
 L"%68Q$RS	
  M"%;$<=

 /"%7$89	
 %<-*IJFl_<M-NO&L=/+JK<BVAW2XYe|>O=P.QR"o"%@$AB

 F]DU4Vbn  rI  qJ  bK  L]/ /rR   c                  @    t        t        ddt        dgf            S )Nr   zorchestrator:ansibleACI_ANNOTATION)r   r/   r   )
annotationrO   rQ   rR   rS   aci_annotation_specrX      s)    *"%5$67
 rR   c                  f    t        t        ddt        dgf      t        dt        dgf            S )Nr   FACI_OWNER_KEYr$   ACI_OWNER_TAGr2   )	owner_key	owner_tagrO   rQ   rR   rS   aci_owner_specr^      s5    E%</IZ:[\E\O;L,MN rR   c            	      ~    t        t        dd      t        dddg      t        dg d      t        d	      
      S )Nr   Tr   r   activepassiver   r0   )zdst-ipzdst-ip-l4portzdst-ip-vlanzdst-ip-l4port-vlanzdst-macz
dst-l4portzsrc-ipzsrc-ip-l4portzsrc-ip-vlanzsrc-ip-l4port-vlanzsrc-macz
src-l4portz
src-dst-ipzsrc-dst-ip-l4portzsrc-dst-ip-vlanzsrc-dst-ip-l4port-vlanzsrc-dst-maczsrc-dst-l4portzsrc-port-idvlanr   r   )name	lacp_modeload_balancing_modenumber_uplinksrP   rQ   rR   rS   enhanced_lag_specrk      sB    ut,EHi+@A 
2 '9 rR   c                  r    t        t        dd      t        d      t        d      t        d            S )Nr   Tr`   r   re   )rf   active_flow_timeoutidle_flow_timeoutsampling_raterj   rQ   rR   rS   netflow_specrp      s1    ut, e,E*&	 rR   c                  f    t        t        ddd      t        dg dd      t        d            S )	Nr   TF)r   r   r%   )not_ininequals
not_equalshas_keydoes_not_have_keyr   r0   r   re   )keyoperatorvaluerj   rQ   rR   rS   expression_specr|      s:    ed59 
  rR   c                       t        dg d      S )Nr   )level1level2level3unspecifiedrc   rj   rQ   rR   rS   aci_contract_qos_specr      s    U$QRRrR   c                 J    t        d| sdndj                  |       gg d      S )Nr   targetz
target_{0})AF11AF12AF13AF21AF22AF23AF31AF32AF33AF41AF42AF43CS0CS1CS2CS3CS4CS5CS6CS7EFVAr   )r   r   r0   )rP   format)	directions    rS   aci_contract_dscp_specr      s,    !*0C0CI0NO
 rR   c            	      v    t        t        dd      t        d      t        dd      t        dd            S )Nr   Tr`   re   )profilel3outr   tenantrj   rQ   rR   rS   route_control_profile_specr     s5    %$/ED1.	 rR   c                  .   t        t        dddg      t        ddg d      t        dddg      t        dd      t        dd      t        ddd	g
      t        d      t        d      t        d      t        d      t        dg d
            S )Nr   Ttenant_name)r   r   r   )ap_nameapp_profileapp_profile_nameepg_namer`   	version_1	version_2rc   r3   re   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   apepg	source_ipdestination_ipspan_versionversion_enforcedflow_idttlmtudscprj   rQ   rR   rS   destination_epg_specr     s    GUT3abedZLAED16u{K.HI6*% ee
' 'rR   c                      t        t        d      t        ddg d      t        d      t        dg d      t        dd	g
      t        dddg      t        d            S )Nr   re   listr   )redistributesummaryzsuppress-far   )r   elementsr0   )nssaregularstubrc   descrr   r   noyes)	area_cost	area_ctrlarea_id	area_typedescriptionmultipod_internal
name_aliasrj   rQ   rR   rS   	ospf_specr   :  sY    E"FU<uv% E+FGegY7ED%=AU# rR   c                 L    t        |       }|j                  |j                  |dS )N)protocolrA   path)r   schemenetloc)httpapi_url
local_path	parse_urls      rS   integrate_urlr   F  s%    %I!(()2B2BJWWrR   c                  J    t        t        d      t        dg d            S )Nr   re   )appendnonereplacerc   )	communitycriteriarj   rQ   rR   rS   action_rule_set_comm_specr   K  s"    E"5*GH rR   c                  p    t        t        d      t        d      t        d      t        d            S )Nr   re   )	half_lifemax_suppress_timereusesuppressrj   rQ   rR   rS   action_rule_set_dampening_specr   R  s/    E"E*5!	 rR   c                  Z    t        t        d      t        d      t        d            S )Nr   re   )r   r   r   rj   rQ   rR   rS   $associated_netflow_exporter_epg_specr   [  s'    Ue rR   c                  Z    t        t        d      t        d      t        d            S )Nr   re   )r   r   extepgrj   rQ   rR   rS   'associated_netflow_exporter_extepg_specr   c  s'     rR   c                  D    t        t        d      t        d            S )Nr   re   )r   vrfrj   rQ   rR   rS   $associated_netflow_exporter_vrf_specr   k  s    e rR   c                  N    t        t        ddg      t        dddg            S )Nr   r   r   pim_interface_policyrf   )r   pimrj   rQ   rR   rS   pim_interface_profile_specr   r  s+    8e&<f%EF rR   c                  N    t        t        ddg      t        dddg            S )Nr   r   r   igmp_interface_policyrf   )r   igmprj   rQ   rR   rS   igmp_interface_profile_specr   y  s9    t@tQVax  {A  aB  HC  D  DrR   c            	      b    t        t        d      t        d      t        dddgd            S )Nr   re   
percentageppsTrx   )rate
burst_rate	rate_typerj   rQ   rR   rS   storm_control_policy_rate_specr   }  s0    uU#EL%+@4P rR   c                   H   e Zd Zd Zd)dZd Zd Zd Zd Zd*dZ	d	 Z
d
 Zd Zd Zd Z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 Zd.dZed        Zd+dZd Zd Z ed        Z!ed         Z"d.d!Z#d" Z$d.d#Z%d.d$Z&d% Z'd& Z(d' Z)d/d(Z*y)0	ACIModulec                    || _         |j                  | _        t        d      | _        t               | _        t               | _        d | _        t        d d       | _        d | _	        t               | _
        d | _        t               | _        d | _        d| _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        t-               | _        d | _        d | _        | j                  j5                  d      | _        | j                  j5                  d      | _        | j;                          | j=                          t?        j@                         | j                  d<   | j                   jB                  r*| j                   jE                  d       d	| j                  d
<   | j                  j5                  d      !djG                  | j                        | _$        n djG                  | j                        | _$        | j                  j5                  d      ratJ        s#tL        s| j                   jO                  d       y | j                  j5                  d      | j                   jE                  d       y y | j                  I| j                  j5                  d      r| jQ                          y | j                   jO                  d       y y )NF)changedcodetext rM   rN   working_directoryz2Enable debug output because ANSIBLE_DEBUG was set.r,   rG   rB   z{protocol}://{host}:{port}z{protocol}://{host}rE   ziCannot use signature-based authentication because cryptography (preferred) or pyopenssl are not availablemsgrD   z^When doing ACI signatured-based authentication, providing parameter 'password' is not requiredzKEither parameter 'password' or 'private_key' is required for authentication))moduleparamsrP   resultheaderssetchild_classes
connectionerrorexistingconfigoriginalproposedstdoutfilter_string
obj_filtermethodr   parent_pathresponsestatusurlr   httpapi_logsimdata
totalCountgetrM   rN   define_protocolset_connectionosgetcwd_debugwarn
format_mapbase_urlHAS_CRYPTOGRAPHYHAS_OPENSSL	fail_jsonlogin)selfr  s     rS   __init__zACIModule.__init__  s;   mm5)v U t$/
  f  	 F  &*[[__5L%M" "&1D!E 	 	 ,.99;'(;;KKQR*1DKK';;??6".8CCDKKPDM1<<T[[IDM;;??=)#K%%  +V%  W,8    "B  C 9__${{z*

%%*w%x %rR   c                 Z    |y|du r|S |du r|S | j                   j                  d       y)zReturn an acceptable value backNTFz3Boolean value '%s' is an invalid ACI boolean value.r   )r  r$  )r&  r{   truefalses       rS   booleanzACIModule.boolean  s<     =d]Ke^L 	"WXrR   c                     	 |j                  d      S # t        $ r? |j                  d      }d|j                  d      |j                  dz  |dd |dd fz  cY S w xY w)	zNReturn an ACI-compatible ISO8601 formatted time: 2123-12-12T00:00:00.000+00:00milliseconds)timespecz%zz%s.%03d%s:%sz%Y-%m-%dT%H:%M:%Si  N   )	isoformat	Exceptionstrftimemicrosecond)r&  dttzs      rS   iso8601_formatzACIModule.iso8601_format  sr    		<<<88 	T"B!/0%2A12	%  	s    AAAc                     | j                   j                  d      s| j                   j                  d      dnd| j                   d<   y)z'Set protocol based on use_ssl parameterrJ   Nhttpshttpr   )r  r  r&  s    rS   r  zACIModule.define_protocol  s7     .2[[__Y-G4;;??[dKeKm'syJrR   c                     | j                   <| j                  j                  r%t        | j                  j                        | _         y y y N)r  r  _socket_pathr   r:  s    rS   r  zACIModule.set_connection  s7    ??"t{{'?'?()A)ABDO (@"rR   c                    dj                  | j                        }dd| j                  j                  d      dn| j                  j                  d      | j                  j                  d      dii}| j	                  d	|t        j                  |      d
      \  }}|j                  d      dk7  rl|j                  d      | _        |j                  d      | _        	 | j                  |d          | j                  dj                  | j                               |j                  j                  d      | j                  d<   y# t        $ r$ | j                  dj                  |             Y Uw xY w)zLog in to APICz{0}/api/aaaLogin.jsonaaaUser
attributesrC   NadminrD   )rf   pwdPOSTTdatareturn_responser     r  bodyz$Authentication failed: {code} {text}r   "Connection failed for {url}. {msg}z
Set-CookieCookie)r   r!  r  r  api_calljsondumpsr  r  response_jsonr$  r   r	  KeyErrorr  )r&  r  payloadrespauths        rS   r%  zACIModule.login  sG    &,,T]];'+{{z'B'JGPTP[P[P_P_`jPk;;??:6
 ]]63TZZ5HZ^]_
d 88H$ HHUODM((8,DKZ""4<0#I#T#TUYU_U_#`a "&!1!1,!?X  Z#G#R#RSW#XYZs    ?E *E54E5Nc                 &   |)| j                   j                  d      j                         }|| j                  }d|j	                  d      z   }|d}	 t
        rJ| j                   j                  d      j                         }t        j                  |dt                     }n)t        t        | j                   j                  d            }| j                   j                  d      E| j                   j                  d      dn| j                   j                  d      | j                   d<   ||z   |z   }	t
        rFj-                  |	j                         t/        j0                         t3        j4                               }
nt-        |	d      }
dj'                  | j                         }ddj7                  |      z   dz   dj7                  t9        t;        j<                  |
                  z   | j>                  d<   y# t        $ r t        j                  j                  | j                   j                  d            r	 d}t
        rd}t        | j                   j                  d      |      5 }|j!                         }ddd       n# 1 sw Y   nxY wnD# t        $ r8 | j"                  j%                  d	j'                  | j                         
       Y nw xY w	 t
        r!t        j                  dt                     }nt        t              }nD# t        $ r8 | j"                  j%                  dj'                  | j                         
       Y nw xY w| j                   j                  d      t        j                  j)                  t        j                  j+                  | j                   j                  d            d         | j                   d<   n5| j"                  j%                  dj'                  | j                         
       Y Cw xY w)zdPerform APIC signature-based authentication, not the expected SSL client certificate authentication.Nr  /r   rE   )rD   backendrrbz-Cannot open private key file '{private_key}'.r   z-Cannot load private key file '{private_key}'.rF   r   zgProvided private key {private_key} does not appear to be a private key or provided file does not exist.rC   rA  sha256z7uni/userext/user-{username}/usercert-{certificate_name}z!APIC-Certificate-Algorithm=v1.0; zAPIC-Certificate-DN={0}; z*APIC-Certificate-Fingerprint=fingerprint; zAPIC-Request-Signature={0}rJ  ) r  r  upperr   lstripr"  encoder   load_pem_private_keyr   r   r   r1  r  existsopenreadr  r$  r   basenamesplitextr   r   PKCS1v15r   SHA256r   r	   base64	b64encoder  )r&  r   rP  r  ry   sig_key
permissionfhprivate_key_contentsig_requestsig_signaturesig_dns               rS   	cert_authzACIModule.cert_auth  sm    >[[__X.446F <99DT[[%%?G$	kkoom4;;='<<!+- *,8VW: ;;??-.69=9T9\gbfbmbmbqbqr|b}DKK*+tmg-#LL););)=w?O?O?QSYS`S`SbcM +x@MJUUVZVaVab/)0089:; +11)F<L<L]<[2\]^ 	XK  	ww~~dkkoom<=w!$J'%)
dkkoom<jI 8R.0ggi+8 8 8  wKK)).].h.himitit.u)vw
w'"/"D"D/%)$3$5# #2,@S"T  wKK)).].h.himitit.u)vw;;??#56>68gg6F6FrwwGWGWX\XcXcXgXghuXvGwxyGz6{DKK 23%% B  M  M  NR  NY  NY  Z & 1	su   A9G; ;AP?/J.J?	JJ	JP>KPKP7LP>MPMB9PPc                    	 t        j                  |      }t        |t              r|| _	        t        |      | _        n:|j                  di       | _	        |j                  d      }|t        |      | _        | j                          y# t        $ r:}t        ddj	                  |            | _        || j                  d<   Y d}~yd}~ww xY w)z Handle APIC JSON response outputz5Unable to parse output as JSON, see 'raw' output. {0}r   rawNr  r  )rL  loadsr1  rP   r   r	  r  
isinstancer   r  lenr  r  r   response_error)r&  	rawoutputjsondataetotal_counts        rS   rN  zACIModule.response_jsonV  s    	zz),H h%"DK!(mDO",,x4DK",,|4K&"%k"2 	#  	2,c,j,jkl,mnDJ!*DKK		s   B
 
	C0CCc                 .   	 t         j                  j                  t        |            }t	        j
                  |      }|j                  di       j                  d      | _        | j                  t               | _        t        |j                  di       j                  di       j                  d	d            | _        | j                          y# t        $ r:}t        ddj                  |            | _	        || j                  d<   Y d}~yd}~ww xY w)
zHandle APIC XML response outputro  z4Unable to parse output as XML, see 'raw' output. {0}r   rp  Nr  childrenr@  r  )lxmletree
fromstringr   r   rE  r1  rP   r   r	  r  r  r  r   r  rt  )r&  ru  xmlxmldatarw  s        rS   response_xmlzACIModule.response_xmlm  s    	**''(;<CjjoG kk(B/33J?;;&DKgkk(B7;;L"MQQR^`bcd 	  	2,b,i,ijk,lmDJ!*DKK		s   =C 	D0DDc                     | j                   dk7  r4	 | j                  d   j                  d      j                  d      | _        yy# t        t
        t        f$ r Y yw xY w)z Set error information when found0r   r	  r@  N)r  r  r  r	  AttributeError
IndexErrorrO  r:  s    rS   rt  zACIModule.response_error  sZ     ??c!![[^//8<<\J
 " #J9 s   2A AAc                 <   t        d |j                         D              }|rt| j                  r| xj                  dz  c_        nd| _        | xj                  dj                  |j                         D cg c]  \  }}|d| c}}      z  c_        yyc c}}w )z,Append key-value pairs to self.filter_stringc              3   0   K   | ]  \  }}|	||f  y wr<  rQ   .0kvs      rS   	<genexpr>z&ACIModule.update_qs.<locals>.<genexpr>       T&1aam1vT   
	&?=N)rP   itemsr  join)r&  r  accepted_paramsr  r  s        rS   	update_qszACIModule.update_qs  s    TFLLNTT!!""c)"%("#((?K`K`Kb+c!Qq!,<+c"dd 
 ,ds   6Bc                 l   t        d |j                         D              }t        |      dk(  r(dj                  fd|j                         D              S t        |      dkD  rIddj                  |j                         D cg c]  \  }}dj	                  ||       c}}      z   dz   S yc c}}w )	z;Build an APIC filter based on obj_class and key-value pairsc              3   0   K   | ]  \  }}|	||f  y wr<  rQ   r  s      rS   r  z)ACIModule.build_filter.<locals>.<genexpr>  r  r     ,c              3   J   K   | ]  \  }}d j                  ||        yw)eq({0}.{1},"{2}")N)r   )r  r  r  	obj_classs      rS   r  z)ACIModule.build_filter.<locals>.<genexpr>  s&     nFQPQ/66y!QGns    #zand(r  )N)rP   r  rs  r  r   )r&  r  r  r  r  r  s    `    rS   build_filterzACIModule.build_filter  s    TFLLNTT1$88nVeVkVkVmnnn!A%CHH`o`u`u`w%xV\WXZ[&9&@&@Aq&Q%xyy| &%xs   B0c                 F   |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }	| j                  j                  j                  d	      d
v r,|*dj                  |      | _        | j                  ddi       ny|dj                  |      | _        ndj                  |      | _        |	r#| j                  d| j                  ||      i       |r#| j                  d| j                  ||      i       | j                  j                  d      8 dj                  dd| j                  i| j                  j                  | _        n7 dj                  dd| j                  i| j                  j                  | _        | j                  r7| j                  ddj                  t        | j                              d       y y )Ntarget_classtarget_filtersubtree_classsubtree_filter	object_rnmodule_objectadd_subtree_filteradd_target_filterstateabsentpresentapi/mo/uni/{0}.jsonrsp-prop-includeconfig-onlyapi/class/{0}.jsonquery-target-filterrsp-subtree-filterrB   !{protocol}://{host}:{port}/{path}r   {protocol}://{host}/{path}fullr  rsp-subtreezrsp-subtree-classrQ   )r  r  r  r   r   r  r  r  r  r  sorted)
r&  objr  r  r  r  r  mor  r  s
             rS   _deep_url_path_builderz ACIModule._deep_url_path_builder  s   ww~.00!12GGK(	WW_% WW%9:GG$78;;!!'*.CC-44Y?DINN.>? $188C	077E	  5t7H7HWd7efg! 4d6G6GWe6fgh;;??6".A:AAgtyygTXT_T_TfTfgDH ;3::`		`T[[M_M_`DHNN#)),&9K9K2L)M rR   c                 @    |D ]  }|j                  d      |u s|c S  y )N	aci_class)r  )r&  parent_objectsparent_classparent_objects       rS   _deep_url_parent_objectz!ACIModule._deep_url_parent_object  s/    + 	%M  -=$$	% rR   c                 
   d| _         d}d}d}d}d}d}	d}
d}|t               | _        nt        |      | _        |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }t	        |||||	      }||}nd
}d
}	||}d}d}d
}d}t               }|dk7  r| j                  ||      }||j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|rd
}nd}d}|dk7  r|j                  |       |$|dj                  ||      }n|}||d<   ||d<   d}n
d}|}d
}|rd
}|}nt        dj                  |            |
s	|s||	urd
}
n|s||urd
}d
}|dk7  r|s|r|d
}n|r$|"d
}| j                  j                  |       |rd
}n|r;|s9|7| j                  j                  |       | j                  j                  |       nC|s |s|| j                  j                  |       n!|s|r|| j                  j                  |       ||d<   ||d<   ||d<   | j                  |       y)a  
        This method is used to retrieve the appropriate URL path and filter_string to make the request to the APIC.

        :param target_object: The target class dictionary containing parent_class, aci_class, aci_rn, target_filter, and module_object keys.
        :param parent_objects: The parent class list of dictionaries containing parent_class, aci_class, aci_rn, target_filter, and module_object keys.
        :param child_classes: The list of child classes that the module supports along with the object.
        :type target_object: dict
        :type parent_objects: list[dict]
        :type child_classes: list[string]
        :return: The path and filter_string needed to build the full URL.
        r   NFr  r  aci_rnr  r  )r  r  r  r  r  Tuni)r  r  z{0}/{1}r  zWReference error for parent_class '{0}'. Each parent_class must reference a valid objectr  r  r  )r  r  r  r  rP   r  addr   
ValueErrorupdater  )r&  target_objectr  r  
rn_buildersubtree_classesr  r  has_target_queryhas_target_query_comparehas_target_query_differencehas_target_query_calledtarget_parent_classr  	target_rnr  target_module_objecturl_path_objectcurrent_parent_classhas_parent_query_comparehas_parent_query_differenceis_first_parentis_single_parentsearch_classesr  parent_parent_classr  	parent_rnparent_filterparent_module_objects                                 rS   construct_deep_urlzACIModule.construct_deep_url  sG     
"! #( &+#"' !$D!$]!3D+//?$((5!%%h/	%))/:,00A%'&(.
  +"J#'+$%#6 ',$*/'"O# UN&%/ $ < <Ni} < ~ ,*7*;*;N*K'#0#4#4[#AL - 1 1( ;I$1$5$5o$FM+8+<+<_+M(&+/(+0(&+O*e3&**<8+7%1)2)9)9)Z)PJ)2J:F7;H8+0(%)
*8+/(+7;4+>($%~  &F  &F  G[  &\  ]  ]2;R'/GG6:36;KSk;k6:3*.'_ '%/b /3KPdPp$(!,1E1Q%)"""&&|4#(,%,5EJ^Jf""&&|4""))/:09INbNj""&&|4%*:?S?[""&&|4'1$0B,-/@+,##O4rR   c           
      l   d| _         |t               | _        nt        |      | _        || j                  ||||||||	       n|| j	                  |||||||	       np|| j                  ||||||	       nW|| j                  |||||	       n?|| j                  ||||	       n(|| j                  |||	       n| j                  ||	       | j                  j                  d      8 dj                  dd| j                  i| j                  j                  | _        n7 dj                  dd| j                  i| j                  j                  | _        | j                  r7| j!                  |
dj#                  t%        | j                              d       y|
d	k(  r| j!                  d
|
i       yy)a,  
        This method is used to retrieve the appropriate URL path and filter_string to make the request to the APIC.

        :param root_class: The top-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_1: The second-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_2: The third-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_3: The fourth-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param child_classes: The list of child classes that the module supports along with the object.
        :type root_class: dict
        :type subclass_1: dict
        :type subclass_2: dict
        :type subclass_3: dict
        :type subclass_4: dict
        :type subclass_5: dict
        :type subclass_6: dict
        :type child_classes: list
        :return: The path and filter_string needed to build the full URL.
        r   NrB   r  r   r  r  r  rz  r  rQ   )r  r  r  _construct_url_7_construct_url_6_construct_url_5_construct_url_4_construct_url_3_construct_url_2_construct_url_1r  r  r   r   r  r  r  r  r  )r&  
root_class
subclass_1
subclass_2
subclass_3
subclass_4
subclass_5
subclass_6r  config_onlyrsp_subtrees              rS   construct_urlzACIModule.construct_urlU  s   >   !$D!$]!3D!!!*j*jR\^hjt  wB  C#!!*j*jR\^hjuv#!!*j*jR\^ij#!!*j*jR]^#!!*j*kR#!!*j+F!!*k:;;??6".A:AAgtyygTXT_T_TfTfgDH:3::`		`T[[M_M_`DHNN#.),&9K9K2L)M J&NNM;78 'rR   c                    |j                  d      }|j                  d      }|j                  d      }|j                  d      }| j                  j                  j                  d      dv r:dj                  |      | _        d| _        |r| j                  d	d
i       || _        y|=dj                  |      | _        |$| j                  d| j                  ||      i       yydj                  |      | _        y)z^
        This method is used by construct_url when the object is the top-level class.
        r  r  r  r  r  r  r  zapi/mo/uni.jsonr  r  Nr  r  )	r  r  r  r   r   r  r  r  r  )r&  r  r  r  obj_rnr  r  s          rS   r  zACIModule._construct_url_1  s     GGK(	"WW_-
WW_%;;!!'*.CC-44V<DI0D 2MBC(DOZ,33I>DI% 5t7H7HT^7_`a & .44V<DIrR   c                 <   |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }	| j                  j                  j                  d      dv rJdj                  ||      | _        dj                  |      | _        |r| j                  d	d
i       || _        y|<|	:dj                  |      | _        | j                  d| j                  ||      i       y|:dj                  |      | _        | j                  d| j                  ||      i       y|	2| j                  j                  |       dj                  |      | _        ydj                  ||      | _        y)za
        This method is used by construct_url when the object is the second-level class.
        r  r  r  r  r  r  api/mo/uni/{0}/{1}.jsonr  r  r  Nr  r  )r  r  r  r   r   r  r  r  r  r  r  )
r&  parentr  r  r  
parent_objr  r  r  r  s
             rS   r  zACIModule._construct_url_2  sn    JJx(	ZZ0
GGK(	"WW_-
WW_%;;!!'*.CC188FKDI4;;IFD 2MBC(DOBJ,33I>DINN143D3DYPZ3[\],33I>DINN143D3DYPZ3[\]Z""9--44Y?DI 288FKDIrR   c                    |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }	|j                  d      }
|j                  d      }|j                  d      }|j                  d      }|j                  d      }| j                  j                  j                  d      dv rLdj                  |||      | _        dj                  ||      | _        |r| j                  d	d
i       || _        y|>|
<|:dj                  |      | _        | j                  d| j                  ||      i       y|<|
:dj                  |      | _        | j                  d| j                  ||      i       y|W|U| j                  j                  |       dj                  |      | _        | j                  d| j                  ||	      i       y|
6|4| j                  j                  ||g       dj                  |      | _        y|x| j                  j                  |       dj                  |      | _        | j                  d| j                  ||	      i       | j                  d| j                  ||      i       y|
U| j                  j                  |       dj                  |      | _        | j                  d| j                  ||      i       y|3| j                  j                  |       dj                  ||      | _        ydj                  |||      | _        y)z`
        This method is used by construct_url when the object is the third-level class.
        r  r  r  r  r  r  api/mo/uni/{0}/{1}/{2}.jsonr  r  r  Nr  r  r  r  )r  r  r  r   r   r  r  r  r  r  r  r  )r&  rootr  r  r  root_rnroot_objr  r  r  r  r  r  r  r  s                  rS   r  zACIModule._construct_url_3  s    ((8$88O,zz+.JJx(	

?3ZZ0
GGK(	"WW_-
WW_%;;!!'*.CC5<<WiQWXDI8??SD 2MBC(DO*"4,33I>DINN143D3DYPZ3[\]*"4,33I>DINN143D3DYPZ3[\]"* ""9-,33LADINN143D3D\S`3abcBJ%%|Y&?@-44W=DI  ""9-,33LADINN143D3D\S`3abcNN0$2C2CIz2Z[\""9--44W=DI NN0$2C2CIz2Z[\Z""9-188)LDI
 6<<WiQWXDIrR   c                    |j                  d      }|j                  d      }|j                  d      }|j                  d      }	|j                  d      }
|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }| j                  |g| _        | j                  j                  j                  d      dv rNdj	                  |||
|      | _        d	j	                  |||
      | _        |r| j                  d
di       || _        y|U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|	U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|V| j                  j                  |       dj	                  ||      | _        | j                  d| j                  ||      i       y|4| j                  j                  |       d	j	                  |||
      | _        ydj	                  |||
|      | _        y)a
        This method is used by construct_url when the object is the fourth-level class.
        r  r  r  r  Nr  r  api/mo/uni/{0}/{1}/{2}/{3}.jsonr  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  r  r  )r&  r  secr  r  r  r  r  sec_rnsec_objr  r  r  r  r  r  s                   rS   r  zACIModule._construct_url_4  sD    ((8$88O,"''/*JJx(	ZZ0
GGK(	"WW_-
WW_%%"+D;;!!'*.CC9@@&R[]cdDI<CCGVU^_D 2MBC(DO""9-,33I>DINN143D3DYPZ3[\]_""9--44W=DI NN0$2C2CIz2Z[\""9-188&IDI NN0$2C2CIz2Z[\Z""9-5<<WfiXDI
 :@@&R[]cdDIrR   c                    |j                  d      }|j                  d      }|j                  d      }	|j                  d      }
|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }| j                  |g| _        | j                  j                  j                  d      dv rPdj	                  ||	|||      | _        d	j	                  ||	||      | _        |r| j                  d
di       || _        y|U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|
U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|V| j                  j                  |       dj	                  ||	      | _        | j                  d| j                  ||      i       y|W| j                  j                  |       dj	                  ||	|      | _        | j                  d| j                  ||      i       y|5| j                  j                  |       d	j	                  ||	||      | _        ydj	                  ||	|||      | _        y)r  r  r  r  r  Nr  r  #api/mo/uni/{0}/{1}/{2}/{3}/{4}.jsonr  r  r  r  r  r  r  r  r  r  )r&  r  terr  r  r  r  r  r  ter_rnter_objr  r  r  r  r  r  r  r  s                      rS   r  zACIModule._construct_url_5M  s   
 ((8$88O,"''/*"''/*JJx(	ZZ0
GGK(	"WW_-
WW_%%"+D;;!!'*.CC=DDWfV\^giopDI@GGQWY_ajkD 2MBC(DO""9-,33I>DINN143D3DYPZ3[\]_""9--44W=DI NN0$2C2CIz2Z[\_""9-188&IDI NN0$2C2CIz2Z[\""9-5<<WffUDI NN0$2C2CIz2Z[\Z""9-9@@&RXZcdDI
 >DDWfV\^giopDIrR   c                    |j                  d      }|j                  d      }	|j                  d      }
|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }| j                  |g| _        | j                  j                  j                  d      dv r8dj	                  ||
||||      | _        |r| j                  d	d
i       || _        y|	U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|V| j                  j                  |       dj	                  ||
      | _        | j                  d| j                  ||      i       y|W| j                  j                  |       dj	                  ||
|      | _        | j                  d| j                  ||      i       y|X| j                  j                  |       dj	                  ||
||      | _        | j                  d| j                  ||      i       y|6| j                  j                  |       dj	                  ||
|||      | _        ydj	                  ||
||||      | _        y)z`
        This method is used by construct_url when the object is the fifth-level class.
        r  r  r  r  Nr  r  'api/mo/uni/{0}/{1}/{2}/{3}/{4}/{5}.jsonr  r  r  r  r  r  r  r  r  r  
r  r  r  r  r   r   r  r  r  r  )r&  r  quadr  r  r  r  r  r  r  quad_rnquad_objr  r  r  r  r  r  r  r  r  r  s                         rS   r  zACIModule._construct_url_6  s    ((8$88O,((8$88O,"''/*"''/*JJx(	ZZ0
GGK(	"WW_-
WW_%%"+D;;!!'*.CCAHHRY[aciktv|}DI 2MBC(DO""9-,33I>DINN143D3DYPZ3[\]""9--44W=DI NN0$2C2CIz2Z[\_""9-188'JDI NN0$2C2CIz2Z[\_""9-5<<WgvVDI NN0$2C2CIz2Z[\""9-9@@'SY[abDI NN0$2C2CIz2Z[\Z""9-=DDWgW]_egpqDI
 BHHRY[aciktv|}DIrR   c	           	         |j                  d      }	|j                  d      }
|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }| j                  |g| _        | j                  j                  j                  d      dv r9dj	                  |	||||||      | _        |r| j                  d	d
i       || _        y|
U| j                  j                  |       dj	                  |      | _        | j                  d| j                  ||      i       y|U| j                  j                  |       dj	                  |	      | _        | j                  d| j                  ||      i       y|V| j                  j                  |       dj	                  |	|      | _        | j                  d| j                  ||      i       y|W| j                  j                  |       dj	                  |	||      | _        | j                  d| j                  ||      i       y|X| j                  j                  |       dj	                  |	|||      | _        | j                  d| j                  ||      i       y|Y| j                  j                  |       dj	                  |	||||      | _        | j                  d| j                  ||      i       y|7| j                  j                  |       dj	                  |	|||||      | _        ydj	                  |	||||||      | _        y)z`
        This method is used by construct_url when the object is the sixth-level class.
        r  r  r  r  Nr  r  z+api/mo/uni/{0}/{1}/{2}/{3}/{4}/{5}/{6}.jsonr  r  r  r  r  r  r  r  r  r  r  r  )r&  r  quinr  r  r  r  r  r  r  r  quin_rnquin_objr	  r
  r  r  r  r  r  r  r  r  r  r  s                            rS   r  zACIModule._construct_url_7  s    ((8$88O,((8$88O,((8$88O,"''/*"''/*JJx(	ZZ0
GGK(	"WW_-
WW_%%"+D;;!!'*.CCELLWV]_fhnpv  yB  DJ  KDI 2MBC(DO""9-,33I>DINN143D3DYPZ3[\]""9--44W=DI NN0$2C2CIz2Z[\""9-188'JDI NN0$2C2CIz2Z[\_""9-5<<WgwWDI NN0$2C2CIz2Z[\_""9-9@@'SZ\bcDI NN0$2C2CIz2Z[\""9-=DDWgW^`fhnoDI NN0$2C2CIz2Z[\Z""9-AHHRY[bdjlrt}~DI
 FLLWV]_fhnpv  yB  DJ  KDIrR   c                     t               | _        | j                  s| j                  sy| j                  j
                  s | j                  d| j                  dd       yd| j                  d<   d| _	        y)z
        This method is used to handle the logic when the modules state is equal to absent. The method only pushes a change if
        the object exists, and if check_mode is False. A successful change will mark the module as changed.
        NDELETEFrF  Tr   )
rP   r  r
  rN   r  
check_moderK  r  r  r  r:  s    rS   delete_configzACIModule.delete_config!  sY    
 }}T%;%;''MM(DHHdEMJ%)DKK	""DKrR   c                    | j                   |   d   }| j                  r| j                  d   |   d   }i }|j                         D ]!  \  }}|j                  |      }||k7  s|||<   # |r)|r!t	        |t
              r|j                  |       |d|ii}| j                  |      }	|	r |r||   j                  d|	i       || _        y|	r|i |	di}|| _        y| j                   }|| _        y)a  
        This method is used to get the difference between the proposed and existing configurations. Each module
        should call the get_existing method before this method, and add the proposed config to the module results
        using the module's config parameters. The new config will added to the self.result dictionary.
        :param aci_class: Type str.
                          This is the root dictionary key for the MO's configuration body, or the ACI class of the MO.
        r@  r   rz  r@  rz  N)	r  r
  r  r  rr  rP   r  get_diff_childrenr  )
r&  r  required_propertiesproposed_configexisting_configr  ry   r{   existing_fieldrz  s
             rS   get_diffzACIModule.get_diff1  s    --	2<@=="mmA.y9,GOF .335 (
U!0!4!4S!9N*"'F3K( &:6I4+PMM"56#lF%;< --i8HFy!((*h)?@  #BH%MN  ]]FrR   c                     | di ii}|j                         D ]'  \  }}|j                  |      }||k7  s|||    d   |<   ) ||    d   sy|S )a  
        This method is used to get the difference between a proposed and existing child configs. The get_nested_config()
        method should be used to return the proposed and existing config portions of child.
        :param child_class: Type str.
                            The root class (dict key) for the child dictionary.
        :param proposed_child: Type dict.
                               The config portion of the proposed child dictionary.
        :param existing_child: Type dict.
                               The config portion of the existing child dictionary.
        :return: The child config with only values that are updated. If the proposed dictionary has no updates to make
                 to what exists on the APIC, then None is returned.
        r@  N)r  r  )child_classproposed_childexisting_childupdate_configry   r{   r  s          rS   get_diff_childzACIModule.get_diff_childW  su     %|R&89(..0 	FJC+//4N&@Ek*<8=	F
 [),7rR   c                    || j                   |   j                  d      }n|}|rg }|#| j                  d   |   j                  dg       }n|}|D ]r  }| j                  ||      \  }}	}
| j	                  ||      \  }}|
|}n,| j                  ||	|
      }|r| j                  |||      }|r|}|sb|j                  |       t |S y)a  
        This method is used to retrieve the updated child configs by comparing the proposed children configs
        against the objects existing children configs.
        :param aci_class: Type str.
                          This is the root dictionary key for the MO's configuration body, or the ACI class of the MO.
        :return: The list of updated child config dictionaries. None is returned if there are no changes to the child
                 configurations.
        Nrz  r   )r  r  r
  get_nested_configget_nested_childrenr!  r  r   )r&  r  proposed_objexisting_objproposed_childrenchild_updatesexisting_childrenchildr  r  r  proposed_child_childrenexisting_child_childrenchild_updatechild_update_childrens                  rS   r  zACIModule.get_diff_childrenp  s     $i 8 < <Z H ,M#$(MM!$4Y$?$C$CJPR$S!$0! + 7>B>T>TUZ\m>n;^^ ,,U4EF++ ")#(L#'#6#6{NTb#cL.040F0FyRi  lC  1D-0+0L  !((6'7.  rR   c                     | j                   rg | _        y| j                  | j                  z   }| j	                  d|dd       y)aH  
        This method is used to get the existing object(s) based on the path specified in the module. Each module should
        build the URL so that if the object's name is supplied, then it will retrieve the configuration for that particular
        object, but if no name is supplied, then it will retrieve all MOs for the class. Following this method will ensure
        that this method can be used to supply the existing configuration when using the get_diff method. The response, status,
        and existing configuration will be added to the self.result dictionary.
        NGETFrD  )rN   r
  r  r  rK  )r&  uris     rS   get_existingzACIModule.get_existing  s?     !!DMhh+++eStUCrR   c                     | j                   rQ|s| j                  r3d| j                  d<   | j                  i k7  r| j                  gng | _        yd| j                  d<   y|r/| j
                  | j                  z   }| j                  d|dd       yy)ae  
        This method is used to get the existing object(s) state after a config change has been completed.
        It will not get the object(s) state if there is no change or suppress_verification is enabled.
        When suppress_verification is enabled, the existing will be set to proposed if there was a change or suppress_previous is enabled.
        Fcurrent_verifiedTr0  NrD  )rM   rN   r  r  r
  r  r  rK  )r&  r   r1  s      rS   __get_existing_validationz#ACIModule.__get_existing_validation  s     %%$0027./37==B3FB 37./((T///CMM%4MG rR   c                    | j                         D ]r  }|}| |   d   }d}|D ]_  }|j                  |      s||   d   }t        |j                               j	                  t        |j                                     r od}a t fS )a<  
        This method is used for stiping off the outer layers of the child dictionaries so only the configuration
        key, value pairs are returned.
        :param proposed_child: Type dict.
                               The dictionary that represents the child config.
        :param existing_children: Type list.
                                  The list of existing child config dictionaries.
        :return: The child's class as str (root config dict key), the child's proposed config dict, and the child's
                 existing configuration dict.
        r@  Nkeysr  r  r  issubset)r  r)  ry   r  r  r  r*  s          rS   r#  zACIModule.get_nested_config  s     "&&( 	+CK,S1,?O"O + +99[)&+Cj&>O ?0023<<SAVAVAX=YZ&*O+	+  O_<<rR   c                 l   | j                         D ]  }|}| |   d   }d}| |   j                  d      }d}|D ]u  }|j                  |      s||   d   }||   j                  d      }t        |j                               j	                  t        |j                                     r d}d}w  fS )a$  
        This method is used for stiping off the outer layers of the child dictionaries so only the children are returned.
        :param proposed_child: Type dict.
                               The dictionary that represents the child config.
        :param existing_children: Type list.
                                  The list of existing child config dictionaries.
        :return: The child's class as str (root config dict key), the child's proposed children as a list and the child's
                 existing children as a list.
        r@  Nrz  r7  )	r  r)  ry   r  r  r  r'  r,  r*  s	            rS   r$  zACIModule.get_nested_children  s     "&&( 	+CK,S1,?O"O .s 3 7 7
 C&*# + 	+99[)&+Cj&>O.3CjnnZ.H+ ?0023<<SAVAVAX=YZ.2+&*O	+	+( !"999rR   c                 .   t        d |j                         D              }| j                  j                  d      | j                  j                  d      |d<   | j                  j                  d      | j                  j                  d      |d<   | j                  j                  d      | j                  j                  d      |d<   |d|ii| _        |r=| j                  |      }|r)| j                  |   j                  t        |	             yyy)
a  
        This method is used to dynamically build the proposed configuration dictionary from the config related parameters
        passed into the module. All values that were not passed values from the playbook task will be removed so as to not
        inadvertently change configurations.
        :param aci_class: Type str
                          This is the root dictionary key for the MO's configuration body, or the ACI class of the MO.
        :param class_config: Type dict
                             This is the configuration of the MO using the dictionary keys expected by the API
        :param child_configs: Type list
                              This is a list of child dictionaries associated with the MOs config. The list should only
                              include child objects that are used to associate two MOs together. Children that represent
                              MOs should have their own module.
        c              3   B   K   | ]  \  }}|	|t        |      f  y wr<  )r   r  s      rS   r  z$ACIModule.payload.<locals>.<genexpr>  s      V1CFVs   
rW   Nr\   ownerKeyr]   ownerTagr@  )rz  )rP   r  r  r  r  handle_child_configsr  )r&  r  class_configchild_configsr  rz  s         rS   rP  zACIModule.payload  s     V0B0B0DVV;;??<(4%)[[__\%BH\";;??;'3#';;??;#?HZ ;;??;'3#';;??;#?HZ "\8$<= 00?Hi(//h0GH  rR   c                    g }|D ]  }t        |      }d}|j                         D ]  }||   d   j                         D ]5  \  }}|||   d   j                  |        t	        |      ||   d   |<   d}7 ||   j                  d      fd}| j                  ||   d         ||   d<    |s|j                  |        |S )NFr@  Trz  )r   r8  r  popr   r  r?  r   )	r&  rA  rz  r*  
child_copy	has_value
class_name	attributer{   s	            rS   r?  zACIModule.handle_child_configs  s    " 	'E!%JI(oo/ 	r
(2:(>|(L(R(R(T )$Iu}j),7;;IFEHZj),7	B$(	) j)--j9E $I484M4MjYcNdeoNp4qE*%j1	r &	' rR   c                 &   | j                   sy| j                  j                  s| j                  }|| j                  j                  d      3 dj                  dd| j                  i| j                  j                  }n2 dj                  dd| j                  i| j                  j                  }|i | j                   gdi| _         | j                  d|t        j                  | j                         d	       yd
| j                  d<   d| _        y)a"  
        This method is used to handle the logic when the modules state is equal to present. The method only pushes a change if
        the object has differences than what exists on the APIC, and if check_mode is False. A successful change will mark the
        module as changed.
        NrB   r  r   r  r  rC  Fr  Tr   rQ   )r  r  r  r  r  r  r   r  rK  rL  rM  r  r  )r&  r  r  s      rS   post_configzACIModule.post_config/  s     {{''((C';;??6*6D=DDq$JZJZq^b^i^i^p^pqC=6==j4CSCSjW[WbWbWiWijC+BT[[M-Z[MM&#tzz$++'>PUMV%)DKK	" DKrR   c                 @   d| j                   v rn| j                   j                  d      dv rQ| j                   j                  d      dv r4|s| j                  n |d   | j                  |d         | j                  d<   | j                   j                  d      dk(  rd| j                   v r| j                  | j                  d	<   | j
                  | j                  d
<   | j                  | j                  d<   | j                  | j                  d<   | j                  | j                  d<   | j                  | j                  | j                  d<   | j                  r| j                  | j                  d<   d| j                   v r| j                  | _        | j                   j                  d      dv r| j                  | j                  d          |s| j                  n |d   | j                  |d         | j                  d<   | j                   j                  d      dv r2| j                  | j                  d<   | j                  | j                  d<   | j                           | j                  j                   di |  | j"                  j$                  di | j                   y)a  
        :param filter_existing: tuple consisting of the function at (index 0) and the args at (index 1)
        CAUTION: the function should always take in self.existing in its first parameter
        :param kwargs: kwargs to be passed to ansible module exit_json()
        filter_existing is not passed via kwargs since it cant handle function type and should not be exposed to user
        r  r  rG   r,   r-   r   r  previousr,   r  r  r  r  r  Nr  r  r   currentsentr  rQ   )r  r  r
  r  r  r  r  r  r  r  r  r  #_ACIModule__get_existing_validationr  r  	dump_jsonr  r  	exit_json)r&  filter_existingkwargss      rS   rQ  zACIModule.exit_jsonE  s:    dkk!{{w'+@@;;??>26GGCRdmmXjXghiXjkokxkx  {J  KL  {M  YNDKK
+ ;;??>*g5$++%/3/A/AO,$(KKDKK!&*mmDKK
#$(KKDKK!!%DKK  ,.2.?.?N+;;$(KKDKK!dkk! MMDM{{w'+@@..t{{9/EF ;JT]]Oa_`Oabfbobo  rA  BC  rD  PEDKK	"{{~.2CC&*kkF#*.--J'$V$,,rR   c                 \   | j                   j                  d      4| j                   j                  d      | j                   | j                  d<   | j                  r| j                  | j                  d<   d| j                  v r| j                  j                  d      dv r6| j                  j                  d      dv r| j
                  | j                  d	<   | j                  j                  d      d
k(  r>| j                  2| j                  | j                  d<   | j                  | j                  d<   | j                  j                  d      d
k(  r| j                  d| j                  v r| j                  | j                  d<   | j                  | j                  d<   | j                  | j                  d<   | j                  | j                  d<   | j                  | j                  d<   | j                  | j                  | j                  d<   d| j                  v rO| j                  j                  d      dv r2| j                  | j                  d<   | j                  | j                  d<    | j                  j                   di |  | j"                  j$                  dd|i| j                   y )Nr   r   r	  r  r  r  rG   rK  rL  r,   r  r  r  r  r  r  r  r  rN  r  r  rQ   )r	  r  r  r  r  r
  r  r  r  r  r  r  r  r  r  r  r  r  r$  )r&  r  rS  s      rS   r$  zACIModule.fail_jsont  s   ::>>&!-$**..2H2T#'::DKK ;;$(KKDKK!dkk!{{w'+@@;;??>26GG.2mmDKK
+ {{~.'9;;*,0KKDKK)04DKK-;;??>*g5xx#dkk)373E3EDKK0(,H%*.--J'(,H%%)XXE"  ,.2.?.?N+dkk!{{~.2CC&*kkF#*.--J'$V$5#55rR   c                    | j                   j                  d      dv r]| j                  j                  dd      d   }|dd  dk(  r|d d }i }| j                  rS| j                  }|D ]A  }|||   d	   d
<   | j
                  d| j
                  v s*| j
                  d   ||   d	   d<   C nX| j                   j                  d      dk(  r:| j                  r.| j                  d   D ]  }t        t        |d            ||<    || j                  d<   | j                   j                  d      }|Jt        |d      5 }| j                  j                  d      du rt        j                  |g|       d d d        y y y # 1 sw Y   y xY w)Nr  r  z/mo/r  )maxsplitro  z.jsonr@  dntDnr  r   deleted)rX  r  )r@  r  rL   ar   T)r  r  r  rsplitr  r  r
  rP   r  r^  rL  dump)r&  dn_pathr  r  rL   output_files         rS   rP  zACIModule.dump_json  s   ;;??7#'<<hhoofqo9"=Grs|w&!#2,B}}]]!# XI8?ByM,/52 DOO3AEQVAWByM,7>	X )X5$--!%q!1 XI$(DGI4V$WByMX !#DKK++//-8K&+s+ 5{{{y1T9		2$45 5 '' =(5 5s   =5E==Fc                     t         s| j                  d       t        |      }|j                  dk(  r|j                  S |j                  dz   |j                  z   S )Nzurlparse is not installedr   r   r  )HAS_URLPARSEr$  r   queryr   )r&  r  parse_results      rS   parsed_url_pathzACIModule.parsed_url_path  sS    NN:N;}#$$$$$s*\-?-???rR   c                    d }| j                   | j                   j                  | j                         | j                   j                  || j	                  |      |      }dj                  t        |j                  d      | j                              | _	        |j                  d      | _
        | j                  j                  | j                   j                                n| j                  j                  d      r#| j                  | j	                  |      ||       t        | j                   ||| j"                  || j                  j                  d      dn| j                  j                  d      | j                  j                  d      d	n| j                  j                  d      
      \  }}|j                  d      | _        |j                  d      | _        || _        |r||fS |j                  d      dk(  rl|dk(  s|dk(  rd	| j*                  d<   	 |dk(  r,t-        j.                  |j1                               d   | _        n | j5                  |j1                                y y 	 | j5                  |d          | j9                  dj                  | j                               y # t6        $ rW |dk(  r-t-        j.                  |j                  d            d   | _        n"| j5                  |j                  d             Y y Y y w xY w# t:        $ r$ | j9                  dj                  |             Y y w xY w)Nr  r  r	  rE   )r   rP  r  rH      rI   T)rE  r  r  rH   rI   r  r  rG  rC  r  r   r0  r  rH  zAPIC Error {code}: {text}r   rI  )r  
set_paramsr  send_requestrd  r   r   r  r   r  r	  r  extendpop_messagesrm  r   r  r  r  r  r  r  rL  rq  r_  r
  rN  r  r$  rO  )r&  r  r  rE  rF  rQ  r-   s          rS   rK  zACIModule.api_call  s   ??&OO&&t{{3??//8L8LS8QSWXD3>>}TXXV[_^b^g^g?hiDH'*DJ$$T__%A%A%CD{{}-D$8$8$=tTZ[""kkooi8@dkkooV_F`"&++//+">"F$DKKOO\gLhJD$ hhx(: xx!S(V#v'9-1DKK	*	=(,

499;(?(I**499;7 &^&&tF|4NN'B'M'Mdjj'YNZ & =(,

488F3C(DX(N**488F+;< &=   ^NN'K'V'VW['\N]^s&   AJ0 0?L 0ALL*M ?M )r   r   )Nr   N)NN)	NNNNNNNTr  )Tr<  )NF)+__name__
__module____qualname__r'  r+  r6  r  r  r%  rm  rN  r  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  staticmethodr!  r  r2  rO  r#  r$  rP  r?  rI  rQ  r$  rP  rd  rK  rQ   rR   rS   r   r     s8   FyPYzC@<C
J.,e@(TA5L C9J=2 LDAYF3ej=q~D~LMK^# $L  0-^DH" = =: : :@I<&!,--^%6N52@1^rR   r   r<  )B
__future__r   r   r   r   __metaclass__rd  rL  r  copyr   ansible.module_utils.urlsr   ansible.module_utils._textr   r	   ansible.module_utils.basicr
   ansible.module_utils.connectionr   OpenSSL.cryptor   r   r   r#  ImportErrorcryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   cryptography.hazmat.backendsr   r"  
lxml.etreer{  HAS_LXML_ETREExmljsonr   HAS_XMLJSON_COBRA+ansible.module_utils.six.moves.urllib.parser   ra  r1  rT   rX   r^   rk   rp   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   objectr   rQ   rR   rS   <module>r     s`  R A @   	  / : 3 6BBK
DA<
N
DL
0fB&S@(V	X
Di^ i^S
  K    N    LsY   B? C C %C& .C3 ?C	C	CCC#"C#&C0/C03C=<C=