%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/cp.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZeje�ZdgZd�Z d	�Z!d
�Z"e#e$dd�Z&d�Z'd
�Z(d�Z)de#ddd�Z*d�Z+dde#d�Z,dddd�Z-dde#dd�Z.dd�Z/ddd�Z0dd�Z1de#ddd�Z2dd�Z3d�Z4dd�Z5ddd�Z6ddd�Z7ddd �Z8dd!�Z9dd"�Z:dd#�Z;de$d$�Z<e#de#d%�Z=ddd&�Z>dS('u#
Minion side functions for salt-cp
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(turlparse(tsixu*cC@s-dtkr%tjjt�td<ntdS(u 
    Return the auth object
    uauth(t__context__tsalttcrypttSAutht__opts__(((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt_auth$sc	C@sdtjjtttdtdd|d|�}|j�}|r`t|t�r`|j|�n|S(uC
    Whenever a state run starts, gather the pillar data fresh
    uidusaltenvtpillar_overridet	pillarenv(	Rtpillart
get_pillarR
t
__grains__tcompile_pillart
isinstancetdicttupdate(R
RRtret((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt_gather_pillar-s	
	cC@s%i}xtj|�D]\}}tjj|�tjj|�krbtjj|�rb|}natjj|�r�tjj|tjj|��}n+tjjtjj|��r�|}ndSy<tj	j
j|d��}|j|�WdQXt
||<Wqtk
rt||<qXqW|S(u�
    Used with salt-cp, pass the files dict, and the destination.

    This function receives small fast copy files from the master via salt-cp.
    It does not work via the CLI.
    uDestination unavailableuw+N(Rt	iteritemstostpathtbasenametisdirtjointdirnameRtutilstfilestfopentwritetTruetIOErrortFalse(RtdestRRtdatatfinaltfp_((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytrecv?s"$	$	
c
C@sRdtkrdtd<nd�}|dkr�ytj|�WnNtk
r�}|jtjkr|tjj|�r�dSq�||j	��SnXt
Stj|�}|r�dnd}yt
jjj||�}Wn�ttfk
rl}|jtjkr||j	��Sytjtjj|��Wn&ttfk
rP}	||	j	��SXt
jjj||�}nXz�y,|j|r�t
jjj|�n|�Wn&ttfk
r�}||j	��SX|r#|dk	r#tjd||�ytj||�Wq#tk
r||j	��SXnt
SWdy|j�Wntk
rLnXXdS(	u�
    This function receives files copied to the minion using ``salt-cp`` and is
    not intended to be used directly on the CLI.
    uretcodeicS@sdtd<|S(Niuretcode(R(tmsg((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt_errords
uPath exists and is a fileuabuwbuSetting mode for %s to %sN(RtNoneRtmakedirstOSErrorterrnotEEXISTRtisfilet__str__R"tbase64t	b64decodeRRRR R#tENOENTRR!t	gzip_utilt
uncompresstlogtdebugtchmodtclosetAttributeError(
R%tchunktappendt
compressedtmodeR+texct	open_modetfh_tmakedirs_exc((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytrecv_chunked\sR
	!

cC@sGdjtt��tkrCtjjt�tdjtt��<ndS(u�
    Create a file client and add it to the context.

    Each file client needs to correspond to a unique copy
    of the opts dictionary, therefore it's hashed by the
    id of the __opts__ dict
    ucp.fileclient_{0}N(tformattidR
RRt
fileclienttget_file_client(((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt
_mk_client�scC@st�tdjtt��S(u8
    Return a client, hashed by the list of masters
    ucp.fileclient_{0}(RJRRFRGR
(((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt_client�sc@s��s||fS�tjjjkr=tdj����ni�t�d<d|ksed|kr�|jdtjd��}t	||jd���d<n
t
�d<t�d<t�d<|�d<��fd�}||�}||�}||fS(	u�
    Process markup in the :param:`path` and :param:`dest` variables (NOT the
    files under the paths they ultimately point to) according to the markup
    format provided by :param:`template`.
    u:Attempted to render file paths with unavailable engine {0}usaltu	pillarenvupillarugrainsuoptsusaltenvc@s�tjjj�}tjjj|d��#}|jtjjj|��WdQXtjjj	�|dt
��}tjjj|�|ds�tdj
|d���n|dSdS(u�
        Render :param:`contents` into a literal pathname by writing it to a
        temp file, rendering that file, and returning the result.
        uw+Ntto_struresultu*Failed to render file path with error: {0}udata(RRRtmkstempR R!tstringutilsRLt	templatestTEMPLATE_REGISTRYR"tsafe_rmRRF(tcontentsttmp_path_fnR(R&(tkwargsttemplate(s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt_render�s"	
(RRRORPRRFt__salt__tgetR
Rt
__pillar__R(RR%tsaltenvRUtkwR
RV((RTRUs3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt_render_filenames�s&





ubasecK@s{t|||||�\}}tjjj|�\}}|rH|}nt||�s[dSt�j|||||�SdS(u�
    .. versionchanged:: 2018.3.0
        ``dest`` can now be a directory

    Used to get a single file from the salt master

    CLI Example:

    .. code-block:: bash

        salt '*' cp.get_file salt://path/to/file /minion/dest

    Template rendering can be enabled on both the source and destination file
    names like so:

    .. code-block:: bash

        salt '*' cp.get_file "salt://{{grains.os}}/vimrc" /etc/vimrc template=jinja

    This example would instruct all Salt minions to download the vimrc from a
    directory with the same name as their os grain and copy it to /etc/vimrc

    For larger files, the cp.get_file module also supports gzip compression.
    Because gzip is CPU-intensive, this should only be used in scenarios where
    the compression ratio is very high (e.g. pretty-printed JSON or YAML
    files).

    Use the *gzip* named argument to enable it.  Valid values are 1..9, where 1
    is the lightest compression and 9 the heaviest.  1 uses the least CPU on
    the master (and minion), 9 uses the most.

    There are two ways of defining the fileserver environment (a.k.a.
    ``saltenv``) from which to retrieve the file. One is to use the ``saltenv``
    parameter, and the other is to use a querystring syntax in the ``salt://``
    URL. The below two examples are equivalent:

    .. code-block:: bash

        salt '*' cp.get_file salt://foo/bar.conf /etc/foo/bar.conf saltenv=config
        salt '*' cp.get_file salt://foo/bar.conf?saltenv=config /etc/foo/bar.conf

    .. note::
        It may be necessary to quote the URL when using the querystring method,
        depending on the shell being used to run the command.
    uN(R\RRturlt	split_envt	hash_fileRKtget_file(RR%RZR-RUtgzipRTtsenv((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyR`�s4		cC@s
t�j�S(uy
    List available environments for fileserver

    CLI Example

    .. code-block:: bash

        salt '*' cp.envs
    (RKtenvs(((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRc0s
ujinjacK@s�d|krt|d<nd|kr2t|d<nd|krKt|d<nd|krdt|d<nt�j||||||�S(u
    Render a file as a template before setting it down.
    Warning, order is not the same as in fileclient.cp for
    non breaking old API.

    CLI Example:

    .. code-block:: bash

        salt '*' cp.get_template salt://path/to/template /minion/dest
    usaltupillarugrainsuopts(RWRYRR
RKtget_template(RR%RURZR-RT((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRd=s



	cK@s7t|||||�\}}t�j||||�S(u�
    Used to recursively copy a directory from the salt master

    CLI Example:

    .. code-block:: bash

        salt '*' cp.get_dir salt://path/to/dir/ /minion/dest

    get_dir supports the same template and gzip arguments as get_file.
    (R\RKtget_dir(RR%RZRURaRT((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRe_suc	C@s�t|tj�r6t�j||||d|�}n't�j|d||dtd|�}|s�tjdt	j
jj|�|�n|S(u/
    .. versionchanged:: 2018.3.0
        ``dest`` can now be a directory

    Used to get a single file from a URL.

    path
        A URL to download a file from. Supported URL schemes are: ``salt://``,
        ``http://``, ``https://``, ``ftp://``, ``s3://``, ``swift://`` and
        ``file://`` (local filesystem). If no scheme was specified, this is
        equivalent of using ``file://``.
        If a ``file://`` URL is given, the function just returns absolute path
        to that file on a local filesystem.
        The function returns ``False`` if Salt was unable to fetch a file from
        a ``salt://`` URL.

    dest
        The default behaviour is to write the fetched file to the given
        destination path. If this parameter is omitted or set as empty string
        (``''``), the function places the remote file on the local filesystem
        inside the Minion cache directory and returns the path to that file.

        .. note::

            To simply return the file contents instead, set destination to
            ``None``. This works with ``salt://``, ``http://``, ``https://``
            and ``file://`` URLs. The files fetched by ``http://`` and
            ``https://`` will not be cached.

    saltenv : base
        Salt fileserver envrionment from which to retrieve the file. Ignored if
        ``path`` is not a ``salt://`` URL.

    source_hash
        If ``path`` is an http(s) or ftp URL and the file exists in the
        minion's file cache, this option can be passed to keep the minion from
        re-downloading the file if the cached copy matches the specified hash.

        .. versionadded:: 2018.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' cp.get_url salt://my/file /tmp/this_file_is_mine
        salt '*' cp.get_url http://www.slashdot.org /tmp/index.html
    tsource_hashtno_cacheu(Unable to fetch file %s from saltenv %s.N(
RRtstring_typesRKtget_urlR,R"R8terrorRRR]tredact_http_basic_auth(RR%RZR-Rftresult((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRips0			
cC@slt||�}t|tj�rhy/tjjj|d��}|j�SWdQXWqht	k
rdt
SXn|S(u
    Download a file from a URL to the Minion cache directory and return the
    contents of that file

    Returns ``False`` if Salt was unable to cache a file from a URL.

    CLI Example:

    .. code-block:: bash

        salt '*' cp.get_file_str salt://my/file
    urN(t
cache_fileRRRhRRRR treadR#R$(RRZtfn_R(((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytget_file_str�s

cC@s$tjjj|�}tjjj|�}djd||�}t|�jdk}yD|r�|tkr�tj	j
t|�r�t|Stj|�nWntk
r�nXtjj
j|�\}}|r�|}nt�j||d|�}|s
tjd||�n|r |t|<n|S(	u�
    Used to cache a single file on the Minion

    Returns the location of the new cached file on the Minion

    source_hash
        If ``name`` is an http(s) or ftp URL and the file exists in the
        minion's file cache, this option can be passed to keep the minion from
        re-downloading the file if the cached copy matches the specified hash.

        .. versionadded:: 2018.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' cp.cache_file salt://path/to/file

    There are two ways of defining the fileserver environment (a.k.a.
    ``saltenv``) from which to cache the file. One is to use the ``saltenv``
    parameter, and the other is to use a querystring syntax in the ``salt://``
    URL. The below two examples are equivalent:

    .. code-block:: bash

        salt '*' cp.cache_file salt://foo/bar.conf saltenv=config
        salt '*' cp.cache_file salt://foo/bar.conf?saltenv=config

    If the path being cached is a ``salt://`` URI, and the path does not exist,
    then ``False`` will be returned.

    .. note::
        It may be necessary to quote the URL when using the querystring method,
        depending on the shell being used to run the command.
    u{0}_|-{1}_|-{2}u
cp.cache_fileuhttpuhttpsuftpRfu,Unable to cache file '%s' from saltenv '%s'.(uhttpuhttpsuftp(RRR&tdecodeRFt	_urlparsetschemeRRRR1tpopR<R]R^RKRmR8Rj(RRZRft
contextkeytpath_is_remoteRbRl((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRm�s,$
	

cC@st�j||�S(u�
    Used to gather many files from the Master, the gathered files will be
    saved in the minion cachedir reflective to the paths retrieved from the
    Master

    CLI Example:

    .. code-block:: bash

        salt '*' cp.cache_files salt://pathto/file1,salt://pathto/file1

    There are two ways of defining the fileserver environment (a.k.a.
    ``saltenv``) from which to cache the files. One is to use the ``saltenv``
    parameter, and the other is to use a querystring syntax in the ``salt://``
    URL. The below two examples are equivalent:

    .. code-block:: bash

        salt '*' cp.cache_files salt://foo/bar.conf,salt://foo/baz.conf saltenv=config
        salt '*' cp.cache_files salt://foo/bar.conf?saltenv=config,salt://foo/baz.conf?saltenv=config

    The querystring method is less useful when all files are being cached from
    the same environment, but is a good way of caching files from multiple
    different environments in the same command. For example, the below command
    will cache the first file from the ``config1`` environment, and the second
    one from the ``config2`` environment.

    .. code-block:: bash

        salt '*' cp.cache_files salt://foo/bar.conf?saltenv=config1,salt://foo/bar.conf?saltenv=config2

    .. note::
        It may be necessary to quote the URL when using the querystring method,
        depending on the shell being used to run the command.
    (RKtcache_files(tpathsRZ((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRws$cC@st�j|||||�S(u�
    Download and cache everything under a directory from the master


    include_pat : None
        Glob or regex to narrow down the files cached from the given path. If
        matching with a regex, the regex must be prefixed with ``E@``,
        otherwise the expression will be interpreted as a glob.

        .. versionadded:: 2014.7.0

    exclude_pat : None
        Glob or regex to exclude certain files from being cached from the given
        path. If matching with a regex, the regex must be prefixed with ``E@``,
        otherwise the expression will be interpreted as a glob.

        .. note::

            If used with ``include_pat``, files matching this pattern will be
            excluded from the subset of files defined by ``include_pat``.

        .. versionadded:: 2014.7.0


    CLI Examples:

    .. code-block:: bash

        salt '*' cp.cache_dir salt://path/to/dir
        salt '*' cp.cache_dir salt://path/to/dir include_pat='E@*.py$'
    (RKt	cache_dir(RRZt
include_emptytinclude_pattexclude_pat((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyRy7s!	cC@st�j|�S(u�
    Retrieve all of the files on the master and cache them locally

    CLI Example:

    .. code-block:: bash

        salt '*' cp.cache_master
    (RKtcache_master(RZ((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyR}]s
cC@sktjj|�sdSt|�}|r[t|�}t|�}|d|dkr[|Snt�j|�S(u�
    Cache a local file on the minion in the localfiles cache

    CLI Example:

    .. code-block:: bash

        salt '*' cp.cache_local_file /etc/hosts
    uuhsum(RRtexistst	is_cachedR_RKtcache_local_file(Rtpath_cachedt	path_hashtpath_cached_hash((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyR�js
cC@st�j|�S(u�
    List all of the available state modules in an environment

    CLI Example:

    .. code-block:: bash

        salt '*' cp.list_states
    (RKtlist_states(RZ((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyR��s
cC@st�j||�S(u�
    List all of the files stored on the master

    CLI Example:

    .. code-block:: bash

        salt '*' cp.list_master
    (RKt	file_list(RZtprefix((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytlist_master�s
cC@st�j||�S(u�
    List all of the directories stored on the master

    CLI Example:

    .. code-block:: bash

        salt '*' cp.list_master_dirs
    (RKtdir_list(RZR�((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytlist_master_dirs�s
cC@st�j||�S(u�
    List all of the symlinks stored on the master

    CLI Example:

    .. code-block:: bash

        salt '*' cp.list_master_symlinks
    (RKtsymlink_list(RZR�((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytlist_master_symlinks�s
cC@st�j|�S(u�
    List all of the files cached on the minion

    CLI Example:

    .. code-block:: bash

        salt '*' cp.list_minion
    (RKtfile_local_list(RZ((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytlist_minion�s
cC@st�j||�S(u�
    Return a boolean if the given path on the master has been cached on the
    minion

    CLI Example:

    .. code-block:: bash

        salt '*' cp.is_cached salt://path/to/file
    (RKR(RRZ((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyR�scC@s=tjjj|�\}}|r*|}nt�j||�S(u'
    Return the hash of a file, to get the hash of a file on the
    salt master file server prepend the path with salt://<file on server>
    otherwise, prepend the file with / for a local file.

    CLI Example:

    .. code-block:: bash

        salt '*' cp.hash_file salt://path/to/file
    (RRR]R^RKR_(RRZRb((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyR_�s	cC@s~tjjj|�\}}|r*|}nt�j||�d}|dkrS|S|tkrvtjjj	|d�S|dS(u5
    Return the permissions of a file, to get the permissions of a file on the
    salt master file server prepend the path with salt://<file on server>
    otherwise, prepend the file with / for a local file.

    CLI Example:

    .. code-block:: bash

        salt '*' cp.stat_file salt://path/to/file
    iiN(
RRR]R^RKthash_and_stat_fileR,R"Rtst_mode_to_octal(RRZtoctalRbtstat((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt	stat_file�s	cC@s�tjd|�d|ks/tjj|�r@tjd�tS|s[tjj|�}ntjj|�s~tjd�tSt�}|r�d|kr�tjd�tjd|�tS|j	tj
�}n|j	tj
�}tjj|�}tjj|�d}g|j
tj
�D]}|r|^q}	idd6td	d	6|	d
6tjj|�d6|jd�d
6}
tjjjjt�}z�tjjj|d���}t}
x�tr{|j�|
d<|jtd�|
d<|
drL|
rL|rHy'tjjj|�tjd|�WqHtk
rDtjd|�tSXntS|j|
�}|srtjd�|St}
q�WWdQXWd|j �XdS(u,
    WARNING Files pushed to the master will have global read permissions..

    Push a file from the minion up to the master, the file will be saved to
    the salt master in the master's minion files cachedir
    (defaults to ``/var/cache/salt/master/minions/minion-id/files``)

    Since this feature allows a minion to push a file up to the master server
    it is disabled by default for security purposes. To enable, set
    ``file_recv`` to ``True`` in the master configuration file, and restart the
    master.

    keep_symlinks
        Keep the path value without resolving its canonical form

    upload_path
        Provide a different path inside the master's minion files cachedir

    remove_source
        Remove the source file on the minion

        .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' cp.push /etc/fstab
        salt '*' cp.push /etc/system-release keep_symlinks=True
        salt '*' cp.push /etc/fstab upload_path='/new/path/fstab'
        salt '*' cp.push /tmp/filename remove_source=True
    uTrying to copy '%s' to masteru../u&Path must be absolute, returning Falseu1Path failed os.path.isfile check, returning FalseuBad path: %siu
_file_recvucmduidupathusizeRutokurbulocufile_buffer_sizeudatauRemoving source file '%s'u"cp.push failed to remove file '%s'u�cp.push Failed transfer failed. Ensure master has 'file_recv' set to 'True' and that the file is not larger than the 'file_recv_size_max' setting on the master.N(!R8R9RRtisabsR$trealpathR1Rtlstriptseptnormpatht
splitdrivetsplitR
tgetsizet	gen_tokenRt	transporttclientt
ReqChanneltfactoryRRR R"ttellRntrm_rfR#RjtsendR;(Rt
keep_symlinkstupload_patht
remove_sourcetautht	load_pathtload_path_normaltload_path_split_drivet_ftload_path_listtloadtchannelR(t	init_sendR((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytpush�s^!

	
+
	

c	C@s�d|kstjj|�r#tS|}tjj|�}tjj|�r]t|d|�Sg}xRtjjj	|�D];\}}}|g|D]}tjj
||�^q�7}qyW|dk	r�g|D]*}	tjtjj
|	�|�r�|	^q�}n|stSx�|D]�}|ru|j|�rutjj
tjj|jtjj�|j|d�jtjj��}nt|d|�}
|
s|
SqWtS(ur
    Push a directory from the minion up to the master, the files will be saved
    to the salt master in the master's minion files cachedir (defaults to
    ``/var/cache/salt/master/minions/minion-id/files``).  It also has a glob
    for matching specific files using globbing.

    .. versionadded:: 2014.7.0

    Since this feature allows a minion to push files up to the master server it
    is disabled by default for security purposes. To enable, set ``file_recv``
    to ``True`` in the master configuration file, and restart the master.

    upload_path
        Provide a different path and directory name inside the master's minion
        files cachedir

    CLI Example:

    .. code-block:: bash

        salt '*' cp.push /usr/lib/mysql
        salt '*' cp.push /usr/lib/mysql upload_path='/newmysql/path'
        salt '*' cp.push_dir /etc/modprobe.d/ glob='*.conf'
    u../R�uN(RRR�R$R�R1R�RRtos_walkRR,tfnmatchRt
startswithR�tstriptreplaceR"(RtglobR�ttmpupload_pathtfilelisttroott_RttmpfiletfiR((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pytpush_dir\s.%0:
(?t__doc__t
__future__RRRR3R/RtloggingR�tsalt.minionRtsalt.fileclienttsalt.utils.datatsalt.utils.filestsalt.utils.gzip_utiltsalt.utils.pathtsalt.utils.templatestsalt.utils.urlt
salt.crypttsalt.transport.clienttsalt.exceptionsRtsalt.ext.six.moves.urllib.parseRRrtsalt.extRt	getLoggert__name__R8t__proxyenabled__RRR)R$R"R,RERJRKR\R`RcRdReRiRpRmRwRyR}R�R�R�R�R�R�RR_R�R�R�(((s3/usr/lib/python2.7/site-packages/salt/modules/cp.pyt<module>sn					A	
		;@	=L'	%
	




_

Zerion Mini Shell 1.0