File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/__pycache__/vistara.cpython-310.pyc
o
�N�gK � @ s\ d Z ddlZddlZddlZe�e�Zdd� Zdd� Z ddd �Z
d
d� Zdd
� Zdd� Z
dS )a
Vistara Runner
Runner to interact with the Vistara (http://www.vistarait.com/) REST API
:codeauthor: Brad Thurber <brad.thurber@gmail.com>
To use this runner, the Vistara client_id and Vistara oauth2 client_key
and client_secret must be set in the master config.
For example ``/etc/salt/master.d/_vistara.conf``:
.. code-block:: yaml
vistara:
client_id: client_012345
client_key: N0tReallyaR3alKeyButShouldB12345
client_secret: ThisI5AreallyLongsecretKeyIwonderwhyTheyMakethemSoBigTheseDays00
� Nc C sT dt v rt d nd} | r(| �dd�}| �dd�}| �dd�}|r$|r$|s&dS dS dS ) z@
Check to see if master config has the necessary config
�vistaraN� client_id�
client_key�
client_secret)Fzbvistara client_id or client_key or client_secret has not been specified in the Salt master config.T)Fzdvistara config has not been specificed in the Salt master config. See documentation for this runner.)�__opts__�get)Zvistara_configr r r � r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/vistara.py�__virtual__! s r
c C s$ t d d t d d t d d d�S )zF
Return the Vistara configuration read from the master config
r r r r )r r r )r r r r r �_get_vistara_configuration; s
�r Tc C s� t � }|sdS t|d |d �}|sdS d| � �}t||d |�}|s%dS t|�}|r4|dkr4d �|�S g }|D ]}|d
} t�| � t| |d |�}
|
sP dS |�|
� q8|S )a�
Deletes a device from Vistara based on DNS name or partial name. By default,
delete_device will only perform the delete if a single host is returned. Set
safety_on=False to delete all matches (up to default API search page size)
CLI Example:
.. code-block:: bash
salt-run vistara.delete_device 'hostname-101.mycompany.com'
salt-run vistara.delete_device 'hostname-101'
salt-run vistara.delete_device 'hostname-1' safety_on=False
Fr r z"Vistara access token not availablezdnsName:r zNo devices found� zJExpected to delete 1 device and found {}. Set safety_on=False to override.�id) r �_get_oath2_access_token�_search_devices�len�format�log�debug�_delete_resource�append)�nameZ safety_onZconfig�access_token�query_stringZdevicesZdevice_countZdelete_responsesZdevice� device_idZdelete_responser r r �
delete_deviceF s4 �
�
r c C sx d|� �}|ddd�}d| i}d}d|� d�}t jjj||||td�}|�d d �} | s-d
S t jj�|d �}
|
d }|S )N�Bearer �application/json�Z
Authorization�Content-Type�AcceptZqueryStringZGETz&https://api.vistara.io/api/v2/tenants/z/devices/search��url�method�header_dict�params�opts�bodyF�results)�salt�utils�http�queryr r �json�loads)r r r �
authstring�headersr$ r"