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

�
���^c@@sldZddlmZmZmZddlZddlZddlZddlZddl	m
Z
ddlmZej
e�Zed�Zedd�Zdd	�Zd
�Zd�Zd�Zd
�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(dS(u�
Module for low-level interaction with JbossAS7 through CLI.

This module exposes two ways of interaction with the CLI, either through commands or operations.

.. note:: Following JBoss documentation (https://developer.jboss.org/wiki/CommandLineInterface):
    "Operations are considered a low level but comprehensive way to manage the AS controller, i.e. if it can't be done with operations it can't be done in any other way.
    Commands, on the other hand, are more user-friendly in syntax,
    although most of them still translate into operation requests and some of them even into a few
    composite operation requests, i.e. commands also simplify some management operations from the user's point of view."

The difference between calling a command or operation is in handling the result.
Commands return a zero return code if operation is successful or return non-zero return code and
print an error to standard output in plain text, in case of an error.

Operations return a json-like structure, that contain more information about the result.
In case of a failure, they also return a specific return code. This module parses the output from the operations and
returns it as a dictionary so that an execution of an operation can then be verified against specific errors.

In order to run each function, jboss_config dictionary with the following properties must be passed:
 * cli_path: the path to jboss-cli script, for example: '/opt/jboss/jboss-7.0/bin/jboss-cli.sh'
 * controller: the IP address and port of controller, for example: 10.11.12.13:9999
 * cli_user: username to connect to jboss administration console if necessary
 * cli_password: password to connect to jboss administration console if necessary

Example:

.. code-block:: yaml

   jboss_config:
      cli_path: '/opt/jboss/jboss-7.0/bin/jboss-cli.sh'
      controller: 10.11.12.13:9999
      cli_user: 'jbossadm'
      cli_password: 'jbossadm'

i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(tsixcC@sXt||�}|ddkr,t|d<n(|rJtdj|���n
t|d<|S(u�
    Execute a command against jboss instance through the CLI interface.

    jboss_config
           Configuration dictionary with properties specified above.
    command
           Command to execute against jboss instance
    fail_on_error (default=True)
           Is true, raise CommandExecutionError exception if execution fails.
           If false, 'success' property of the returned dictionary is set to False

    CLI Example:

    .. code-block:: bash

        salt '*' jboss7_cli.run_command '{"cli_path": "integration.modules.sysmod.SysModuleTest.test_valid_docs", "controller": "10.11.12.13:9999", "cli_user": "jbossadm", "cli_password": "jbossadm"}' my_command
    uretcodeiusuccessuVCommand execution failed, return code={retcode}, stdout='{stdout}', stderr='{stderr}' (t
__call_clitTrueRtformattFalse(tjboss_configtcommandt
fail_on_errortcli_command_result((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pytrun_command7s

icC@s)t|||�}|ddkrut|d�rYt|d�}|ddk|d<q%tdj|d���n�t|d�r�t|d�}t|d<tjd|d�}|jd	�|d
<|d|d<nL|r�tdj|���n.itd6|dd6|dd6|dd6}|S(
u
    Execute an operation against jboss instance through the CLI interface.

    jboss_config
           Configuration dictionary with properties specified above.
    operation
           An operation to execute against jboss instance

    fail_on_error (default=True)
           Is true, raise CommandExecutionError exception if execution fails.
           If false, 'success' property of the returned dictionary is set to False
    retries:
           Number of retries in case of "JBAS012144: Could not connect to remote" error.

    CLI Example:

    .. code-block:: bash

        salt '*' jboss7_cli.run_operation '{"cli_path": "integration.modules.sysmod.SysModuleTest.test_valid_docs", "controller": "10.11.12.13:9999", "cli_user": "jbossadm", "cli_password": "jbossadm"}' my_operation
    uretcodeiustdoutuoutcomeusuccessu.Operation has returned unparseable output: {0}u^(JBAS\d+):ufailure-descriptioniuerr_codeuVCommand execution failed, return code={retcode}, stdout='{stdout}', stderr='{stderr}' ustderr(	Rt_is_cli_outputt_parseRRRtretsearchtgroup(R	t	operationRtretriesRt
cli_resulttmatch((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyt
run_operationVs(
cC@s�|dddj|d�g}dtj|�krR|jdj|d��ndtj|�kr�|jdj|d��n|jd	jt|���d
j|�}td|�}tjd|�tjd
|d�tjd|d�tjd|d�|ddkr:t	djd|d���n|ddkrrd|dkrrt	dj|���n|ddkr�d|dkr�|dkr�tjd|�t
jd�t|||d�S|S(Nucli_pathu	--connectu--controller="{0}"u
controllerucli_useru--user="{0}"ucli_passwordu--password="{0}"u--command="{0}"u ucmd.run_allucli_command_result=%su========= STDOUT:
%sustdoutu========= STDERR:
%sustderru========= RETCODE: %duretcodeiuwCould not execute jboss-cli.sh script. Have you specified server_dir variable correctly?
Current CLI path: {cli_path}. tcli_pathiu)Unable to authenticate against controlleru�Could not authenticate against controller, please check username and password for the management console. Err code: {retcode}, stdout: {stdout}, stderr: {stderr}u
JBAS012144iu+Command failed, retrying... (%d tries left)i(
RRtiterkeystappendt__escape_commandtjoint__salt__tlogtdebugRttimetsleepR(R	R
Rtcommand_segmentst
cli_scriptR((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR�s. ,
cC@s(|jdd�}|jdd�}|S(u�	
    This function escapes the command so that can be passed in the command line to JBoss CLI.
    Escaping commands passed to jboss is extremely confusing.
    If you want to save a binding that contains a single backslash character read the following explanation.

    A sample value, let's say "a" (with single backslash), that is saved in the config.xml file:
    <bindings>
      <simple name="java:/app/binding1" value="a"/>
    </bindings>

    Eventhough it is just a single "" if you want to read it from command line you will get:

    /opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh --connect --controller=ip_addr:9999 --user=user --password=pass --command="/subsystem=naming/binding="java:/app/binding1":read-resource"
    {
       "outcome" => "success",
       "result" => {
           "binding-type" => "simple",
           "value" => "a\b"
       }
    }

    So, now you have two backslashes in the output, even though in the configuration file you have one.
    Now, if you want to update this property, the easiest thing to do is to create a file with appropriate command:
    /tmp/update-binding.cli:
    ----
    /subsystem=naming/binding="java:/app/binding1":write-attribute(name=value, value="a\\b")
    ----
    And run cli command:
    ${JBOSS_HOME}/bin/jboss-cli.sh --connect --controller=ip_addr:9999 --user=user --password=pass --file="/tmp/update-binding.cli"

    As you can see, here you need 4 backslashes to save it as one to the configuration file. Run it and go to the configuration file to check.
    (You may need to reload jboss afterwards:  ${JBOSS_HOME}/bin/jboss-cli.sh --connect --controller=ip_addr:9999 --user=user --password=pass --command=":reload" )

    But if you want to run the same update operation directly from command line, prepare yourself for more escaping:
    ${JBOSS_HOME}/bin/jboss-cli.sh --connect --controller=ip_addr:9999 --user=user --password=pass --command="/subsystem=naming/binding="java:/app/binding1":write-attribute(name=value, value="a\\\\b")"

    So, here you need 8 backslashes to force JBoss to save it as one.
    To sum up this behavior:
    (1) 1 backslash in configuration file
    (2) 2 backslashes when reading
    (3) 4 backslashes when writing from file
    (4) 8 backslashes when writing from command line
    ... are all the same thing:)

    Remember that the command that comes in is already (3) format. Now we need to escape it further to be able to pass it to command line.
    u\u\\u"u\"(treplace(R
tresult((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR�s/cC@s0tjdtj�}|j|�r(tStSdS(Nu^\s*{.+}\s*$(RtcompiletDOTALLRRR(ttexttcli_re((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR�scC@s6t|�}t|�}tjdtj|��|S(Nu=== RESULT: (t
__tokenizet__process_tokensRRtpprinttpformat(t
cli_outputttokensR%((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR�scC@st|�\}}|S(N(t__process_tokens_internal(R/R%ttoken_no((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR+�sc	C@sTt||�r,|dkr,t|dd�Stjd|�|}i}d}x�|t|�krO||}tjd||�t|�r�tjd�|dkr�t|�}tjd|�qBt|�||<tjd|||�d}nNt|�r@tjd	|�t	|�||<tjd|||�d}nt
|�r�tjd
�t|�||<tjd|||�d}n�t|�r�tjd�t
|�||<tjd|||�d}npt|�rtjd�t|�||<tjd|||�d}n't|�rWtjd
�tjd|�d||<d}n�t|�r�tjd�t|d|d�\}}tjd|�|||<tjd|||�d}n|t|�r�tjd�||fSt|�rtjd�t}n7t|�r-tjd�t}ntdj|���|d}qQWdS(Nitstart_atiu__process_tokens, start_at=%suPROCESSING TOKEN %d: %su    TYPE: QUOTED STRING u    KEY: %su    %s -> %su    TYPE: DATATYPE: %s u    TYPE: BOOLEAN u    TYPE: INT u    TYPE: LONG u    TYPE: UNDEFINED u+    %s -> undefined (Adding as None to map)u    TYPE: DICT STARTu    DICT = %s u    TYPE: DICT ENDu    TYPE: ASSIGNMENTu    TYPE: EXPRESSIONuUnknown token! Token: {0}(t__is_dict_startR0RRtNonetlent__is_quoted_stringt__get_quoted_stringt
__is_datatypet__get_datatypet__is_booleant
__get_booleant__is_intt	__get_intt	__is_longt
__get_longt__is_undefinedt
__is_dict_endt__is_assignmentRt__is_expressionRR(	R/R2R1R%tcurrent_keyttokent
dict_valuet
is_assignmentt
is_expression((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR0�sx

		
	
	
	

	

	


	
	cC@s8tjdtj�}|j|�}tjd|�|S(NuA("(?:[^"\\]|\\"|\\\\)*"|=>|{|}|true|false|undefined|[0-9A-Za-z]+)u	tokens=%s(RR&R'tfindallRR(R.t	tokens_reR/((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR*6scC@s
|dkS(Nu{((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR3?scC@s
|dkS(Nu}((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyRACscC@s|dkp|dkS(Nutrueufalse((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR:GscC@s
|dkS(Nutrue((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR;KscC@s
|j�S(N(tisdigit(RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR<OscC@s
t|�S(N(tint(RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR=SscC@s!|dd!j�o |ddkS(Nii����uL(RK(RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR>WscC@s/tjrt|dd!�St|dd!�SdS(Nii����(RtPY2tlongRL(RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR?[s	cC@s
|dkS(NuINTuBOOLEANuSTRINGuOBJECTuLONG(uINTuBOOLEANuSTRINGuOBJECTuLONG((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR8bscC@s|S(N((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR9fscC@s
|dkS(Nu	undefined((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR@jscC@s|ddko|ddkS(Niu"i����((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR6nscC@s#|dd!}|jdd�}|S(Nii����u\\u\(R$(RER%((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyR7rs
cC@s
|dkS(Nu=>((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyRBxscC@s
|dkS(Nu
expression((RE((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyRC|s()t__doc__t
__future__RRRtloggingRR,R tsalt.exceptionsRtsalt.extRt	getLoggert__name__RRR
RRRRRR+R0R*R3RAR:R;R<R=R>R?R8R9R@R6R7RBRC(((s;/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.pyt<module>%s@1#	4			C																

Zerion Mini Shell 1.0