
    Vh}B                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
mZmZ d d
lmZmZ d Zd Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionz1.1
deprecated	community)metadata_versionstatussupported_byad
  
---
module: meraki_device
short_description: Manage devices in the Meraki cloud
description:
- Visibility into devices associated to a Meraki environment.
notes:
- This module does not support claiming of devices or licenses into a Meraki organization.
- More information about the Meraki API can be found at U(https://dashboard.meraki.com/api_docs).
- Some of the options are likely only used for developers within Meraki.
deprecated:
  removed_in: '3.0.0'
  why: Updated modules released with increased functionality
  alternative: cisco.meraki.networks_devices_claim, cisco.meraki.networks_devices_remove and cisco.meraki.networks
options:
    state:
        description:
        - Query an organization.
        choices: [absent, present, query]
        default: query
        type: str
    net_name:
        description:
        - Name of a network.
        aliases: [network]
        type: str
    net_id:
        description:
        - ID of a network.
        type: str
    serial:
        description:
        - Serial number of a device to query.
        type: str
    hostname:
        description:
        - Hostname of network device to search for.
        aliases: [name]
        type: str
    model:
        description:
        - Model of network device to search for.
        type: str
    tags:
        description:
        - Space delimited list of tags to assign to device.
        type: list
        elements: str
    lat:
        description:
        - Latitude of device's geographic location.
        - Use negative number for southern hemisphere.
        aliases: [latitude]
        type: float
    lng:
        description:
        - Longitude of device's geographic location.
        - Use negative number for western hemisphere.
        aliases: [longitude]
        type: float
    address:
        description:
        - Postal address of device's location.
        type: str
    move_map_marker:
        description:
        - Whether or not to set the latitude and longitude of a device based on the new address.
        - Only applies when C(lat) and C(lng) are not specified.
        type: bool
    lldp_cdp_timespan:
        description:
        - Timespan, in seconds, used to query LLDP and CDP information.
        - Must be less than 1 month.
        type: int
    note:
        description:
        - Informational notes about a device.
        - Limited to 255 characters.
        type: str
    query:
        description:
        - Specifies what information should be queried.
        type: str
        choices: [lldp_cdp, uplink]


author:
- Kevin Breit (@kbreit)
extends_documentation_fragment: cisco.meraki.meraki
a  
- name: Query all devices in an organization.
  meraki_device:
    auth_key: abc12345
    org_name: YourOrg
    state: query
  delegate_to: localhost

- name: Query all devices in a network.
  meraki_device:
    auth_key: abc12345
    org_name: YourOrg
    net_name: YourNet
    state: query
  delegate_to: localhost

- name: Query a device by serial number.
  meraki_device:
    auth_key: abc12345
    org_name: YourOrg
    net_name: YourNet
    serial: ABC-123
    state: query
  delegate_to: localhost

- name: Lookup uplink information about a device.
  meraki_device:
    auth_key: abc12345
    org_name: YourOrg
    net_name: YourNet
    serial_uplink: ABC-123
    state: query
  delegate_to: localhost

- name: Lookup LLDP and CDP information about devices connected to specified device.
  meraki_device:
    auth_key: abc12345
    org_name: YourOrg
    net_name: YourNet
    serial_lldp_cdp: ABC-123
    state: query
  delegate_to: localhost

- name: Lookup a device by hostname.
  meraki_device:
    auth_key: abc12345
    org_name: YourOrg
    net_name: YourNet
    hostname: main-switch
    state: query
  delegate_to: localhost

- name: Query all devices of a specific model.
  meraki_device:
    auth_key: abc123
    org_name: YourOrg
    net_name: YourNet
    model: MR26
    state: query
  delegate_to: localhost

- name: Update information about a device.
  meraki_device:
    auth_key: abc123
    org_name: YourOrg
    net_name: YourNet
    state: present
    serial: '{{ serial }}'
    name: mr26
    address: 1060 W. Addison St., Chicago, IL
    lat: 41.948038
    lng: -87.65568
    tags: recently-added
  delegate_to: localhost

- name: Claim a device into a network.
  meraki_device:
    auth_key: abc123
    org_name: YourOrg
    net_name: YourNet
    serial: ABC-123
    state: present
  delegate_to: localhost

- name: Remove a device from a network.
  meraki_device:
    auth_key: abc123
    org_name: YourOrg
    net_name: YourNet
    serial: ABC-123
    state: absent
  delegate_to: localhost
zc
response:
    description: Data returned from Meraki dashboard.
    type: dict
    returned: info
)AnsibleModulejson)MerakiModulemeraki_argument_specc                 &    |D ]  }|d   |k(  s y y)zJ Parse a list of devices for a serial and return True if it's in the list serialTF )merakir   datadevices       n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/meraki/plugins/modules/meraki_device.pyis_device_validr      s&     (v%     c                     | j                  d|      }| j                  |d      }| j                  dk7  r| j                  d       |S )z$ Get all devices in an organization get_all_orgorg_idGETmethod   z9Failed to query all devices belonging to the organizationmsgconstruct_pathrequestr	   	fail_json)r   r   pathresponses       r   get_org_devicesr(      sL      v >D~~d5~1H}}XYOr   c                     | j                  d|      }| j                  |d      }| j                  dk7  r| j                  d       |S )z Get all devices in a network get_allnet_idr   r   r   z4Failed to query all devices belonging to the networkr    r"   )r   r,   r&   r'   s       r   get_net_devicesr-      sL      6 :D~~d5~1H}}STOr   c                     i }| d   | d   |d<   | d   | d   |d<   | d   | d   |d<   | d   | d   |d<   | d   | d   |d<   | d   | d   |d<   | d	   | d	   |d
<   |S )z  Create payload based on inputs hostnamenametagslatlngaddressmove_map_markermoveMapMarkernotenotesr   )paramspayloads     r   construct_payloadr;      s    Gj% ,f~! .e} e} i$#I.	 ,#)*;#< f~!!&>Nr   c                     t               } | j                  t        dg dd      t        ddg      t        d      t        d      t        d      t        dd	g      t        d      t        d
dd       t        ddgd       t        ddgd       t        dd       t        dd       t        dd       t        dd ddg             t        | d      }t	        |d      }|j
                  d   3|j
                  d   dk(  r!|j
                  d   s|j                  d       |j
                  d   r!|j
                  d   r|j                  d       d |j
                  d!<   dd"i}dd#i}dd$i}dd%i}dd&i}dd'i}dd$i}	dd(i}
|j                  d)   j                  |       ||j                  d*<   ||j                  d+<   ||j                  d,<   ||j                  d-<   ||j                  d.<   ||j                  d/<   |	|j                  d0<   |
|j                  d1<   d }|j
                  d2   }||j                  |j
                  d3         }|j                  |4      }d }|j
                  d   s|j
                  d   r1|j
                  d   }| |j                  |j
                  d   |5      }|j
                  d6   dk(  r"|j
                  d   s|j
                  d   rg }|j
                  d7   rX|j                  d+|d7|j
                  d7   i8      }|j                  |d9:      }|j                  |       ||j                  d;<   |j
                  d   dk(  rE|j                  d,|d7|j
                  d7   i8      }|j                  |d9:      |j                  d;<   n|j
                  d   dk(  r|j
                  d   d<kD  r|j                  d=       |j                  d-|d7|j
                  d7   i8      }|d>z   t        |j
                  d         z   }|j                  |j                  |d9:             ||j                  d;<   n|j
                  d?   re|j                  d)|@      }|j                  |d9:      }|D ]8  }	 |d	   |j
                  d?   k(  r |j                  |       ||j                  d;<   : n|j
                  dA   rg|j                  d)|@      }|j                  |d9:      }g }|D ])  }|dA   |j
                  dA   k(  s|j                  |       + ||j                  d;<   n"|j                  d)|@      }|j                  |d9:      }||j                  d;<   n|j                  d*|dBdCiD      }|j                  |d9dEF      }|j
                  d7   r.|D ]'  }|d7   |j
                  d7   k(  s||j                  d;<   ) n||j                  d;<   ns|j
                  d6   dGk(  rg }|t#        ||      }t%        ||j
                  d7   |      du r3d7|j
                  d7   i}|j                  d/|4      }g }|j                  |j                  |dHt'        j(                  |      I             ||j                  d;<   dJ|j                  dK<   nt+        ||      }t%        ||j
                  d7   |      dJu r|j                  d)|@      }t%        ||j
                  d7   |      r`t-        |j
                        }|j                  d+|d7|j
                  d7   i8      }|j                  |d9:      }g dL}|j/                  |||M      rz|j                  d0d7|j
                  d7   iN      }g }|j                  |j                  |dOt'        j(                  |      I             ||j                  d;<   dJ|j                  dK<   n||j                  d;<   nr|j                  d)|@      }|j                  |d9:      }t%        ||j
                  d7   |      du r/|r,dP|j
                  d7   gi}|j                  d.|@      }g }|j                  |j                  |dHt'        j(                  |      I             ||j                  d;<   dJ|j                  dK<   n|j
                  d6   dQk(  rg }|j                  d)|@      }|j                  |d9:      }t%        ||j
                  d7   |      dJu rZd7|j
                  d7   i}|j                  d1|@      }|j                  |dHt'        j(                  |      I      }dJ|j                  dK<    |j0                  dRi |j                   y # t         $ r Y w xY w)SNstr)absentpresentqueryr@   )typechoicesdefaultnetwork)rA   aliases)rA   intr0   list)rA   elementsrC   floatlatitude)rA   rE   rC   	longitude)rA   rC   boollldp_cdpuplink)rA   rC   rB   )statenet_namer,   r   lldp_cdp_timespanr/   modelr1   r2   r3   r4   r5   r7   r@   F)argument_specsupports_check_moder   )functionrQ   zDlldp_cdp_timespan is required when querying LLDP and CDP informationr    rP   r,   z*net_name and net_id are mutually exclusiveallfollow_redirectsz/networks/{net_id}/devicesz/organizations/{org_id}/devicesz/devices/{serial}z/devices/{serial}/lldpCdpz /networks/{net_id}/devices/claimz/organizations/{org_id}/claimz!/networks/{net_id}/devices/remover*   r   
get_deviceget_device_uplinkget_device_lldpcreatebind_orgupdatedeleter   org_namer   )rP   r   rO   r   )r,   customr   r   r   i ' z=LLDP/CDP timespan must be less than a month (2592000 seconds)z
?timespan=r/   r+   rR   perPage1000)r   r9   i  )r   pagination_itemsr?   POST)r   r:   Tchanged)lanIpr   macrR   	networkIdr6   wan1Ipwan2Ip)optional_ignore)r`   PUTserialsr>   r   )r   r]   dictr   r   r9   r%   url_catalog
get_org_idget_nets
get_net_idr#   r$   appendresultr=   KeyErrorr(   r   r   dumpsr-   r;   is_update_required	exit_json)rS   moduler   
query_urlsquery_org_urlsquery_device_urlsquery_device_lldp_urlsclaim_device_urlsbind_org_urlsupdate_device_urlsdelete_device_urlsr:   r   netsr,   r   r&   r$   devicesunitdevice_matchdevice_listcreated_device
query_pathdevice_dataignore_keysupdated_devices                              r   mainr     s	    )*Mt8V`gh"&EI;"G $% 0 $% 0+/U+;"&EF8"D#/"M!wdS!wtT!%5$!?)-64)H"t<#zS[F\]  ( /4F &84F}}W)==!Z/}}01cd}}Z V]]8%<IJ(-FMM$%89J ABN!#67&(CD!#EF>?M"$78"$GH
y!((4(6F}%'8F|$.?F*+,BF()#4Fx %2Fz"#5Fx #5Fx G ]]8$F~""6==#<=??&?)DF}}X&--
";x(>&&j0IPT&UF}}W(==$h(?F}}X&,,\&RZ\b\i\ijr\sQt,u ..e.<g&(.f%==)X5!001DV]egmgtgtu}g~\0  AD-3^^D^-OFMM&)]]7+z9}}%89GC((-l(m!001B6[cekerers{e|Z}0~D,.V]]CV5W1XXDMM&..e."DE,2FMM&)z*,,Yv,F ..e.<# D<6==+DD"MM$/4:FMM&1	 w',,Yv,F ..e.<!% 4Fg&--*@@$++F34 )5f%,,Yv,F ..e.<(/f%((vyZ`Na(bDnnT%$nOG}}X&% 7Fh'6==+BB06f-7 )0f%	w	9	,>)&&9Kvv}}X'>LPUU#V]]8%<=,,Z,G!#%%fnnT&RVR\R\]dRen&fg(6f%+/i()&&9Kvv}}X'>LPTT#229V2L
"66==+BKP/>G!'!6!6|F\dflfsfst|f}[~!6!J"(..E."JK"wK00gWb0c%44XxQWQ^Q^_gQhFi4j)+&--fnnT%Y]YcYcdkYln.mn0>f-37i00;f-#229V2L
$nnZnF"66==+BKPTYY#,v}}X/F.G"H%44Xf4M)+&--fnnT&Z^ZdZdelZmn.no0>f-37i0	w	8	+**9V*D
nnZn>66==#:KHDPx!89G((&(ADnnT&$**WBUnVG'+FMM)$ F%v}}%U $ s   	5e77	ff__main__N)
__future__r   r   r   rA   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r   Kansible_collections.cisco.meraki.plugins.module_utils.network.meraki.merakir   r   r   r(   r-   r;   r   __name__r   r   r   <module>r      sx    A @ n Yv\|
 ; z(n&b zF r   