Mini Shell

Direktori : /lib/python3.6/site-packages/blivet/devicelibs/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/blivet/devicelibs/__pycache__/raid.cpython-36.pyc

3

{)c�_�@s�ddlZddlmZddlmZddlmZdd�Zeej�Gdd	�d	e	��Z
eej�Gd
d�de
��ZGdd
�d
e	�Ze�Z
Gdd�de�ZGdd�de�Ze�Ze
je�e�Ze
je�Gdd�de�Ze�Ze
je�Gdd�de�Ze�Ze
je�Gdd�de�Ze�Ze
je�Gdd�de�Ze�Ze
je�Gdd�de�Ze�Ze
je�Gdd�de
�Ze�Ze
je�Gdd�de
�ZGd d!�d!e�Ze�Ze
je�Gd"d#�d#e�Ze�Ze
je�Gd$d%�d%e
�Ze�Ze
je�d&d'�ZdS)(�N)�
add_metaclass�)�	RaidError)�SizecCs||d|S)z�Rounds up integer division.  For example, div_up(3, 2) is 2.

       :param int a: the dividend
       :param int b: the divisor
    ��)�a�brr�/usr/lib/python3.6/raid.py�div_up src@sfeZdZdZejdd�Zejdd�Zejdd�Zej	dd��Z
ejdd�Zd	d
�Zdd�Z
d
d�ZdS)�	RAIDLevelz�An abstract class which is the parent of all classes which represent
       a RAID level.

       It ensures that RAIDLevel objects will really be singleton objects
       by overriding copy methods.
    z!The canonical name for this level)�docz(List of recognized names for this level.zIThe minimum number of members required to make a fully functioning array.cCs
t��dS)a Whether this RAID level incorporates inherent redundancy.

            Note that for some RAID levels, the notion of redundancy is
            meaningless.

            :rtype: boolean
            :returns: True if this RAID level has inherent redundancy
        N)�NotImplementedError)�selfrrr
�has_redundancy7s
zRAIDLevel.has_redundancyz9Whether data is uniformly distributed across all devices.cCs|jS)N)�name)rrrr
�__str__EszRAIDLevel.__str__cCs|S)Nr)rrrr
�__copy__HszRAIDLevel.__copy__cCs|S)Nr)r�memorrr
�__deepcopy__KszRAIDLevel.__deepcopy__N)�__name__�
__module__�__qualname__�__doc__�abc�abstractpropertyr�names�min_members�abstractmethodr�
is_uniformrrrrrrr
r)src@s�eZdZdZejdd�Zejdd�Zedd��Z	edd�dd�Z
ed	d�d
d�Zedd�dd�Zed
d�dd�Z
dd�Zejdd��Zdd�Zejdd��Zdd�Zejdd��Zejdd��Zejdd��Zdd �Zejd!d"��Zd(d$d%�Zd)d&d'�Zd#S)*�RAIDna An abstract class which is the parent of classes which represent a
       numeric RAID level. A better word would be classification, since 'level'
       implies an ordering, but level is the canonical word.

       The abstract properties of the class are:

       - level: A string containing the number that designates this level

       - nick: A single nickname for this level, may be None

        All methods in this class fall into these categories:

        1) May not be overrridden in any subclass.

        2) Are private abstract methods.

        3) Are special Python methods, e.g., __str__


        Note that each subclass in this file is instantiated immediately after
        it is defined and using the same name, effectively yielding a
        singleton object of the class.
    zA code representing the level)r
zA nickname for this levelcCsdS)NTr)�srrr
�<lambda>pszRAIDn.<lambda>cCs
t|j�S)N)�int�level)r!rrr
r"rszA numeric code for this levelcCs
d|jS)NZraid)r$)r!rrr
r"usz!The canonical name for this levelcCsd|j|j|jgS)NZRAID)r$�number)r!rrr
r"xsz9names that can be synthesized from level but are not namecCs dd�|jg|jg|jD�S)NcSsg|]}|dk	r|�qS)Nr)�.0�nrrr
�
<listcomp>|sz"RAIDn.<lambda>.<locals>.<listcomp>)r�nick�alt_synth_names)r!rrr
r"{szall valid names for this levelcCs(||jkrtd|j|jf��|j|�S)aThe maximum number of spares for this level.

           :param int member_count: the number of members belonging to the array
           :rtype: int

           Raiess a RaidError if member_count is fewer than the minimum
           number of members required for this level.
        z%s requires at least %d disks)rrr�_get_max_spares)r�member_countrrr
