HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/__pycache__/vistara.cpython-310.pyc
o

�N�gK�@s\dZddlZddlZddlZe�e�Zdd�Zdd�Z	ddd	�Z
d
d�Zdd
�Zdd�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


�NcCsTdtvrtdnd}|r(|�dd�}|�dd�}|�dd�}|r$|r$|s&dSdSdS)	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_configrrr�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/vistara.py�__virtual__!sr
cCs$tddtddtddd�S)zF
    Return the Vistara configuration read from the master config
    rrrr)rrr)rrrrr	�_get_vistara_configuration;s


�rTcCs�t�}|sdSt|d|d�}|sdSd|��}t||d|�}|s%dSt|�}|r4|dkr4d	�|�Sg}|D]}|d
}	t�|	�t|	|d|�}
|
sPdS|�|
�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

    Frrz"Vistara access token not availablezdnsName:rzNo 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_stringZdevicesZdevice_countZdelete_responsesZdevice�	device_idZdelete_responserrr	�
delete_deviceFs4�
�
rcCsxd|��}|ddd�}d|i}d}d|�d�}tjjj||||td�}|�d	d�}	|	s-d
Stjj�|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�queryrr�json�loads)rrr�
authstring�headersr$r"r!�resp�respbody�respbodydictZ
deviceresultsrrr	r|s"
�
�rc
Csfd|��}|ddd�}d}d�||�}tjjj|||td�}|�dd�}|s(dStjj�|d�}	|	S)	NrrrZDELETEzAhttps://api.vistara.io/api/v2/tenants/{}/rtype/DEVICE/resource/{})r!r"r#r%r&F)	rr(r)r*r+rrr,r-)
rrrr.r/r"r!r0r1r2rrr	r�s"
���rc	Csv|s|st�d�dSd}d}ddd�}d||d	�}tjjj||||td
�}|�dd�}|s0dStjj�	|�d
}|S)z8
    Query the vistara API and get an access_token

    zQclient_key and client_secret have not been specified and are required parameters.F�POSTz'https://api.vistara.io/auth/oauth/tokenz!application/x-www-form-urlencodedr)rrZclient_credentials)Z
grant_typerrr r&Nr)
r�errorr(r)r*r+rrr,r-)	rrr"r!r/r$r0r1rrrr	r�s,���
�r)T)�__doc__�loggingZsalt.outputr(Zsalt.utils.http�	getLogger�__name__rr
rrrrrrrrr	�<module>s

6