
    Vhq              	       @   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
g       ed	       ed	                   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)typedefaultchoices)r   )statehostNamenadIpr   r   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)IpsecEnablec                 r    || _         t        |j                  d      |j                  d            | _        y )Nr   r   )	host_namenad_ip)isedictget
new_object)selfparamsr   s      i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/ise/plugins/action/ipsec_enable.py__init__zIpsecEnable.__init__3   s-    jj,::g&
    c                     d }| j                   j                  dd      j                  j                  dg       }t	        |d|      }|S )Nnative_ipsec )familyfunctionresponsename)r   execr)   r   r   )r   r*   resultitemss       r!   get_object_by_namezIpsecEnable.get_object_by_name:   sH    ^bAJJNN
 !5r#   c                    	 | j                   j                  ddd|id      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)
Nr%   get_ipsec_nodeidF)r'   r(   r    handle_func_exceptionr)   a'  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   r+   r)   	TypeErrorAttributeError	fail_jsonformat	Exception)r   r1   r,   es       r!   get_object_by_idzIpsecEnable.get_object_by_idC   s    	XX]]%)bz&+	 # 
 hz#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 )NFr1   r*   z9The 'id' and 'name' params don't refer to the same object)r   r   r;   
isinstancer   r.   r   )r   prev_obj	id_existsname_existso_idr*   _id	it_existss           r!   existszIpsecEnable.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$$r#   c                 P    | j                   ddg}t        fd|D              S )N)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>z.IpsecEnable.requires_update.<locals>.<genexpr>y   sB      
 +M %	*M,=,=m,L 
s   8;)r   any)r   rJ   
obj_paramsrK   s    ` @r!   requires_updatezIpsecEnable.requires_updatep   s9     &

  
 /9	
 
 	
r#   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )Nr1   r*   )r1   r%   enable_ipsec_connection)r'   r(   r    )r   r   r.   updater   r   r+   r)   )r   r1   r*   r,   id_s        r!   rR   zIpsecEnable.update   s    __  &""6*))$/33D9COO""43<0!.??  
 (	 	
 r#   N)	__name__
__module____qualname__r"   r.   r;   rD   rO   rR    r#   r!   r   r   2   s     
,%.
 r#   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   superrY   r"   _supports_async_supports_check_mode_result)r   argskwargs	__class__s      r!   r"   zActionModule.__init__   sC    )#k  	lD*D;F;$$)!r#   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_conditionalsr*   )r   _taskr`   r   rd   rf   rg   rh   ri   actionvalidater   )r   aavvaliderrorss       r!   _check_argspeczActionModule._check_argspec   sr    %m4# $' /#5"3	! ""
 *-&vtzz#F++ r#   c                 l   d| j                   _        t        t        |   ||      | _        d| j
                  d<   | j                          t        | j                   j                        }t        | j                   j                  |      }| j                   j                  j                  d      }d }|dk(  r|j                         \  }}|r|j                  |      r[|j                         }	| j
                  j                  t        |	             |j                         \  }}
|
}|j                          n$|}|j!                          n|j#                  d       | j
                  j                  t        |             | j
                  j                  |j%                                | j
                  S )	NFchanged)r    r   r   )ise_update_responsez.Object does not exists, plugin only has update)ise_response)rn   diffr\   rY   runr_   rt   r	   r`   r   r   rD   rO   rR   r   object_updatedobject_already_presentr7   	exit_json)r   tmp	task_varsr   objr   r)   
obj_existsr>   rw   updated_objrb   s              r!   rz   zActionModule.run   sE   

\44S)D"'YDJJOO,$**//3/

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

-Z*H&&('H..0NODh78CMMO,||r#   )NN)rT   rU   rV   r"   rt   rz   __classcell__)rb   s   @r!   rY   rY      s    ," r#   rY   N)
__future__r   r   r   r   __metaclass__ansible.plugins.actionr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater   r[   ImportErroransible.errorsr   6ansible_collections.cisco.ise.plugins.plugin_utils.iser	   r
   r   r   =ansible_collections.cisco.ise.plugins.plugin_utils.exceptionsr   rd   rR   r   rf   rg   rh   ri   objectr   rY   rW   r#   r!   <module>r      s    A @ -& "& , 
 "#   y9+F5! i*g.5   Z& Zz:: :  '!&'s   B BB