�get_max_spares�s	
zRAIDn.get_max_sparescCs
t��dS)z+Helper function; not to be called directly.N)r)rr,rrr
r+�szRAIDn._get_max_sparescCs:||jkrtd|j|jf��|dkr.td��|j||�S)a�The required size for each member of the array for
           storing only data.

           :param size: size of data to be stored
           :type size: :class:`~.size.Size`
           :param int member_count: number of members in this array
           :rtype: :class:`~.size.Size`

           Raises a RaidError if member_count is fewer than the minimum
           number of members required for this array or if size is less
           than 0.
        z%s requires at least %d disksrzsize is a negative number)rrr�_get_base_member_size)r�sizer,rrr
�get_base_member_size�s

zRAIDn.get_base_member_sizecCs
t��dS)z+Helper function; not to be called directly.N)r)rr/r,rrr
r.�szRAIDn._get_base_member_sizecCs>||jkrtd|j|jf��|td�kr2td��|j||�S)aReturn the space, essentially the number of bits available
           for storage. This value is generally a function of the
           smallest member size. If the smallest member size represents
           the amount of data that can be stored on the smallest member,
           then the result will represent the amount of data that can be
           stored on the array. If the smallest member size represents
           both data and metadata, then the result will represent the
           available space in the array for both data and metadata.

           :param int member_count: the number of members in the array
           :param smallest_member_size: the size of the smallest
             member of this array
           :type smallest_member_size: :class:`~.size.Size`
           :returns: the array size
           :rtype: :class:`~.size.Size`

           Raises a RaidError if member_count is fewer than the minimum
           number of members required for this array or if size is less
           than 0.
        z%s requires at least %d disksrzsize is a negative number)rrrr�_get_net_array_size)rr,�smallest_member_sizerrr
�get_net_array_size�s

zRAIDn.get_net_array_sizecCs
t��dS)z+Helper function; not to be called directly.N)r)rr,r2rrr
r1�szRAIDn._get_net_array_sizecCs
t��dS)a�Helper function; not to be called directly.

           Trims size to the largest size that the level allows based on the
           chunk_size.

           :param size: the size of the array
           :type size: :class:`~.size.Size`
           :param chunk_size: the smallest unit of size this array allows
           :type chunk_size: :class:`~.size.Size`
           :rtype: :class:`~.size.Size`
        N)r)rr/�
chunk_sizerrr
�_trim�s
zRAIDn._trimcCs
t��dS)a�Helper function; not to be called directly.

           Pads size to the smallest size greater than size that is in units
           of chunk_size.

           :param size: the size of the array
           :type size: :class:`~.size.Size`
           :param chunk_size: the smallest unit of size this array allows
           :type chunk_size: :class:`~.size.Size`
           :rtype: :class:`~.size.Size`
        N)r)rr/r4rrr
�_pad�s
z
RAIDn._padcCs(||jkrtd|j|jf��|j|�S)aSReturn a recommended stride size in blocks.

           Returns None if there is no recommended size.

           :param int member_count: the number of members in the array
           :rtype: int or None

           Raises a RaidError if member_count is fewer than the
           minimum number of members required for this level
        z%s requires at least %d disks)rrr�_get_recommended_stride)rr,rrr
�get_recommended_stride�s
zRAIDn.get_recommended_stridecCs
t��dS)z+Helper function; not to be called directly.N)r)rr,rrr
r7�szRAIDn._get_recommended_strideNcCst|std�S|dkrt|�}|dks0|td�kr8td��|dkrHtd��t|�}||�}|j|||�}|j||�S)a�Estimate the amount of data that can be stored on this array.

           :param member_size: a list of the sizes of members of this array
           :type member_size: list of :class:`~.size.Size`
           :param int num_members: the number of members in the array
           :param chunk_size: the smallest unit of size read or written
           :type chunk_size: :class:`~.size.Size`
           :param superblock_size_func: a function that estimates the
              superblock size for this array
           :type superblock_size_func: a function from :class:`~.size.Size` to
              :class:`~.size.Size`
           :returns: an estimate of the amount of data that can be stored on
              this array
           :rtype: :class:`~.size.Size`

           Note that the number of members in the array may not be the same
           as the length of member_sizes if the array is still
           under construction.
        rNz/chunk_size parameter value %s is not acceptablez4superblock_size_func value of None is not acceptable)r�lenr�minr5r3)r�member_sizes�num_membersr4�superblock_size_func�min_size�superblock_size�
