%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/runners/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/runners/vistara.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZej	e
�Zd�Zd�Z
ed�Zd�Zd�Zd	�ZdS(
u
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


i(tabsolute_importtprint_functiontunicode_literalsNcC@s�dtkrtdnd}|r{|jdd�}|jdd�}|jdd�}|sm|sm|rwtdfStStdfS(u@
    Check to see if master config has the necessary config
    uvistarau	client_idu
client_keyu
client_secretubvistara client_id or client_key or client_secret has not been specified in the Salt master config.udvistara config has not been specificed in the Salt master config. See documentation for this runner.N(t__opts__tNonetgettFalsetTrue(tvistara_configt	client_idt
client_keyt
client_secret((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyt__virtual__$s
cC@s1itddd6tddd6tddd6S(uF
    Return the Vistara configuration read from the master config
    uvistarau	client_idu
client_keyu
client_secret(R(((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyt_get_vistara_configuration8scC@s�t�}|stSt|d|d�}|s4dSdj|�}t||d|�}|scdSt|�}|r�|dkr�dj|�Sg}xR|D]J}|d	}	tj|	�t|	|d|�}
|
s�tS|j	|
�q�W|S(
u�
    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

    u
client_keyu
client_secretu"Vistara access token not availableudnsName:{0}u	client_iduNo devices foundiuKExpected to delete 1 device and found {0}. Set safety_on=False to override.uid(
R
Rt_get_oath2_access_tokentformatt_search_devicestlentlogtdebugt_delete_resourcetappend(tnamet	safety_ontconfigtaccess_tokentquery_stringtdevicestdevice_counttdelete_responsestdevicet	device_idtdelete_response((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyt
delete_deviceCs.	


cC@s�dj|�}i|d6dd6dd6}i|d6}d}dj|�}tjjjd	|d
|d|d|d
t�}|jdd�}	|	s�tStjj	j
|d�}
|
d}|S(Nu
Bearer {0}u
Authorizationuapplication/jsonuContent-TypeuAcceptuqueryStringuGETu8https://api.vistara.io/api/v2/tenants/{0}/devices/searchturltmethodtheader_dicttparamstoptsubodyuresults(RtsalttutilsthttptqueryRRRRtjsontloads(RR	Rt
authstringtheadersR%R#R"tresptrespbodytrespbodydictt
deviceresults((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyRus*

	
c
	C@s�dj|�}i|d6dd6dd6}d}dj||�}tjjjd|d	|d
|dt�}|jdd�}|s�tStjj	j
|d�}	|	S(
Nu
Bearer {0}u
Authorizationuapplication/jsonuContent-TypeuAcceptuDELETEuChttps://api.vistara.io/api/v2/tenants/{0}/rtype/DEVICE/resource/{1}R"R#R$R&ubody(RR'R(R)R*RRRRR+R,(
RR	RR-R.R#R"R/R0R1((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyR�s"
	c	C@s�|r|rtjd�tSd}d}idd6dd6}idd	6|d
6|d6}tjjjd|d
|d|d|dt�}|jdd�}|s�tStjj
j|�d}|S(u8
    Query the vistara API and get an access_token

    uQclient_key and client_secret have not been specified and are required parameters.uPOSTu'https://api.vistara.io/auth/oauth/tokenu!application/x-www-form-urlencodeduContent-Typeuapplication/jsonuAcceptuclient_credentialsu
grant_typeu	client_idu
client_secretR"R#R$R%R&ubodyuaccess_tokenN(RterrorRR'R(R)R*RRRR+R,(	R
RR#R"R.R%R/R0R((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyR�s0

	(t__doc__t
__future__RRRtloggingtsalt.outputR'tsalt.utils.httpt	getLoggert__name__RRR
RR!RRR(((s8/usr/lib/python2.7/site-packages/salt/runners/vistara.pyt<module>s		2	#	

Zerion Mini Shell 1.0