
    Vh(                        d dl mZmZmZ eZd dlmZ 	 d dlm	Z	 dZ
d dlmZ d dlmZmZmZmZ d dlmZ  e       Zej-                   e ed	d
d
dg       ed	       ed	       ed	       ed	       ed	       ed	       ed	       ed       ed	      
             dddgdfgZg Zg Zg Z G d de      Z G d de      Zy# e$ r dZ
Y w xY w)    )absolute_importdivisionprint_function)
ActionBase)AnsibleArgSpecValidatorTF)AnsibleActionFail)ISESDKise_argument_specise_compare_equalityget_dict_result)InconsistentParametersstrpresentabsent)typedefaultchoices)r   bool)
statedescriptionsxpPeersxpVpnsxpNode	ipAddresssxpMode
sxpVersionenabledidr   r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
SxpConnectionsc                 R   || _         t        |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d	      
	      | _        y )Nr   r   r   r   r   r   r   r   r   )	r   sxp_peersxp_vpnsxp_node
ip_addresssxp_modesxp_versionr   r   )isedictget
new_object)selfparamsr(   s      l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/ise/plugins/action/sxp_connections.py__init__zSxpConnections.__init__:   s    

=1ZZ	*JJx(ZZ	*zz+.ZZ	*

<0JJy)zz$

    c                 N   d }| j                   j                  dd      }	 |D ]'  }|j                  d   d   }t        |d|      }|s%|c S  	 |S # t        t
        f$ r7}| j                   j                  dj                  |      	       Y d }~|S d }~wt        $ r d }|cY S w xY w)
Nsxp_connectionsget_sxp_connections_generator)familyfunctionSearchResult	resourcesname'  An error occured when executing operation. Check the configuration of your API Settings and API Gateway settings on your ISE server. This collection assumes that the API Gateway, the ERS APIs and OpenAPIs are enabled. You may want to enable the (ise_debug: True) argument. The error was: {error}errormsg)	r(   execresponser   	TypeErrorAttributeError	fail_jsonformat	Exception)r,   r8   resultgen_items_responsesitems_responseitemses          r.   get_object_by_namez!SxpConnections.get_object_by_nameH   s    "hhmm$/N , 
	"5 "&//?L(=!M	"$  >* 		HH.
 &q&/      	FM	s)   &A A A B$,BB$#B$c                    	 | j                   j                  dddd|i      j                  d   }|S # t        t        f$ r7}| j                   j                  dj                  |      	       Y d }~S d }~wt        $ r d }Y |S w xY w)
Nr2   get_sxp_connections_by_idFr   )r4   r5   handle_func_exceptionr-   ERSSxpConnectionr9   r:   r<   )r(   r>   r?   r@   rA   rB   rC   rD   )r,   r   rE   rI   s       r.   get_object_by_idzSxpConnections.get_object_by_idc   s    	XX]](4&+bz	 # 
 h)+F$  >* 		HH.
 &q&/      	F	s   .2 B,A33BBc                    d}d}d }| j                   j                  d      }| j                   j                  d      }|r'| j                  |      }|d uxr t        |t              }|s)|r'| j                  |      }|d uxr t        |t              }|r8|j                  d      }|r|r||k7  rt        d      |r| j                  |      }|d uxr t        |t              }||fS )NFr   r8   z9The 'id' and 'name' params don't refer to the same object)r+   r*   rO   
isinstancer)   rJ   r   )r,   	id_existsname_existsprev_objo_idr8   _id	it_existss           r.   existszSxpConnections.existsy   s    	""4(""6*,,T2H ,KHd1KIT..t4H"$.M:h3MK,,t$C[TS[,O  005D(GZ$-G	8$$r0   c                 P    | j                   g d}t        fd|D              S )N)	)r   r   )r   r"   )r   r#   )r   r$   )r   r%   )r   r&   )r   r'   )r   r   )r   r   c              3   z   K   | ]2  \  }}t        j                  |      j                  |              4 y w)N)r   r*   ).0	ise_paramansible_paramcurrent_objrequested_objs      r.   	<genexpr>z1SxpConnections.requires_update.<locals>.<genexpr>   sB      
 +M %	*M,=,=m,L 