min_data_sizerrr
�get_size�szRAIDn.get_sizecCsD|dkrtd��|j||�}|||�7}|dk	r<|j||�}||S)a�Estimate the amount of memory required by this array, including
           memory allocated for metadata.

           :param size: the amount of data on this array
           :type size: :class:`~.size.Size`
           :param int num_members: the number of members in the array
           :param chunk_size: the smallest unit of size read or written
           :type chunk_size: :class:`~.size.Size`
           :param superblock_size_func: a function that estimates the
              superblock size for this array
           :type superblock_size_func: a function from :class:`~.size.Size` to
              :class:`~.size.Size`
           :returns: an estimate of the memory required, including metadata
           :rtype: :class:`~.size.Size`
        Nz4superblock_size_func value of None is not acceptable)rr0r6)rr/r<r4r=Zsize_per_memberrrr
�	get_space!szRAIDn.get_space)NNN)NN)rrrrrrr$r)�propertyrr%rr*rr-rr+r0r.r3r1r5r6r8r7rArBrrrr
r Ps0

%r c@s>eZdZdZd
dd�Zedd��Zdd�Zd	d
�Zdd�Z	dS)�
RAIDLevelsz�A class which keeps track of registered RAID levels. This class
       may be extended, overriding the is_raid method to include any
       additional properties that a client of this package may require
       for its RAID levels.
    Ncs\|pg}t�|_xF|D]>��fdd�tD�}t|�dkrFtd���q|j|d�qWdS)a�Add the specified standard levels to the levels in this object.

           :param levels: the levels to be added to this object
           :type levels: list of valid RAID level descriptors

           If levels is True, add all standard levels. Else, levels
           must be a list of valid level descriptors of standard levels.
           Duplicate descriptors are ignored.
        csg|]}�|jkr|�qSr)r)r&�l)r$rr
r(Psz'RAIDLevels.__init__.<locals>.<listcomp>rz)invalid standard RAID level descriptor %srN)�set�_raid_levels�
ALL_LEVELSr9r�add_raid_level)rZlevelsZmatchesr)r$r
�__init__Cs

zRAIDLevels.__init__cCst|j�dko|j|jkS)a�Return False if level does not satisfy minimum requirements for
           a RAID level, otherwise return True.

           :param object level: an object representing a RAID level

           There must be at least one element in the names list, or the level
           will be impossible to look up by any string.

           The name property must be defined; it should be one of the
           elements in the names list.

           All RAID objects that extend RAIDlevel are guaranteed to pass these
           minimum requirements.

           This method should not be overridden in any subclass so that it
           is so restrictive that a RAIDlevel object does not satisfy it.
        r)r9rr)�clsr$rrr
�
is_raid_levelVszRAIDLevels.is_raid_levelcCs6x$|jD]}||jks||kr|SqWtd|��dS)aRReturn RAID object corresponding to descriptor.

           :param object descriptor: a RAID level descriptor

           Note that descriptor may be any object that identifies a
           RAID level, including the RAID object itself.

           Raises a RaidError if no RAID object can be found for this
           descriptor.
        z invalid RAID level descriptor %sN)rGrr)r�
descriptorr$rrr
�
raid_levelkszRAIDLevels.raid_levelcCs"|j|�std��|jj|�dS)z�Adds level to levels if it is not already there.

           :param object level: an object representing a RAID level

           Raises a RaidError if level is not valid.

           Does not allow duplicate level objects.
        zlevel is not a valid RAID levelN)rLrrG�add)rr$rrr
rI{s	
zRAIDLevels.add_raid_levelcCs
t|j�S)N)�iterrG)rrrr
�__iter__�szRAIDLevels.__iter__)N)
rrrrrJ�classmethodrLrNrIrQrrrr
rD;s

