
    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
g       ed	       ed	       ed       ed       ed       ed	       ed	       ed	       ed       ed	       ed	                   dd
g d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)MERAKImeraki_argument_specmeraki_compare_equality2get_dict_result)InconsistentParametersstrpresent)typedefaultchoices)r   floatboollist)stateaddressfloorPlanIdlatlngmoveMapMarkernamenotesswitchProfileIdtagsserialorganizationIdr   )r   r!   r    c                   F    e Zd Zd ZddZddZd Zd Zd Zd Z	d	 Z
d
 Zy)Devicesc                    || _         t        |j                  d      |j                  d      |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    r!   )r   r   r   r   r   r   r   r   r   r    organization_id)merakidictget
new_object)selfparamsr&   s      g/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/meraki/plugins/action/devices.py__init__zDevices.__init__9   s    JJy)

=1

5!

5! **_5F#**W%"JJ'89F#::h'"JJ'78
    Nc                    i }| j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   d|d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d	      | j                   j                  d
      ;| j                   j                  d	      xs | j                   j                  d
      |d	<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   |xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   |S )NperPageper_pagetotal_pagesstartingAfterstarting_afterendingBeforeending_beforeconfigurationUpdatedAfterconfiguration_updated_after
networkIdsnetwork_idsproductTypesproduct_typesr   tagsFilterTypetags_filter_typer   macr    modelmacsserialssensorMetricssensor_metricssensorAlertProfileIdssensor_alert_profile_idsmodelsr!   r%   r)   r(   r*   r   idnew_object_paramss       r,   get_all_paramszDevices.get_all_paramsI   s   ??y)59L9LZ9X9d+/??+>+>y+I ,0##J/ i(+--(??/;t?R?RSc?d?p151D1D_1U 26##$45 o.??~.:doo>Q>QRa>b>n040C0CN0S 15##O4 n-??:;G4??K^K^_|K}  LJ=A__=P=PQl=m >C##$AB 9:??|,8DOO<O<OP]<^<j.2oo.A.A,.O /3##M2 l+??~.:doo>Q>QRa>b>n040C0CN0S 15##O4 n-??v&2doo6I6I&6Q6](,(;(;F(Cf%??/0<@S@STf@g@s26//2E2EFV2W 38##$67 ./$($GDOO,?,?,G&!??u%1T__5H5H5O5['+':':5'Ae$??x(48K8KH8U8a*.//*=*=h*Gh'??w'3t7J7J77S7_)-)<)<W)Eg&??v&2doo6I6I&6Q6](,(;(;F(Cf%??y)59L9LY9W9c+/??+>+>y+Ii(??/;t?R?RSc?d?p151D1D_1U 26##$45 o.??67CtGZGZ[uGv  HC9=9L9LMd9e :@##$>? 56??x(48K8KH8U8a*.//*=*=h*Gh'??/0<@S@STe@f@r26//2E2EFV2W 37##$56 ./  r.   c                     i }| j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   |S )Nr    rI   rJ   s       r,   get_params_by_idzDevices.get_params_by_id{   sQ    ??x(48K8KH8U8a*.//*=*=h*Gh'  r.   c                    i }| j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d	      | j                   j                  d	      ;| j                   j                  d	      xs | j                   j                  d	      |d	<   | j                   j                  d
      | j                   j                  d      ;| j                   j                  d
      xs | j                   j                  d      |d
<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   | j                   j                  d      | j                   j                  d      ;| j                   j                  d      xs | j                   j                  d      |d<   |S )Nr   r   floor_plan_idr   r   r   move_map_markerr   r   r   switch_profile_idr   r    rI   )r*   rL   s     r,   update_by_id_paramszDevices.update_by_id_params   s   ??y)59L9LY9W9c+/??+>+>y+I ,/##I. i(??}-9T__=P=PQ`=a=m/3/B/B=/Q 05##O4 m,??u%1T__5H5H5O5['+':':5'A (+##E* e$??u%1T__5H5H5O5['+':':5'A (+##E* e$??/;t?R?RSd?e?q151D1D2!o.??v&2doo6I6I&6Q6](,(;(;F(C ),##F+ f%??w'3t7J7J77S7_)-)<)<W)E *-##G, g&??01=ATATUhAiAu37??3F3FGX3Y 49##$78 /0??v&2doo6I6I&6Q6](,(;(;F(C ),##F+ f%??x(48K8KH8U8a*.//*=*=h*G +.##H- h'  r.   c                    d }	 | j                   j                  dd| j                  |            }t        |t              rd|v r|j                  d      }t        |d|      }||}|S # t        $ r}t        d|       d }Y d }~|S d }~ww xY w)NorganizationsgetOrganizationDevices)r   familyfunctionr+   responser   Error: )	r&   exec_merakirM   
isinstancer'   r(   r   	Exceptionprint)r*   r   resultitemses        r,   get_object_by_namezDevices.get_object_by_name   s    	KK++&1***5 , E
 %&&!IIj1E$UFD9F~   	)QF	s   A$A* *	B3BBc                     d }	 | j                   j                  dd| j                               }t        |t              rd|v r|j                  d      }|}|S # t        $ r}t        d|       d }Y d }~|S d }~ww xY w)Ndevices	getDevicerX   r[   r\   )r&   r]   rO   r^   r'   r(   r_   r`   )r*   rK   ra   rb   rc   s        r,   get_object_by_idzDevices.get_object_by_id   s    	KK++ $,,. , E
 %&&!IIj1EF   	)QF	s   AA 	A;"A66A;c                    d }d}d}| j                   j                  d      }|xs8 | j                   j                  d      xs | j                   j                  d      }| j                   j                  d      }| j                   j                  d      xs | j                   j                  d      }t        |       t        |       |r'| j                  |      }|d uxr t	        |t
              }|s+|r)|r'| j                  |      }|d uxr t	        |t
              }|r|j                  d      }|xs |j                  d      }|r|r||k7  rt        d      |rJ| j                   j                  t        |             | j                   j                  t        |	             |r| j                  |      }|d uxr t	        |t
              }||fS )
