%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/tomcat.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ
ddlmZddlmZmZmZmZmZddlZe
je�Z idd6Z!id	d
gd6dd
gd6Z"d�Z#d�Z$d�Z%d�Z&d�Z'dddd�Z)ddd�Z*ddd�Z+ddd�Z,ddd�Z-ddd�Z.ddd�Z/ddd�Z0ddd�Z1ddd�Z2ddd �Z3ddd!�Z4d"dd#dde5d$�Z6d%d&dd'�Z7d(�Z8d)�Z9dd*�Z:ed+kr�iZ;iZ<id,d	6d-d6Z=e%�Z>iid,d6d-d6d.6Z=e%�Z?e>e?kr�e j@d/�q�e jAd0�ndS(1u�
Support for Tomcat

This module uses the manager webapp to manage Apache tomcat webapps.
If the manager webapp is not configured some of the functions won't work.

:configuration:
    - Java bin path should be in default path
    - If ipv6 is enabled make sure you permit manager access to ipv6 interface
      "0:0:0:0:0:0:0:1"
    - If you are using tomcat.tar.gz it has to be installed or symlinked under
      ``/opt``, preferably using name tomcat
    - "tomcat.signal start/stop" works but it does not use the startup scripts

The following grains/pillar should be set:

.. code-block:: yaml

    tomcat-manager:
      user: <username>
      passwd: <password>

or the old format:

.. code-block:: yaml

    tomcat-manager.user: <username>
    tomcat-manager.passwd: <password>

Also configure a user in the conf/tomcat-users.xml file:

.. code-block:: xml

    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
        <role rolename="manager-script"/>
        <user username="tomcat" password="tomcat" roles="manager-script"/>
    </tomcat-users>

.. note::

   - More information about tomcat manager:
     http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html
   - if you use only this module for deployments you've might want to strict
     access to the manager only from localhost for more info:
     http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access
   - Tested on:

     JVM Vendor:
         Sun Microsystems Inc.
     JVM Version:
         1.6.0_43-b01
     OS Architecture:
         amd64
     OS Name:
         Linux
     OS Version:
         2.6.32-358.el6.x86_64
     Tomcat Version:
         Apache Tomcat/7.0.37