rDc@sheZdZedd��Zedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�RAID0cCsdS)N�0r)r!rrr
r"�szRAID0.<lambda>cCsdS)Nrr)r!rrr
r"�scCsdS)NZstriper)r!rrr
r"�scCsdS)NFr)rrrr
r�szRAID0.has_redundancycCsdS)Nrr)rr,rrr
r+�szRAID0._get_max_sparescCs
t||�S)N)r)rr/r,rrr
r.�szRAID0._get_base_member_sizecCs||S)Nr)rr,r2rrr
r1�szRAID0._get_net_array_sizecCs|||S)Nr)rr/r4rrr
r5�szRAID0._trimcCs|||||S)Nr)rr/r4rrr
r6�sz
RAID0._padcCs|dS)N�r)rr,rrr
r7�szRAID0._get_recommended_strideN)rrrrCr$rr)rr+r.r1r5r6r7rrrr
rS�srSc@seZdZdZdZegZdS)�Stripedz" subclass with canonical lvm name ZstripedN)rrrrrrrrrr
rV�srVc@sreZdZedd��Zedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
ddd�ZdS)�RAID1cCsdS)N�1r)r!rrr
r"�szRAID1.<lambda>cCsdS)Nrr)r!rrr
r"�scCsdS)NZmirrorr)r!rrr
r"�scCsdS)NTr)rrrr
r�szRAID1.has_redundancycCs
||jS)N)r)rr,rrr
r+�szRAID1._get_max_sparescCs|S)Nr)rr/r,rrr
r.�szRAID1._get_base_member_sizecCs|S)Nr)rr,r2rrr
r1�szRAID1._get_net_array_sizecCs|S)Nr)rr/r4rrr
r5�szRAID1._trimcCs|S)Nr)rr/r4rrr
r6�sz
RAID1._padcCsdS)Nr)rr,rrr
r7�szRAID1._get_recommended_strideNcCsH|std�S|dkrt|�}t|�}||�}|j|||�}|j||�S)Nr)rr9r:r5r3)rr;r<r4r=r>r?r@rrr
rA�szRAID1.get_size)NNN)rrrrCr$rr)rr+r.r1r5r6r7rArrrr
rW�srWc@sheZdZedd��Zedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�RAID4cCsdS)N�4r)r!rrr
r"�szRAID4.<lambda>cCsdS)N�r)r!rrr
r"�scCsdS)Nr)r!rrr
r"�scCsdS)NTr)rrrr
r�szRAID4.has_redundancycCs
||jS)N)r)rr,rrr
r+�szRAID4._get_max_sparescCst||d�S)Nr)r)rr/r,rrr
r.�szRAID4._get_base_member_sizecCs||dS)Nrr)rr,r2rrr
r1�szRAID4._get_net_array_sizecCs|||S)Nr)rr/r4rrr
r5�szRAID4._trimcCs|||||S)Nr)rr/r4rrr
r6�sz
RAID4._padcCs|ddS)NrrUr)rr,rrr
r7�szRAID4._get_recommended_strideN)rrrrCr$rr)rr+r.r1r5r6r7rrrr
rY�srYc@sheZdZedd��Zedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�RAID5cCsdS)N�5r)r!rrr
r"szRAID5.<lambda>cCsdS)Nr[r)r!rrr
r"scCsdS)Nr)r!rrr
r"scCsdS)NTr)rrrr
rszRAID5.has_redundancycCs
||jS)N)r)rr,rrr
r+	szRAID5._get_max_sparescCst||d�S)Nr)r)rr/r,rrr
r.szRAID5._get_base_member_sizecCs||dS)Nrr)rr,r2rrr
r1szRAID5._get_net_array_sizecCs|||S)Nr)rr/r4rrr
r5szRAID5._trimcCs|||||S)Nr)rr/r4rrr
r6sz
RAID5._padcCs|ddS)NrrUr)rr,rrr
r7szRAID5._get_recommended_strideN)rrrrCr$rr)rr+r.r1r5r6r7rrrr
r\sr\c@sheZdZedd��Zedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�RAID6cCsdS)N�6r)r!rrr
r"!szRAID6.<lambda>cCsdS)N�r)r!rrr
r""scCsdS)Nr)r!rrr
r"#scCsdS)NTr)rrrr
r%szRAID6.has_redundancycCs
||jS)N)r)rr,rrr
r+(szRAID6._get_max_sparescCst||d�S)Nr)r)rr/r,rrr
r.+szRAID6._get_base_member_sizecCs||dS)Nrr)rr,r2rrr
r1.szRAID6._get_net_array_sizecCs|||S)Nr)rr/r4rrr
r51szRAID6._trimcCs|||||S)Nr)rr/r4rrr
r64sz
RAID6._padcCsdS)Nr)rr,rrr
r77szRAID6._get_recommended_strideN)rrrrCr$rr)rr+r.r1r5r6r7rrrr
r^ sr^c@sheZdZedd��Zedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�RAID10cCsdS)NZ10r)r!rrr
r"@szRAID10.<lambda>cCsdS)Nr`r)r!rrr
r"AscCsdS)Nr)r!rrr
r"BscCsdS)NTr)rrrr
rDszRAID10.has_redundancycCs
||jS)N)r)rr,rrr
r+GszRAID10._get_max_sparescCst||d�S)Nr)r)rr/r,rrr
r.JszRAID10._get_base_member_sizecCs||dS)Nrr)rr,r2rrr
r1MszRAID10._get_net_array_sizecCs|S)Nr)rr/r4rrr
r5PszRAID10._trimcCs|||||S)Nr)rr/r4rrr
r6SszRAID10._padcCsdS)Nr)rr,rrr
r7VszRAID10._get_recommended_strideN)rrrrCr$rr)rr+r.r1r5r6r7rrrr
ra?srac@s^eZdZdZegZdZedd��Zedd��Zdd�Z	dd	�Z
ddd�Zd
d�Zddd�Z
d
S)�	ContainerZ	containerrcCsdS)Nr)r!rrr
r"bszContainer.<lambda>cCsdS)NFr)r!rrr
r"cscCstd��dS)Nz6redundancy is not a concept that applies to containers)r)rrrr
reszContainer.has_redundancycCstd��dS)Nz1get_max_spares is not defined for level container)r)rr,rrr
r-hszContainer.get_max_sparesNcCs|S)Nr)rr/r<r4r=rrr
rBlszContainer.get_spacecCstd��dS)Nz9get_recommended_stride is not defined for level container)r)rr,rrr
r8psz Container.get_recommended_stridecCst|td��S)Nr)�sumr)rr;r<r4r=rrr
rAtszContainer.get_size)NN)NNN)rrrrrrrCr)rrr-rBr8rArrrr
rb^s
rbc@sXeZdZdZdZedd��Zedd��Zdd�Zdd	�Z	ddd�Z
d
d�Zddd�Zd
S)�
ErsatzRAIDa� A superclass for a raid level which is not really a raid level at
        all, just a bunch of block devices of possibly differing sizes
        thrown together. This concept has different names depending on where
        it crops up. btrfs's name is single, lvm's is linear. Consequently,
        this abstract class implements all the functionality, but there are
        distinct subclasses which have different names.
    rcCsdS)Nr)r!rrr
