%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z
ddlZ
ddlZ
ddl
Z
ddlZ
ddlZ
ddlZ
ddlmZyCddlZeejj�ed�kr�ed��neZWneefk
reZnXddlmZdZej�Z d	�Z!d
d�Z"d�Z#d
�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+dS(u�
The backend for serving files from the Azure blob storage service.

.. versionadded:: 2015.8.0

To enable, add ``azurefs`` to the :conf_master:`fileserver_backend` option in
the Master config file.

.. code-block:: yaml

    fileserver_backend:
      - azurefs

Starting in Salt 2018.3.0, this fileserver requires the standalone Azure
Storage SDK for Python. Theoretically any version >= v0.20.0 should work, but
it was developed against the v0.33.0 version.

Each storage container will be mapped to an environment. By default, containers
will be mapped to the ``base`` environment. You can override this behavior with
the ``saltenv`` configuration option. You can have an unlimited number of
storage containers, and can have a storage container serve multiple
environments, or have multiple storage containers mapped to the same
environment. Normal first-found rules apply, and storage containers are
searched in the order they are defined.

You must have either an account_key or a sas_token defined for each container,
if it is private. If you use a sas_token, it must have READ and LIST
permissions.

.. code-block:: yaml

    azurefs:
      - account_name: my_storage
        account_key: 'fNH9cRp0+qVIVYZ+5rnZAhHc9ycOUcJnHtzpfOr0W0sxrtL2KVLuMe1xDfLwmfed+JJInZaEdWVCPHD4d/oqeA=='
        container_name: my_container
      - account_name: my_storage
        sas_token: 'ss=b&sp=&sv=2015-07-08&sig=cohxXabx8FQdXsSEHyUXMjsSfNH2tZ2OB97Ou44pkRE%3D&srt=co&se=2017-04-18T21%3A38%3A01Z'
        container_name: my_dev_container
        saltenv: dev
      - account_name: my_storage
        container_name: my_public_container

.. note::

    Do not include the leading ? for sas_token if generated from the web
i(tabsolute_importtprint_functiontunicode_literalsN(tLooseVersionu0.20.0u+azure.storage.__version__ must be >= 0.20.0(tsixuazurefscC@s?ttdkrtStstSdtkr.tSt�s;tStS(uQ
    Only load if defined in fileserver_backend and azure.storage is present
    ufileserver_backenduazurefs(t__virtualname__t__opts__tFalset	HAS_AZUREt_validate_configtTrue(((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyt__virtual__Ss	ubasecK@s�idd6dd6}x�tjdg�D]�}|jdd�|krKq'ntjjt|�|�}tjj|�r'tjj	t|�r'||d<||d<yt
tj|��|d<Wntk
r�nX|Sq'W|S(u6
    Search the environment for the relative path
    uupathureluazurefsusaltenvubaseustat(
Rtgettostpathtjoint_get_container_pathtisfiletsaltt
fileservertis_file_ignoredtlisttstatt	Exception(Rtsaltenvtkwargstfndt	containertfull((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyt	find_filefs 






cC@sLg}x3tjdg�D]}|j|jdd��qWtt|��S(u_
    Each container configuration can have an environment setting, or defaults
    to base
    uazurefsusaltenvubase(RRtappendRtset(tsaltenvsR((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pytenvs�sc
@s[idd6dd6}d}t�fd�|D��s\tjdd	j|j����|S|dsj|S|d
|d<�jdd�}tjj	|d�}t
jjj
|d���}|j�d�|jtd
�}|rtjrt
jjj|�r|jt�}n|rG|rGt
jjj||�}||d<n||d<WdQX|S(u?
    Return a chunk from a file based on the data received
    uudataudestupathulocusaltenvc3@s|]}|�kVqdS(N((t.0tx(tload(s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pys	<genexpr>�su<Not all of the required keys present in payload. Missing: %su, urelugzipurbufile_buffer_sizeN(upathulocusaltenv(talltlogtdebugRt
differenceRtNoneR
RtnormpathRtutilstfilestfopentseektreadRRtPY3t	is_binarytdecodet__salt_system_encoding__t	gzip_utiltcompress(R$Rtrettrequired_load_keystgziptfpathtfp_tdata((R$s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyt
serve_file�s.


%
c	C@sPxItdD]=}t|�}yUtjj|�sBtj|�n/tjj|�sqtj|�tj|�nWn#t	k
r�}t
jd�qnXt|�}|d}y|j
|�}Wn#t	k
r�}t
jd�qnXg|D]}|j^q�}t|�}x�tjjj|�D]�\}	}
}x�|D]{}tjj|	|�}
tjj|
|�}||kr;tjj|
d|
�ytj|
�Wq�t	k
r�q�Xq;q;W|
r%|r%tj|	�q%q%Wxy|D]q}tjj||j�}
t}tjj|
�rj|jjj}tjtjjj|
d�j d��}||krpt!}qpnt!}|r�tjjtjj"|
��s�tjtjj"|
��n|
d}tjj||
�tjj#j$|d��Wd	QXy|j%||j|
�Wn#t	k
r+}t
jd
�q�nXytj|�WqTt	k
rPqTXq�q�W|d}|d}tjj||�tjj#j$|d��Wd	QXtjj#j$|d��}tjj&j'||�Wd	QXytj|�Wnt	k
r�nXy-tjjtddd
�}tj|�Wqt	k
rGt
jd�qXqWd	S(u"
    Update caches of the storage containers.

    Compares the md5 of the files on disk to the md5 of the blobs in the
    container, and only updates if necessary.

    Also processes deletions by walking the container caches and comparing
    with the list of blobs in the container
    uazurefsu3Error occurred creating cache directory for azurefsucontainer_nameu-Error occurred fetching blob list for azurefsu.lkumd5uhexuwNu)Error occurred fetching blob from azurefsu.listucachediruhashesu;Problem occurred trying to invalidate hash cach for azurefs((RRR
RtexiststmakedirstisdirtshutiltrmtreeRR&t	exceptiont_get_container_servicet
list_blobstnameRRR+tos_walkRtrelpathRt	wait_locktunlinkRt
propertiestcontent_settingstcontent_md5tbase64t	b64encodet	hashutilstget_hashR2R
tdirnameR,R-tget_blob_to_pathtjsontdump(RRtexctblob_serviceREt	blob_listtblobt
blob_namestblob_settroottdirsR,tftfnameRGtupdatet
source_md5t	local_md5tlk_fntcontainer_listR:t
hash_cachedir((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyR_�s�




%


*






c@s�t�fd�dD��s dSitdd6}|d}|d}tjjtddd	�}tjjj|�dd
j|td��}tjj	|�sAtjj
tjj|��s�tjtjj|��ntjj
j|td�|d<tjjj|d��'}|jtjjj|d��Wd
QX|Stjjj|d��&}tjjj|j��|d<Wd
QX|Sd
S(uL
    Return a file hash based on the hash type set in the master config
    c3@s|]}|�kVqdS(N((R"R#(R$(s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pys	<genexpr>supathusaltenvuu	hash_typeurelucachediruazurefsuhashesu{0}.hash.{1}uhsumuw+Nurb(upathusaltenv(uN(R%R)RR
RRRR+tformatRR=RQR>RORPR,R-twritetstringutilstto_strt
to_unicodeR/(R$RR6RGRRdthashdestR:((R$s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyt	file_hashs(

	 &%c	C@s�t�}y�x�tdD]�}|jdd�|dkr?qnt|�d}|d}tjj||d�tjj	|�s�qntj
jj|d��)}|j
ttj
jj|���WdQXqWWn tk
r�}tjd	�nXt|�S(
u?
    Return a list of all files in a specified environment
    uazurefsusaltenvubaseu.listu.lkiurNu�azurefs: an error ocurred retrieving file lists. It should be resolved next time the fileserver updates. Please do not manually modify the azurefs cache directory.(RRRRRRRHR
RR=R+R,R-R_RSR$RR&terrorR(R$R6RRctlkR:RU((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyt	file_list.s	
0cC@skt�}t|�}xI|D]A}|}x2|r\tjj|�}|r+|j|�q+q+WqWt|�S(uE
    Return a list of all directories in a specified environment
    (RRnR
RRQtaddR(R$R6R,R]RQ((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pytdir_listFs	
	cC@setjjtdd�}dj|jdd�|jdd�|jdd��}tjj||�S(	u�
    Get the cache path for the container in question

    Cache paths are generate by combining the account name, container name,
    and saltenv, separated by underscores
    ucachediruazurefsu{0}_{1}_{2}uaccount_nameuucontainer_nameusaltenvubase(R
RRRReR(RR[t
container_dir((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyRUs
cC@s�d|kr/tjj|dd|d�}nEd|kr^tjj|dd|d�}ntjj|d�}|j�}|S(u�
    Get the azure block blob service for the container in question

    Try account_key, sas_token, and no auth in that order
    uaccount_keyuaccount_nametaccount_keyu	sas_tokent	sas_token(tazuretstoragetCloudStorageAccounttcreate_block_blob_service(RtaccountRV((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyRCcs##cC@s�ttdt�s$tjd�tSxatdD]U}t|t�sXtjd|�tSd|kspd|kr/tjd|�tSq/WtS(uF
    Validate azurefs config, return False if it doesn't validate
    uazurefsu?azurefs configuration is not formed as a list, skipping azurefsudOne or more entries in the azurefs configuration list are not formed as a dict. Skipping azurefs: %suaccount_nameucontainer_nameu\An azurefs container configuration is missing either an account_name or a container_name: %s(t
isinstanceRRR&RlRtdictR
(R((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyR	ss
(,t__doc__t
__future__RRRRMtloggingR
R@tsalt.fileserverRtsalt.utils.filestsalt.utils.gzip_utiltsalt.utils.hashutilstsalt.utils.jsontsalt.utils.pathtsalt.utils.stringutilstsalt.utils.versionsRt
azure.storageRtRut__version__tImportErrorR
RtAttributeErrorRtsalt.extRRt	getLoggerR&RRR!R<R_RkRnRpRRCR	(((s;/usr/lib/python2.7/site-packages/salt/fileserver/azurefs.pyt<module>/sD

	"			a					

Zerion Mini Shell 1.0