i(tabsolute_importtunicode_literalstprint_functionN(tstring_types(t	urlencode(turlopentHTTPBasicAuthHandlertHTTPDigestAuthHandlertbuild_openertinstall_openerureloadureload_utomcat-manager.userutomcat-manager:useruuserutomcat-manager.passwdutomcat-manager:passwdupasswdcC@s#t�std�rdStdfS(uO
    Only load tomcat if it is installed or if grains/pillar config exists
    udummyutomcatu�Tomcat execution module not loaded: neither Tomcat installed locally nor tomcat-manager credentials set in grains/pillar/config.(t__catalina_homet_authtFalse(((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt__virtual__mscC@sdddg}xQ|D]I}tj|�}|rx+|D] }tjj|d�r5|Sq5WqqWtS(u4
    Tomcat paths differ depending on packaging
    u/usr/share/tomcat*u/opt/tomcatu/bin(tglobtostpathtisdirR(t	locationstlocationtfolderst
catalina_home((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyR
ws

cC@s�itd6td6}xl|D]d}x[tttgD]J}xAt|D]5}tjjj||d�}|rB|||<PqBqBWq1WqW|d|dfS(uD
    Get the username and password from opts, grains, or pillar
    uuserupasswdN(
Rt__opts__t
__grains__t
__pillar__t__valid_configstsalttutilstdatattraverse_dict_and_listtNone(trettitemtstructt
config_keytvalue((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt_get_credentials�s

	
c
C@s�t�\}}|tks'|tkr+tSt�}|jddd|d|d|�t�}|jddd|d|d|�t||�S(u�
    returns a authentication handler.
    Get user & password from grains, if are not set default to
    modules.config.option

    If user & pass are missing return False
    trealmuTomcat Manager Applicationturitusertpasswd(R$Rt_HTTPBasicAuthHandlertadd_passwordt_HTTPDigestAuthHandlert
_build_opener(R&R'tpasswordtbasictdigest((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyR�s		
	
cC@s^tjj|�}tjj|�d}tjd|�}|rZt|�dkrZ|dSdS(uc
    Extract the version from the war file name. There does not seem to be a
    standard for encoding the version into the `war file name`_

    .. _`war file name`: https://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html

    Examples:

    .. code-block:: bash

        /path/salt-2015.8.6.war -> 2015.8.6
        /path/V6R2013xD5.war -> None
    iu-([\d.-]+)$iN(RRtbasenametsplitexttretfindalltlenR(twarR0twar_packagetversion((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytextract_war_version�suhttp://localhost:8080/manageri�cC@sxitd6gd6}t|�}|tkrDt|d<d|d<|S|ddkra|d7}n|}|dj|�7}|dj|�7}|r�|djt|��7}|djt|��7}nt|�y&t|d	|�j�j�|d<WnUt	k
rOy&t|d	|�j�j�|d<WqPt	k
rKd
|d<qPXnX|ddj
d�stt|d<n|S(
u�
    A private function used to issue the command to tomcat via the manager
    webapp

    cmd
        the command to execute

    url
        The URL of the server manager webapp (example:
        http://localhost:8080/manager)

    opts
        a dict of arguments

    timeout
        timeout for HTTP request

    Return value is a dict in the from of::

        {
            res: [True|False]
            msg: list of lines we got back from the manager
        }
    uresumsgu5missing username and password settings (grain/pillar)i����u/utext/{0}u{0}u?{0}ttimeoutuFailed to create HTTP requestiuOK(tTrueRRtformatt
_urlencodet_install_openert_urlopentreadt
splitlinest	Exceptiont
startswith(tcmdtoptsturlR9Rtauthturl6((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt_wget�s6




&
&

cC@skyIi|d6t|�|dd6}djt|||d|�d�SWntk
rfdj|�SXdS(uI
    Simple command wrapper to commands that need only a path option
    upathuversionu
R9umsgu%FAIL - No context exists for path {0}N(tlstjoinRHRAR;(RCtappRER9RD((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt_simple_cmds'
cC@s!tdidd6|d|�dS(u�
    Find memory leaks in tomcat

    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.leaks
    u	findleaksutrueu
statusLineR9umsg(RH(RER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytleaksscC@stdi|d|�dS(uE
    Used to test if the tomcat manager is up

    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.status
        salt '*' tomcat.status http://localhost:8080/manager
    ulistR9ures(RH(RER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytstatus0scC@s�i}tdd|d|�}|dtkr2iS|djd�x�|dD]�}|jd�}i|dd	6|d
d6|dd
6dd6||d<|djd�}t|�dkrN|d||dd<qNqNW|S(u2
    list all the deployed webapps

    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.ls
        salt '*' tomcat.ls http://localhost:8080/manager
    ulistuR9uresumsgiu:iumodeiusessionsiufullnameuversionu##(RHRtpoptsplitR4(RER9RRtlinettmptsliced((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyRIDs cC@std||d|�S(ub
    Stop the webapp

    app
        the webapp context path
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.stop /jenkins
        salt '*' tomcat.stop /jenkins http://localhost:8080/manager
    ustopR9(RL(RKRER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytstopiscC@std||d|�S(u_
    Start the webapp

    app
        the webapp context path
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.start /jenkins
        salt '*' tomcat.start /jenkins http://localhost:8080/manager
    ustartR9(RL(RKRER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytstartscC@std||d|�S(uh
    Reload the webapp

    app
        the webapp context path
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.reload /jenkins
        salt '*' tomcat.reload /jenkins http://localhost:8080/manager
    ureloadR9(RL(RKRER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytreload_�scC@std||d|�S(u�
    return the status of the webapp sessions

    app
        the webapp context path
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.sessions /jenkins
        salt '*' tomcat.sessions /jenkins http://localhost:8080/manager
    usessionsR9(RL(RKRER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytsessions�scC@s?t|d|�}x&|D]}||kr||dSqWdS(u�
    return the status of the webapp (stopped | running | missing)

    app
        the webapp context path
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.status_webapp /jenkins
        salt '*' tomcat.status_webapp /jenkins http://localhost:8080/manager
    R9umodeumissing(RI(RKRER9twebappsti((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt
status_webapp�s

cC@s�tdi|d|�}|dtkr7i|dd6Si}|djd�x?|dD]3}|jd�}|dj�||dj�<qYW|S(	uD
    return details about the server

    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.serverinfo
        salt '*' tomcat.serverinfo http://localhost:8080/manager
    u
serverinfoR9uresumsguerroriu:i(RHRRORPtstrip(RER9RRRQRR((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt
serverinfo�s"cC@std||d|�S(ul
    Undeploy a webapp

    app
        the webapp context path
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    timeout : 180
        timeout for HTTP request

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.undeploy /jenkins
        salt '*' tomcat.undeploy /jenkins http://localhost:8080/manager
    uundeployR9(RL(RKRER9((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytundeploy�sunoubasecC@s�djtjj|��}|dk	r^tjj|�sFdj|�Stjj||�}ntjjtj�|�}t	}	tjj
|�s�t}	td|||�}
|
s�dSytd|
d�Wq�t
k
r�q�Xn|}idj|�d6|d	6}|rI|tkr$t|�n|}t|t�rI||d
<qIn|dkrbd|d
<ntd||d|�}dj|d�}
|	r�td|�n|
S(uM
    Deploy a WAR file

    war
        absolute path to WAR file (should be accessible by the user running
        tomcat) or a path supported by the salt.modules.cp.get_file function
    context
        the context path to deploy
    force : False
        set True to deploy the webapp even one is deployed in the context
    url : http://localhost:8080/manager
        the URL of the server manager webapp
    saltenv : base
        the environment for WAR file in used by salt.modules.cp.get_url
        function
    timeout : 180
        timeout for HTTP request
    temp_war_location : None
        use another location to temporarily copy to war file
        by default the system's temp directory is used
    version : ''
        Specify the war version.  If this argument is provided, it overrides
        the version encoded in the war file name, if one is present.

        Examples:

        .. code-block:: bash

            salt '*' tomcat.deploy_war salt://salt-2015.8.6.war version=2015.08.r6

        .. versionadded:: 2015.8.6

    CLI Examples:

    cp module

    .. code-block:: bash

        salt '*' tomcat.deploy_war salt://application.war /api
        salt '*' tomcat.deploy_war salt://application.war /api no
        salt '*' tomcat.deploy_war salt://application.war /api yes http://localhost:8080/manager

    minion local file system

    .. code-block:: bash

        salt '*' tomcat.deploy_war /tmp/application.war /api
        salt '*' tomcat.deploy_war /tmp/application.war /api no
        salt '*' tomcat.deploy_war /tmp/application.war /api yes http://localhost:8080/manager
    usalt.{0}u Error - "{0}" is not a directoryu
cp.get_urlu#FAIL - could not cache the WAR fileu
file.set_modeu0644ufile:{0}uwarupathuversionuyesutrueuupdateudeployR9u
umsgufile.removeN(R;RRR0RRRJttempfilet
gettempdirRtisfileR:t__salt__tKeyErrorR8t
isinstancet
_string_typesRH(R5tcontexttforceREtsaltenvR9ttemp_war_locationR7ttfiletcachetcachedRDtdeployedtres((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt
deploy_wars>;



uusha1cC@sutt|�rtt|�p!d}|r_|rO|jdj|||��q_|j|�n|rq|j�pttS(uk
    This function replaces the $CATALINA_HOME/bin/digest.sh script
    convert a clear-text password to the $CATALINA_BASE/conf/tomcat-users.xml
    format

    CLI Examples:

    .. code-block:: bash

        salt '*' tomcat.passwd secret
        salt '*' tomcat.passwd secret tomcat sha1
        salt '*' tomcat.passwd secret tomcat sha1 'Protected Realm'
    u{0}:{1}:{2}N(thasattrthashlibtgetattrRtupdateR;t	hexdigestR(R(R'talgR%R/((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyR(~s$cC@sgt�d}td|�j�}x=|D]5}|s<q*nd|kr*|jd�}|dSq*WdS(u�
    Return server version from catalina.sh version

    CLI Example:

    .. code-block:: bash

        salt '*' tomcat.version
    u/bin/catalina.sh versionucmd.runuServer versionu: iN(R
RaR@RP(RCtoutRQtcomps((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyR7�s


cC@s�t�d}i}td|�j�}xP|D]H}|sBq0nd|kr0|jd�}|dj�||d<q0q0W|S(u�
    Return all server information from catalina.sh version

    CLI Example:

    .. code-block:: bash

        salt '*' tomcat.fullversion
    u/bin/catalina.sh versionucmd.runu: ii(R
RaR@RPtlstrip(RCRRuRQRv((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pytfullversion�s


cC@s]idd6dd6dd6dd6}||kr2dSdjt�||�}td	|�dS(
u�
    Signals catalina to start, stop, securestart, forcestop.

    CLI Example:

    .. code-block:: bash

        salt '*' tomcat.signal start
    ustop -forceu	forcestopustart -securityusecurestartustartustopNu{0}/bin/catalina.sh {1}ucmd.run(R;R
Ra(tsignalt
valid_signalsRC((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyRy�s


u__main__ufoobarubarfoo1!utomcat-manageruConfig backwards compatibleuConfig not backwards compatible(Bt__doc__t
__future__RRRRR2RRpR^tloggingtsalt.ext.sixRRdtsalt.ext.six.moves.urllib.parseRR<t!salt.ext.six.moves.urllib.requestRR>RR)RR+RR,R	R=tsalt.utils.dataRt	getLoggert__name__tlogt__func_alias__RR
R
R$RR8RRHRLRMRNRIRTRURVRWRZR\R]R:RnR(R7RxRyRRRtold_format_credstnew_format_credstinfotifno(((s7/usr/lib/python2.7/site-packages/salt/modules/tomcat.pyt<module>>s~(



	
				C%h		
		

Zerion Mini Shell 1.0