HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/pcs.cpython-310.pyc
o

�N�gL8�@s�dZddlZddlZe�e�Zdd�Zdd�Z	d,dd	�Z		d-dd�Z
d.dd�Zd/dd�Zd0dd�Z
d1dd�Zd1dd�Zd2dd�Zd2dd�Zd1dd�Zd3d d!�Zd3d"d#�Zd3d$d%�Z	d3d&d'�Zd3d(d)�Zd3d*d+�ZdS)4z�
Configure a Pacemaker/Corosync cluster with PCS
===============================================

Configure Pacemaker/Cororsync clusters with the
Pacemaker/Cororsync conifguration system (PCS)

:depends: pcs

.. versionadded:: 2016.3.0
�NcCstjj�d�r	dSdS)z/
    Only load if pcs package is installed
    �pcs)FzMissing dependency: pcs)�salt�utils�path�which�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pcs.py�__virtual__sr	cCsFtdd�}t�d|�td|d�dkrt�d�dSt�d	�d
S)z�
    The command line arguments of pcs changed after version 0.10
    This will return True if the new arguments are needed and
    false if the old ones are needed
    zpkg.versionrzPCS package version %szpkg.version_cmpz0.10�zNew version, new commandTzOld VersionF)�__salt__�log�debug)Zpcs_versionrrr�__use_new_commandss

r�showc
CsZt�}dg}t|t�r|d|g7}t|t�r||g7}nt|ttf�r'||7}|dvr0||g7}|r_|dkr_|dkr_|dkr_|dkrEd}nt|ttf�r_t|�D]\}}	||dkr^d||<qPt|t�rj||g7}nt|ttf�ru||7}t|t�r||g7}t|ttf�r�||7}|dvr�t|ttf�r�d|vr�|dg7}t�d	|�td
|ddd
�S)a�
    Show an item via pcs command
    (mainly for use with the pcs state module)

    item
        config, property, resource, constraint etc.
    item_id
        id of the item
    item_type
        item type
    show
        show command (probably None, default: show or status for newer implementation)
    extra_args
        additional options for the pcs command
    cibfile
        use cibfile instead of the live CIB
    r�-f��
constraint�configr�propertyrz--fullzRunning item show %s�cmd.run_all�traceF��output_loglevel�python_shell)	r�
isinstance�str�list�tuple�	enumeraterr
r)
�item�item_id�	item_typer�
extra_args�cibfileZnew_commands�cmd�index�valuerrr�	item_show.s@


�



r'�createcCs�dg}t|t�r|d|g7}t|t�r||g7}nt|ttf�r$||7}|dvr2t|t�r2||g7}t|t�r=||g7}nt|ttf�rH||7}|dvr[||g7}t|t�r[||g7}t|ttf�rr|dvrn|d|��g}||7}td|ddd�S)	a�
    Create an item via pcs command
    (mainly for use with the pcs state module)

    item
        config, property, resource, constraint etc.
    item_id
        id of the item
    item_type
        item type
    create
        create command (create or set f.e., default: create)
    extra_args
        additional options for the pcs command
    cibfile
        use cibfile instead of the live CIB
    rrrzid=rrFr�rrrrr)rr r!r(r"r#r$rrr�item_createqs.







r*�	haclustercCs`t�rgd�}ngd�}|�d|d|g�t�s#t|ttf�r#||7}||7}td|ddd�S)	aN
    Authorize nodes to the cluster

    nodes
        a list of nodes which should be authorized to the cluster
    pcsuser
        user for communitcation with PCS (default: hacluster)
    pcspasswd
        password for pcsuser (default: hacluster)
    extra_args
        list of extra option for the 'pcs cluster auth' command. The newer cluster host command has no extra args and so will ignore it.

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.auth nodes='[ node1.example.org, node2.example.org ]' pcsuser=hacluster pcspasswd=hoonetorg extra_args=[ '--force' ]
    )r�host�auth�r�clusterr-�-u�-prrFr)r�extendrrrr)�nodes�pcsuser�	pcspasswdr"r$rrrr-�s
r-cCs>t�r
dddd|d|g}ngd�}||7}td|dd	d
d�S)a�
    Check if nodes are already authorized

    nodes
        a list of nodes to be checked for authorization to the cluster
    pcsuser
        user for communitcation with PCS (default: hacluster)
    pcspasswd
        password for pcsuser (default: hacluster)

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.is_auth nodes='[node1.example.org, node2.example.org]' pcsuser=hacluster pcspasswd=hoonetorg
    rr,r-r0r1r.rz

rF)�stdinrr)rr)r3r4r5r$rrr�is_auth�s�r7�
pcsclustercCsbgd�}t�r
||g7}n|d|g7}||7}t|ttf�r"||7}t�d|�td|ddd�S)a�
    Setup pacemaker cluster via pcs command

    nodes
        a list of nodes which should be set up
    pcsclustername
        Name of the Pacemaker cluster (default: pcscluster)
    extra_args
        list of extra option for the 'pcs cluster setup' command

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.cluster_setup nodes='[ node1.example.org, node2.example.org ]' pcsclustername=pcscluster
    )rr/�setupz--namezRunning cluster setup: %srrFr)rrrrrr
r)r3Zpcsclusternamer"r$rrr�
cluster_setup�sr:cCs<gd�}t|ttf�r||7}t�d|�td|ddd�S)a
    Destroy corosync cluster using the pcs command

    extra_args
        list of extra option for the 'pcs cluster destroy' command (only really --all)

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.cluster_destroy extra_args=--all
    )rr/ZdestroyzRunning cluster destroy: %srrFr)rrrrr
r)r"r$rrr�cluster_destroys

r;cCs:gd�}||g7}t|ttf�r||7}td|ddd�S)a&
    Add a node to the pacemaker cluster via pcs command

    node
        node that should be added
    extra_args
        list of extra option for the 'pcs cluster node add' command

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.cluster_node_add node=node2.example.org
    )rr/�node�addrrFr)rrrr)r<r"r$rrr�cluster_node_adds

r>�
configurationcC�Nddd|g}t|t�r|d|��g7}t|ttf�r||7}td|ddd�S)	a�
    Create a CIB-file from the current CIB of the cluster

    cibfile
        name/path of the file containing the CIB
    scope
        specific section of the CIB (default: configuration)
    extra_args
        additional options for creating the CIB-file

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.cib_create cibfile='/tmp/VIP_apache_1.cib' scope=False
    rr/Zcib�scope=rrFrr)�r#Zscoper"r$rrr�
cib_create7�
rCcCr@)	aw
    Push a CIB-file as the new CIB to the cluster

    cibfile
        name/path of the file containing the CIB
    scope
        specific section of the CIB (default: configuration)
    extra_args
        additional options for creating the CIB-file

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.cib_push cibfile='/tmp/VIP_apache_1.cib' scope=False
    rr/zcib-pushrArrFrr)rBrrr�cib_pushQrDrEcCstddd|d�S)z�
    Show config of cluster

    cibfile
        name/path of the file containing the CIB

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.config_show cibfile='/tmp/cib_for_galera'
    rN�rr r"r#�r')r#rrr�config_showks
rHcC�td|||d�S)a|
    Show the value of a cluster property

    prop
        name of the property
    extra_args
        additional options for the pcs property command
    cibfile
        use cibfile instead of the live CIB

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.prop_show cibfile='/tmp/2_node_cluster.cib' prop='no-quorum-policy' cibfile='/tmp/2_node_cluster.cib'
    rrFrG)�propr"r#rrr�	prop_show{��rKcCstd|�d|��dd||d�S)a�
    Set the value of a cluster property

    prop
        name of the property
    value
        value of the property prop
    extra_args
        additional options for the pcs property command
    cibfile
        use cibfile instead of the live CIB

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.prop_set prop='no-quorum-policy' value='ignore' cibfile='/tmp/2_node_cluster.cib'
    r�=N�set)rr r!r(r"r#�r*)rJr&r"r#rrr�prop_set�s�rPcCrI)ai
    Show the value of a cluster stonith

    stonith_id
        name for the stonith resource
    extra_args
        additional options for the pcs stonith command
    cibfile
        use cibfile instead of the live CIB

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.stonith_show stonith_id='eps_fence' cibfile='/tmp/2_node_cluster.cib'
    �stonithrFrG)�
stonith_idr"r#rrr�stonith_show�rLrScC�td||||d�S)a
    Create a stonith resource via pcs command

    stonith_id
        name for the stonith resource
    stonith_device_type
        name of the stonith agent fence_eps, fence_xvm f.e.
    stonith_device_options
        additional options for creating the stonith resource
    cibfile
        use cibfile instead of the live CIB for manipulation

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.stonith_create stonith_id='eps_fence' stonith_device_type='fence_eps'
                                    stonith_device_options="['pcmk_host_map=node1.example.org:01;node2.example.org:02', 'ipaddr=myepsdevice.example.org', 'action=reboot', 'power_wait=5', 'verbose=1', 'debug=/var/log/pcsd/eps_fence.log', 'login=hidden', 'passwd=hoonetorg']" cibfile='/tmp/cib_for_stonith.cib'
    rQ�rr r!r"r#rO)rRZstonith_device_typeZstonith_device_optionsr#rrr�stonith_create�s�rVcCrI)aT
    Show a resource via pcs command

    resource_id
        name of the resource
    extra_args
        additional options for the pcs command
    cibfile
        use cibfile instead of the live CIB

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.resource_show resource_id='galera' cibfile='/tmp/cib_for_galera.cib'
    �resourcerFrG)�resource_idr"r#rrr�
resource_show�rLrYcCrT)ad
    Create a resource via pcs command

    resource_id
        name for the resource
    resource_type
        resource type (f.e. ocf:heartbeat:IPaddr2 or VirtualIP)
    resource_options
        additional options for creating the resource
    cibfile
        use cibfile instead of the live CIB for manipulation

    CLI Example:

    .. code-block:: bash

        salt '*' pcs.resource_create resource_id='galera' resource_type='ocf:heartbeat:galera' resource_options="['wsrep_cluster_address=gcomm://node1.example.org,node2.example.org,node3.example.org', '--master']" cibfile='/tmp/cib_for_galera.cib'
    rWrUrO)rXZ
resource_typeZresource_optionsr#rrr�resource_create�s�rZ)NNrNN)r(NN)r+r+N)r+r+)r8N)N)r?N)NN)�__doc__�loggingZsalt.utils.pathr�	getLogger�__name__rr	rr'r*r-r7r:r;r>rCrErHrKrPrSrVrYrZrrrr�<module>s2
	
�D
�
7
"

!