NFrK   r    r   r!   r%   z9The 'id' and 'name' params don't refer to the same object)rK   r    )	r)   r(   r`   rh   r^   r'   rd   r   update)	r*   prev_obj	id_existsname_existso_idr   orgID_id	it_existss	            r,   existszDevices.exists   s   	""4( 7t** 7,,X6 	""6*##$45 9L9L:de,,T2H ,KHd1KITe..t4H"$.M:h3MK,,t$C/h/C[TS[,OQ Q&&ts|4&&t3'78005D(GZ$-G	8$$r.   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   )r    r    )r!   r!   c              3   z   K   | ]2  \  }}t        j                  |      j                  |              4 y w)N)r   r(   ).0meraki_paramansible_paramcurrent_objrequested_objs      r,   	<genexpr>z*Devices.requires_update.<locals>.<genexpr>   sD      D4m 00M0=0A0A-0PR R Ds   8;)r)   any)r*   ry   
obj_paramsrz   s    ` @r,   requires_updatezDevices.requires_update   s3    

  D8BD D 	Dr.   c                    | j                   j                  d      }|xs | j                   j                  d      }| j                   j                  d      }d }|sb| j                  |      }d }|r&|j                  d      }|xs |j                  d      }|r%| j                   j                  t	        |             | j
                  j                  dd| j                         d      }|S )	NrK   r    r   rj   rf   updateDeviceT)rY   rZ   r+   op_modifies)r)   r(   rd   rk   r'   r&   r]   rT   )r*   rK   r   ra   prev_obj_nameid_s         r,   rk   zDevices.update   s    __  &04??&&x0""6* 33D9MC#''-8]..x8&&t3'78((#++-	 ) 
 r.   NN)__name__
__module____qualname__r-   rM   rO   rT   rd   rh   rs   r~   rk    r.   r,   r#   r#   8   s3    
 0!d! !D("%@D,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   superr   r-   _supports_async_supports_check_mode_result)r*   argskwargs	__class__s      r,   r-   zActionModule.__init__  sC    )#km m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'   r   r   r   r   r   actionvalidater   )r*   aavvaliderrorss       r,   _check_argspeczActionModule._check_argspec  sr    %m4# $' /#5"3	! ""
 *-&vtzz#F++ r.   c                    d| j                   _        t        t        |   ||      | _        d| j
                  d<   | j                          t        | j                   j                        }t        | j                   j                  |      }| j                   j                  j                  d      }d }|dk(  rk|j                         \  }}|rE|j                  |      r!|j                         }|j                          n$|}|j                          n|j!                  d       | j
                  j                  t#        |             | j
                  j                  |j%                                | j
                  S )NFchangedr   r   z.Object does not exists, plugin only has update)meraki_response)r   diffr   r   runr   r   r	   r   r#   r(   rs   r~   rk   object_updatedobject_already_present	fail_jsonr'   	exit_json)
r*   tmp	task_varsr&   objr   r[   
obj_existsrl   r   s
            r,   r   zActionModule.run0  s!   

\44S)D"'Y

(djjoov.

##G,I%(ZZ\"Z&&x0"zz|H))+'H113  DF 	D:;F,,./||r.   r   )r   r   r   r-   r   r   __classcell__)r   s   @r,   r   r     s    ," r.   r   N)
__future__r   r   r   r   __metaclass__ansible.plugins.actionr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater   r   ImportErroransible.errorsr   <ansible_collections.cisco.meraki.plugins.plugin_utils.merakir	   r
   r   r   @ansible_collections.cisco.meraki.plugins.plugin_utils.exceptionsr   r   rk   r'   r   r   r   r   objectr#   r   r   r.   r,   <module>r      s   C B -& "& , 
 %&   T
E9yk
Be% ''F#	5	
E
e$	6	UU#   i=tD   Yf Yx7: 7K  '!&'s   C C%$C%