r"�szErsatzRAID.<lambda>cCsdS)NFr)r!rrr
r"�scCsdS)NFr)rrrr
r�szErsatzRAID.has_redundancycCs
||jS)N)r)rr,rrr
r-�szErsatzRAID.get_max_sparesNcCs |dkrtd��||||�S)Nz4superblock_size_func value of None is not acceptable)r)rr/r<r4r=rrr
rB�szErsatzRAID.get_spacecCsdS)Nr)rr,rrr
r8�sz!ErsatzRAID.get_recommended_stridecCsB|std�S|dkrtd��t|td��}||�}|t|�|S)Nrz4superblock_size_func value of None is not acceptable)rrrcr9)rr;r<r4r=Ztotal_spacer?rrr
rA�szErsatzRAID.get_size)NN)NNN)
rrrrrrCr)rrr-rBr8rArrrr
rd}s
rdc@seZdZdZdZedgZdS)�Linearz" subclass with canonical lvm name ZlinearZjbodN)rrrrrrrrrr
re�srec@seZdZdZdZegZdS)�Singlez% subclass with canonical btrfs name. ZsingleN)rrrrrrrrrr
rf�srfc@s>eZdZdZdZegZdZedd��Zedd��Z	dd�Z
d	S)
�Dupz� A RAID level which expresses one way btrfs metadata may be distributed.

        For this RAID level, duplication occurs within a single block device.
    �duprcCsdS)Nr)r!rrr
r"�szDup.<lambda>cCsdS)NFr)r!rrr
r"�scCsdS)NTr)rrrr
r�szDup.has_redundancyN)rrrrrrrrCr)rrrrrr
rg�srgcCs
tj|�S)a� Convenience function to return a RAID level for the descriptor.

        :param object descriptor: a RAID level descriptor
        :rtype: RAIDLevel
        :returns: The RAIDLevel object for this descriptor

        Note that descriptor may be any object that identifies a
        RAID level, including the RAID object itself.

        Raises a RaidError is there is no RAID object for the descriptor.
    )rHrN)rMrrr
�get_raid_level�sri)rZsixr�errorsrr/rr�ABCMeta�objectrr rDrHrSrVrIrWrYr\r^rarbrdrerfrgrirrrr
�<module>s\	&kQ

'





*