%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/glusterfs.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddljj	Z
ddlZddl
ZddlmZmZddlmZeje�Zd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Ze e e de e e d�Z!d�Z"d�Z#dd�Z%e d�Z&e d�Z'e(d�Z)d�Z*d�Z+d�Z,e d�Z-d�Z.d�Z/d�Z0d�Z1d �Z2d!�Z3dS("u
Manage a glusterfs pool
i(tabsolute_importtunicode_literalstprint_functionN(tSaltInvocationErrortCommandExecutionError(tsixcC@s#tjjjd�rtStdfS(u=
    Only load this module if the gluster command exists
    uglusteru!glusterfs server is not installed(tsalttutilstpathtwhichtTruetFalse(((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt__virtual__scC@s�ddg}d}td|�j�}xX|D]P}|jd�r/|j�djd�}g|D]}t|�^qd}q/q/Wt|�S(Niiugluster --versionucmd.runu	glusterfsi����u.(t__salt__t
splitlinest
startswithtsplittintttuple(tversiontcmdtresulttlineti((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt_get_version s
&cC@st|jd�j�dkS(uA
    Extract boolean return value from Gluster's XML output.
    uopReti(Rtfindttext(txml_data((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt_gluster_ok,scC@sWd}xJ|j�D]<}|jd�r?||dj�7}q||j�7}qW|S(u�
    Gluster versions prior to 6 have a bug that requires tricking
    isatty. This adds "gluster> " to the output. Strip it off and
    produce clean xml for ElementTree.
    uugluster>i	(RRtstrip(RtretR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt_gluster_output_cleanup3scC@st�dkr1tddddj|��}ntddddj|��}ytjt|��}Wn3tjk
r�td	j|j	�d
 ���nXt
|�r�|jd�}|dk	r�t
jd||jd�j�qt
jd
|�nt
jd||jd�j�|S(u9
    Perform a gluster --xml command and log result.
    iiucmd.runu*script -q -c "gluster --xml --mode=script"tstdinu{0}
ugluster --xml --mode=scriptu{0}
u
i����uoutputuGluster call "%s" succeeded: %suGluster call "%s" succeededuFailed gluster call: %s: %suopErrstr(iiN(RR
tformattETt
fromstringRt
ParseErrorRtjoinRRRtNonetlogtinfoRterror(RRtroottoutput((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt_gluster_xmlCs(#		cC@stt|��S(u@
    Perform a gluster command and return a boolean status.
    (RR,(R((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt_glusterhscC@s7i}x!|D]}t|�||j<q
W|p6|jS(N(t_etree_to_dictttagR(tttdtchild((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyR.os
cC@s-tjdkr|j|�S|j|�SdS(u+
    Checks for python2.6 or python2.7
    iiN(ii(tsystversion_infotgetiteratortiter(R*tterm((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt_itervs
cC@std�}t|�sdSi}x�t|d�D]�}|jd�j}igd6||<x�|D]�}|jdkr�||dj|j�qb|jdkr�xi|D]8}|j||dkr�||dj|j�q�q�Wqb|jdkrb|j|||j<qbqbWq2W|S(ug
    Return peer status information

    The return value is a dictionary with peer UUIDs as keys and dicts of peer
    information as values. Hostnames are listed in one list. GlusterFS separates
    one of the hostnames but the only reason for this seems to be which hostname
    happens to be used first in peering.

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.peer_status

    GLUSTER direct CLI example (to show what salt is sending to gluster):

        $ gluster peer status

    GLUSTER CLI 3.4.4 return example (so we know what we are parsing):

        Number of Peers: 2

        Hostname: ftp2
        Port: 24007
        Uuid: cbcb256b-e66e-4ec7-a718-21082d396c24
        State: Peer in Cluster (Connected)

        Hostname: ftp3
        Uuid: 5ea10457-6cb2-427b-a770-7897509625e9
        State: Peer in Cluster (Connected)


    upeer statusupeeruuuidu	hostnamesuhostnameN(R,RR&R8RRR/tappend(R*Rtpeertuuidtitemthostname((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytpeer_status�s""

"cC@sItjjj|d�r0tdj|���ndj|�}t|�S(u�
    Add another node into the peer list.

    name
        The remote host to probe.

    CLI Example:

    .. code-block:: bash

        salt 'one.gluster.*' glusterfs.peer two

    GLUSTER direct CLI example (to show what salt is sending to gluster):

        $ gluster peer probe ftp2

    GLUSTER CLI 3.4.4 return example (so we know what we are parsing):
        #if the "peer" is the local host:
        peer probe: success: on localhost not needed

        #if the peer was just added:
        peer probe: success

        #if the peer was already part of the cluster:
        peer probe: success: host ftp2 port 24007 already in peer list



    ua-zA-Z0-9._-u%Invalid characters in peer name "{0}"upeer probe {0}(RRtcloudt
check_nameRR!R-(tnameR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyR:�s
utcpc	
C@s�t|tj�r|g}n|rIt|�dkrItdd��nxw|D]o}	y@|	jd�\}
}|jd�s�tdj|	���nWqPtk
r�tdj|	���qPXqPW|r�|dkr�td	d
��ndj|�}|r|dj|�7}n|r/|d
j|�7}n|rB|d7}n|rU|d7}n|dkrw|dj|�7}n|dj	|�7}|r�|d7}nt
|�s�tS|r�t|�St
S(u�
    Create a glusterfs volume

    name
        Name of the gluster volume

    bricks
        Bricks to create volume from, in <peer>:<brick path> format. For         multiple bricks use list format: '["<peer1>:<brick1>",         "<peer2>:<brick2>"]'

    stripe
        Stripe count, the number of bricks should be a multiple of the stripe         count for a distributed striped volume

    replica
        Replica count, the number of bricks should be a multiple of the         replica count for a distributed replicated volume

    arbiter
        If true, specifies volume should use arbiter brick(s).         Valid configuration limited to "replica 3 arbiter 1" per         Gluster documentation. Every third brick in the brick list         is used as an arbiter brick.

        .. versionadded:: 2019.2.0

    device_vg
        If true, specifies volume should use block backend instead of regular         posix backend. Block device backend volume does not support multiple         bricks

    transport
        Transport protocol to use, can be 'tcp', 'rdma' or 'tcp,rdma'

    start
        Start the volume after creation

    force
        Force volume creation, this works even if creating in root FS

    CLI Examples:

    .. code-block:: bash

        salt host1 glusterfs.create newvolume host1:/brick

        salt gluster1 glusterfs.create vol2 '["gluster1:/export/vol2/brick",         "gluster2:/export/vol2/brick"]' replica=2 start=True
    iu%Block device backend volume does not usupport multiple bricksu:u/u$Brick paths must start with / in {0}u%Brick syntax is <peer>:<path> got {0}iu!Arbiter configuration only valid uin replica 3 volumeuvolume create {0} ustripe {0} ureplica {0} u
arbiter 1 u
device vg utcputransport {0} u u force(t
isinstanceRtstring_typestlenRRRR!t
ValueErrorR%R-Rtstart_volumeR
(
RAtbrickststripetreplicat	device_vgt	transporttstarttforcetarbitertbrickt	peer_nameRR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt
create_volume�sH5







cC@sEtd�}t|�sdSgt|d�D]}|j^q,}|S(uv
    List configured volumes

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.list_volumes
    uvolume listuvolumeN(R,RR&R8R(R*txtresults((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytlist_volumesAs
%c
C@s�tdj|��}t|�s%d
Siid6id6id6}d�}i}xTt|d�D]C}|jd�j}|jd�j}|dkr_|||<q_q_Wx�t|d�D]�}|jd�j}|dkr|jd�j}||�|ddj||�<q�|d	krN|jd�j}||}	||�|d|	<q�|jd�j}||}	||�|d|	<q�W|S(u�
    Check the status of a gluster volume.

    name
        Volume name

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.status myvolume
    uvolume status {0}ubricksunfsuhealerscS@s2t|�}|ddk|d<|d|d<|S(Nustatusu1uonlineuhostnameuhost(R.(R0R((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytetree_legacy_wrapisunodeupeeriduhostnameu
NFS ServeruSelf-heal Daemonupathu{0}:{1}N(u
NFS ServeruSelf-heal Daemon(u
NFS ServeruSelf-heal Daemon(R,R!RR&R8RR(
RAR*RRUthostreftnodetpeeridR=Rt
true_hostname((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytstatusSs0	#

cC@s�d}|dk	r#|d|7}nt|�}t|�s?dSi}xXt|d�D]G}|jd�j}t|�||<i}x�tt|d�dd�D]�\}}dj|�}i|jd	6||<x>|D]6}	|	j	dks�||j
i|	j|	j	6�q�q�Wx(|j�D]\}
}||||
<qWq�W|||d
<i}x9t|d�D](}
|
jd�j||
jd�j<qbW|||d
<qUW|S(u�
    .. versionadded:: 2015.8.4

    Return gluster volume info.

    name
        Optional name to retrieve only information of one volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.info
    uvolume infou uvolumeunameubrickRLiubrick{0}upathubricksuoptionuvalueuoptionsN(R&R,RR8RRR.t	enumerateR!R/tupdatetitems(RARR*RtvolumeRGRROtbrickkeyR2tktvtoptionstoption((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyR(�s2(
%&cC@s�dj|�}|r'dj|�}nt|�}||krStjd|�tS|r�||ddkr�tjd|�tSt|�S(u
    Start a gluster volume

    name
        Volume name

    force
        Force the volume start even if the volume is started
        .. versionadded:: 2015.8.4

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.start mycluster
    uvolume start {0}u	{0} forceu#Cannot start non-existing volume %sustatusu1uVolume %s already started(R!R(R'R)RR
R-(RARMRtvolinfo((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyRF�scC@s�t�}||kr)tjd|�tSt||d�dkrWtjd|�tSdj|�}|ry|d7}nt|�S(u�
    Stop a gluster volume

    name
        Volume name

    force
        Force stop the volume

        .. versionadded:: 2015.8.4

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.stop_volume mycluster
    u"Cannot stop non-existing volume %sustatusiu)Attempt to stop already stopped volume %suvolume stop {0}u force(	R(R'R)RRtwarningR
R!R-(RARMRdR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytstop_volume�s	
cC@s�t�}||kr)tjd|�tS||ddk}|r^|r^tjd|�tS|r}t|dt�s}tSndj|�}t|�S(u�
    Deletes a gluster volume

    target
        Volume to delete

    stop : True
        If ``True``, stop volume before delete

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.delete_volume <volume>
    u$Cannot delete non-existing volume %sustatusu1u)Volume %s must be stopped before deletionRMuvolume delete {0}(R(R'R)RRfR
R!R-(ttargettstopRdtrunningR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt
delete_volume�s	
cC@st�}||kr)tjd|�tSg}dj|�}t|tj�r\|g}ng||dj�D]}|d^qq}x=|D]5}||kr�tj	d||�q�|j
|�q�Wt|�dkrx!|D]}|dj|�7}q�Wt|�St
S(u�
    Add brick(s) to an existing volume

    name
        Volume name

    bricks
        List of bricks to add to the volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.add_volume_bricks <volume> <bricks>
    u+Volume %s does not exist, cannot add bricksuvolume add-brick {0}ubricksupathu6Brick %s already in volume %s...excluding from commandiu {0}(R(R'R)RR!RBRRCtvaluestdebugR9RDR-R
(RARGRdt
new_bricksRRRt
volume_bricksRO((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytadd_volume_brickss*	+



cC@s#dj|�}t|�stStS(u�
    Enable quota on a glusterfs volume.

    name
        Name of the gluster volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.enable_quota_volume <volume>
    uvolume quota {0} enable(R!R-RR
(RAR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytenable_quota_volumeNscC@s#dj|�}t|�stStS(u�
    Disable quota on a glusterfs volume.

    name
        Name of the gluster volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.disable_quota_volume <volume>
    uvolume quota {0} disable(R!R-RR
(RAR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytdisable_quota_volumebscC@ssdj|�}|r+|dj|�7}n|rG|dj|�7}n|r_t|�s_q_nt|�sotStS(u�
    Set quota to glusterfs volume.

    name
        Name of the gluster volume

    path
        Folder path for restriction in volume ("/")

    size
        Hard-limit size of the volume (MB/GB)

    enable_quota
        Enable quota before set up restriction

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.set_quota_volume <volume> <path> <size> enable_quota=True
    uvolume quota {0}u limit-usage {0}u {0}(R!RpR-RR
(RARtsizetenable_quotaR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytset_quota_volumevscC@s?dj|�}|r+|dj|�7}nt|�s;tStS(u�
    Unset quota on glusterfs volume

    name
        Name of the gluster volume

    path
        Folder path for restriction in volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.unset_quota_volume <volume> <path>
    uvolume quota {0}u remove {0}(R!R-RR
(RARR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytunset_quota_volume�scC@s{dj|�}|d7}t|�}t|�s5dSi}x9t|d�D](}|jd�j}t|�||<qKW|S(u�
    List quotas of glusterfs volume

    name
        Name of the gluster volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.list_quota_volume <volume>
    uvolume quota {0}u listulimitupathN(R!R,RR&R8RRR.(RARR*RtlimitR((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytlist_quota_volume�s

cC@s�dj|�}t|�}t|�s=t|jd�jfSi}x�t|d�D]p}xg|D]_}|jdkr�|j}q`|jdkr`x,|D]!}|jdkr�|j}q�q�Wq`q`WqSW|S(u�
    .. versionadded:: 2019.2.0

    Returns the glusterfs volume op-version

    name
        Name of the glusterfs volume

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.get_op_version <volume>
    u!volume get {0} cluster.op-versionuopErrstru
volGetoptsuValueuOpt(R!R,RRRRR8R/(RARR*Rt
op_versionR<R2((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytget_op_version�s

cC@st�dkr>tdjtdjd�t�D����fSd}t|�}t|�srt|jd�jfSi}x�t	|d�D]p}xg|D]_}|j
d	kr�|j}q�|j
d
kr�x,|D]!}|j
d	kr�|j}q�q�Wq�q�Wq�W|S(u�
    .. versionadded:: 2019.2.0

    Returns the glusterfs volume's max op-version value
    Requires Glusterfs version > 3.9

    CLI Example:
    .. code-block:: bash

        salt '*' glusterfs.get_max_op_version
    ii
u6Glusterfs version must be 3.10+.  Your version is {0}.u.cs@s|]}t|�VqdS(N(tstr(t.0R((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pys	<genexpr>�su%volume get all cluster.max-op-versionuopErrstru
volGetoptsuValueuOpt(ii
(RRR!RzR%R,RRRR8R/(RR*Rtmax_op_versionR<R2((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytget_max_op_version�s /

cC@sMdj|�}t|�}t|�s=t|jd�jfS|jd�jS(u�
    .. versionadded:: 2019.2.0

    Set the glusterfs volume op-version

    version
        Version to set the glusterfs volume op-version

    CLI Example:

    .. code-block:: bash

        salt '*' glusterfs.set_op_version <volume>
    u%volume set all cluster.op-version {0}uopErrstruoutput(R!R,RRRR(RRR*((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytset_op_versions
cC@sdjt��S(u�
    .. versionadded:: 2019.2.0

    Returns the version of glusterfs.
    CLI Example:
    .. code-block:: bash

        salt '*' glusterfs.get_version
    u.(R%R(((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pytget_version-s(4t__doc__t
__future__RRRtloggingR3txml.etree.ElementTreetetreetElementTreeR"tsalt.utils.cloudRtsalt.utils.pathtsalt.exceptionsRRtsalt.extRt	getLoggert__name__R'RRRRR,R-R.R8R>R:RRQRTRZR&R(RFRfR
RjRoRpRqRtRuRwRyR}R~R(((s:/usr/lib/python2.7/site-packages/salt/modules/glusterfs.pyt<module>sJ						%			
	6	&	d		6/!!%	/		$			#	"	

Zerion Mini Shell 1.0