s   8;)r+   any)r,   r^   
obj_paramsr_   s    ` @r.   requires_updatezSxpConnections.requires_update   s1    


  
 /9	
 
 	
r0   c                 j    | j                   j                  dd| j                        j                  }|S )Nr2   create_sxp_connectionsr4   r5   r-   )r(   r>   r+   r?   )r,   rE   s     r.   createzSxpConnections.create   s7    $-??  
 (	 	
 r0   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )Nr   r8   r   r2   update_sxp_connections_by_idrf   r+   r*   rJ   updater)   r(   r>   r?   r,   r   r8   rE   id_s        r.   rl   zSxpConnections.update       __  &""6*))$/33D9COO""43<0$3??  
 (	 	
 r0   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )Nr   r8   ri   r2   delete_sxp_connections_by_idrf   rk   rm   s        r.   deletezSxpConnections.delete   ro   r0   N)__name__
__module____qualname__r/   rJ   rO   rX   rc   rg   rl   rr    r0   r.   r    r    9   s*    
6,%.
.r0   r    c                   0     e Zd Z fdZd Zd fd	Z xZS )ActionModulec                 x    t         st        d      t        t        |   |i | d| _        d| _        d | _        y )NzYansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'F)ANSIBLE_UTILS_IS_INSTALLEDr   superrx   r/   _supports_async_supports_check_mode_result)r,   argskwargs	__class__s      r.   r/   zActionModule.__init__   sC    )#k  	lD*D;F;$$)!r0   c                 *   t        | j                  j                  t        t              dt        t
        t        t        t              | j                  j                        }|j                         \  }}| j                  _        |st        |      y )N)argument_specargspec)required_ifrequired_one_ofmutually_exclusiverequired_together)dataschemaschema_formatschema_conditionalsr8   )r   _taskr   r)   r   r   r   r   r   actionvalidater   )r,   aavvaliderrorss       r.   _check_argspeczActionModule._check_argspec   sr    %m4# $' /#5"3	! ""
 *-&vtzz#F++ r0   c                    d| j                   _        t        t        |   ||      | _        d| j
                  d<   | j                          t        | j                   j                        }t        | j                   j                  |      }| j                   j                  j                  d      }d }|dk(  rh|j                         \  }}|r|j                  |      r|j                         }	| j
                  j                  t        |	             |j                         \  }}
|
}d }|	j                  d      j                  d      }t        |      d	k(  s@|d	   j                  d
      dk(  rV|d	   j                  d
      |d	   j                  d      k(  r-| j
                  j!                  dd        |j#                          n|j%                          n|}|j#                          n|j'                         }|j                         \  }}|}|j)                          nM|dk(  rH|j                         \  }}|r#|j+                          |}|j-                          n|j/                          | j
                  j                  t        |             | j
                  j                  |j1                                | j
                  S )NFchanged)r-   r   r   )ise_update_responseUpdatedFieldsListupdatedFieldr   newValue oldValuer   r   )ise_response)r   diffr{   rx   runr~   r   r	   r   r    r*   rX   rc   rl   r)   lenpopobject_already_presentobject_updatedrg   object_createdrr   object_deletedobject_already_absent	exit_json)r,   tmp	task_varsr(   objr   r?   
obj_existsrT   r   updated_objhas_changedise_create_responsecreated_objr   s                 r.   r   zActionModule.run   s<   

\44S)D"'YDJJOO,TZZ__c2

##G,I%(ZZ\"Z&&x0*-**,'LL''AT(UV03

-Z*H"&K"5"9"9:M"N"R"R&#K K(A-&q>--j9R?'N..z:&q>--j9: (()>E224**,'H..0&)jjl#,/JJL)[&""$h%(ZZ\"Z

#""$))+Dh78CMMO,||r0   )NN)rs   rt   ru   r/   r   r   __classcell__)r   s   @r.   rx   rx      s    ,"7 7r0   rx   N)
__future__r   r   r   r   __metaclass__ansible.plugins.actionr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater   rz   ImportErroransible.errorsr   6ansible_collections.cisco.ise.plugins.plugin_utils.iser	   r
   r   r   =ansible_collections.cisco.ise.plugins.plugin_utils.exceptionsr   r   rl   r)   r   r   r   r   objectr    rx   rv   r0   r.   <module>r      s   A @ -& "& , 
 "#   y9h:OPe$% % E"% U#&!U  h%   PV PfT: Ty  '!&'s   C CC