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

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZ	ddl
mZmZddl
mZeje�Zidd6ZdZd	�Zd
�Zdd�Zd
�Zd�Zded�Zd�Zed�Zd�Zd�ZdS(u.
Salt module to manage RAID arrays with mdadm
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortSaltInvocationError(tsixulistulist_uraidcC@s=tddkrtdfStjjjd�s9tdfStS(u1
    mdadm provides raid functions for Linux
    ukerneluLinuxuEThe mdadm execution module cannot be loaded: only available on Linux.umdadmuQThe mdadm execution module cannot be loaded: the mdadm binary is not in the path.(t
__grains__tFalsetsalttutilstpathtwhicht__virtualname__(((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pyt__virtual__ s


cC@s�i}x�tddddgdt�j�D]�}d|krDq,n|j�}|d}i|d6||<xL|d	D]@}|jd
�dj�}|jd
�d}||||<qvWq,W|S(uh
    List the RAID devices.

    CLI Example:

    .. code-block:: bash

        salt '*' raid.list
    ucmd.run_stdoutumdadmu--detailu--scantpython_shellu iudeviceiu=i(t__salt__Rt
splitlinestsplittlower(trettlinetcompstdevicetcomptkeytvalue((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytlist_+s


u/dev/md0cC@s�i}i|d<tjj|�s@d}t|j|���ndd|g}xGtd|dt�j�D])}|j|�r�qlnd|kr�qlnd|kr,d	|krl|j	�}|d
d!}i|dd6|d
d6|dd6|dd6|dd6dj
|�d6|d|d<qlqln|j	d�}|dj�|d<|dj�|d<|dj
dd�|d<|d
j�||d<qlW|S(u�
    Show detail for a specified RAID device

    CLI Example:

    .. code-block:: bash

        salt '*' raid.detail '/dev/md0'
    umembersuDevice {0} doesn't exist!umdadmu--detailucmd.run_stdoutRu u:u/dev/ii����udeviceiumajoriuminoriunumberiu
raiddeviceustateu : u_(tosR
texistsRtformatRRRt
startswithRtjoinRtstriptreplace(RRtmsgtcmdRRtstate((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytdetailEs:

#
"cC@syt|�}Wntk
r$tSXdd|g}ddg}td|dt�r�x+|dD]}|j|d|d�qaWtd|dt�ntjd�d	kr�d
}nd}y!td|d
j|�d�Wntk
r�nXtd�j|�dkrt
StSdS(u�
    Destroy a RAID device.

    WARNING This will zero the superblock of all members of the RAID array..

    CLI Example:

    .. code-block:: bash

        salt '*' raid.destroy /dev/md0
    umdadmu--stopu--zero-superblockucmd.retcodeRumembersudeviceu	os_familyuDebianu/etc/mdadm/mdadm.confu/etc/mdadm.confufile.replaceuARRAY {0} .*uu	raid.listN(R%RRRtappendRtgetRRtNonetTrue(Rtdetailststop_cmdtzero_cmdtnumbertcfg_file((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytdestroyrs(
	!
cC@sd}td|�rtStS(u�
    Shut down all arrays that can be shut down (i.e. are not currently in use).

    CLI Example:

    .. code-block:: bash

        salt '*' raid.stop
    umdadm --stop --scanucmd.retcode(RR)R(R#((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytstop�s
udefaultcK@s#g}t|�}x�|D]~}|jd�st|jdj|��||tk	rt|jtj||��qtn|dkr|t||�8}qqWdd|dddtj|�g|d	|d
tj|�g|}	dj|	�}
|tkr�|
S|t	krt
d|	d
t	�SdS(u
    Create a RAID device.

    .. versionchanged:: 2014.7.0

    .. warning::
        Use with CAUTION, as this function can be very destructive if not used
        properly!

    CLI Examples:

    .. code-block:: bash

        salt '*' raid.create /dev/md0 level=1 chunk=256 devices="['/dev/xvdd', '/dev/xvde']" test_mode=True

    .. note::

        Adding ``test_mode=True`` as an argument will print out the mdadm
        command that would have been run.

    name
        The name of the array to create.

    level
        The RAID level to use when creating the raid.

    devices
        A list of devices used to build the array.

    metadata
        Version of metadata to use when creating the array.

    kwargs
        Optional arguments to be passed to mdadm.

    returns
        test_mode=True:
            Prints out the full command.
        test_mode=False (Default):
            Executes command on remote the host(s) and
            Prints out the mdadm output.

    .. note::

        It takes time to create a RAID array. You can check the progress in
        "resync_status:" field of the results from the following command:

        .. code-block:: bash

            salt '*' raid.detail /dev/md0

    For more info, read the ``mdadm(8)`` manpage
    u__u--{0}u
spare-devicesumdadmu-Cu-Ru-vu-lu-eu-nu ucmd.runRN(tlenRR&RR)Rt	text_typetintRRR(tnametleveltdevicestmetadatat	test_modetkwargstoptstraid_devicesRR#tcmd_str((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytcreate�s;
 
Ec
C@s�tdddt�j�}tddkr�ddg}x{t|�D]j\}}x[|D]S}djtj|��}tj|d	tj	�}tj
|d
||�||<qXWqEWntjd�dkr�d
}nd}yztg|D]}|j
�d|f^q��}xD|D]<}	djtj|	��}td||||	dt�qWWn%tk
r{td|d|�nXtjd�dkr�tdd�Stjd�dkr�tdd�SdS(u^
    Save RAID configuration to config file.

    Same as:
    mdadm --detail --scan >> /etc/mdadm/mdadm.conf

    Fixes this issue with Ubuntu
    REF: http://askubuntu.com/questions/209702/why-is-my-raid-dev-md1-showing-up-as-dev-md126-is-mdadm-conf-being-ignored

    CLI Example:

    .. code-block:: bash

        salt '*' raid.save_config

    ucmd.runumdadm --detail --scanRuosuUbuntuunameumetadatau	\s{0}=\S+tflagsuu	os_familyuDebianu/etc/mdadm/mdadm.confu/etc/mdadm.confiu^ARRAY\s+{0}.*$ufile.replacetappend_if_not_foundu
file.writetargsuupdate-initramfs -uuRedHatudracut --forceN(RRRRt	enumerateRtretescapetcompiletItsubR'tdictRR)R(
tscantbuggy_ubuntu_tagstitelemtbad_tagtpatternR.Rtvol_dtvol((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytsave_configs,
(	/
&
cK@s�g}xZ|D]R}|jd�s
|jdj|��||tk	r_|j||�q_q
q
Wt|tj�r�|jd�}ndd|dg||}|tkr�|S|tkr�t	d|dt�Sd	S(
u�
    Assemble a RAID device.

    CLI Examples:

    .. code-block:: bash

        salt '*' raid.assemble /dev/md0 ['/dev/xvdd', '/dev/xvde']

    .. note::

        Adding ``test_mode=True`` as an argument will print out the mdadm
        command that would have been run.

    name
        The name of the array to assemble.

    devices
        The list of devices comprising the array to assemble.

    kwargs
        Optional arguments to be passed to mdadm.

    returns
        test_mode=True:
            Prints out the full command.
        test_mode=False (Default):
            Executes command on the host(s) and prints out the mdadm output.

    For more info, read the ``mdadm`` manpage.
    u__u--{0}u,umdadmu-Au-vucmd.runRN(
RR&RR)t
isinstanceRtstring_typesRRR(R4R6R8R9R:RR#((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytassemble5s#
cC@srtddj|�dddt�}i}x@|j�D]2}|jd�ddd�\}}|||<q8W|S(	u�
    Show detail for a specified RAID component device

    CLI Example:

    .. code-block:: bash

        salt '*' raid.examine '/dev/sda1'
    ucmd.run_stdoutumdadm -Y -E {0}toutput_loglevelutraceRu=Ni(RRRRt	partition(RtresRRR4tvar((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytexamineks
%"cC@s0dj||�}td|�dkr,tStS(u�
    Add new device to RAID array.

    CLI Example:

    .. code-block:: bash

        salt '*' raid.add /dev/md0 /dev/sda1

    umdadm --manage {0} --add {1}ucmd.retcodei(RRR)R(R4RR#((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pytadd~s(t__doc__t
__future__RRRRtloggingRBtsalt.utils.pathRtsalt.exceptionsRRtsalt.extRt	getLoggert__name__tlogt__func_alias__RR
RR%R/R0RR=RPRSRXRY(((s;/usr/lib/python2.7/site-packages/salt/modules/mdadm_raid.pyt<module>s,
		-	*	T	14	

Zerion Mini Shell 1.0