Mini Shell

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

3

{)c3��@s@ddlZddlmZddlmZddlmZddlmZddlmZddl	m
Z
dd	l	mZmZdd
l
mZmZddlmZmZddlmZmZdd
lmZmZddlmZmZddlmZmZddlmZddlm Z ddl!m"Z"ddl#Z#e#j$d�Z%dZ&dZ'dZ(dZ)dZ*dZ+dZ,e&de'de(de)de*de+de,d iZ-dZ.dZ/d!Z0d"Z1e.de/d#e0d$e1d%iZ2d&Z3d'Z4e3d(e4d)iZ5d*d+�Z6d,d-�Z7d.d/�Z8ee �Gd0d1�d1ej9��Z:Gd2d3�d3e:�Z;Gd4d5�d5e:�Z<Gd6d7�d7e:�Z=Gd8d9�d9e:�Z>Gd:d;�d;e:�Z?Gd<d=�d=e:�Z@Gd>d?�d?e:�ZAGd@dA�dAe:�ZBGdBdC�dCe:�ZCGdDdE�dEe:�ZDdS)F�N)�
add_metaclass�)�util)�udev)�DependencyError)�get_current_entropy)�
StorageDevice)�PartitionDevice�LVMLogicalVolumeDevice)�
get_format�luks)�
partitionFlag�
PARTITION_LBA)�_�N_)�CreateFormatPreData�CreateFormatPostData)�ResizeFormatPreData�ResizeFormatPostData)�WaitForEntropyData�ReportProgressData)�Size)�SynchronizedMeta)�	luks_dataZbliveti�i��d�2�
��NoneZDestroyZResizeZCreateZAddZRemoveZ	Configure��ZFormatZDevice�	Container�X�YZShrinkZGrowcCs>|dkrdSx(tj�D]\}}|j�|j�kr|SqWt|�S)N)�action_strings�items�lower�resize_type_from_string)�type_string�k�v�r+�"/usr/lib/python3.6/deviceaction.py�action_type_from_stringQsr-cCs:|dkrdSx(tj�D]\}}|j�|j�kr|SqWdS)N)�object_stringsr%r&)r(r)r*r+r+r,�action_object_from_string\s
r/cCs:|dkrdSx(tj�D]\}}|j�|j�kr|SqWdS)N)�resize_stringsr%r&)r(r)r*r+r+r,r'es
r'c@s:eZdZdZeZeZdZdd�Z	dd�Z
dd�Zd:d
d�Zdd
�Z
edd��Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zed,d-��Zed.d/��Zd0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#d8d9�Z$d	S);�DeviceActionak An action that will be carried out in the future on a Device.

        These classes represent actions to be performed on devices or
        filesystems.

        The operand Device instance will be modified according to the
        action, but no changes will be made to the underlying device or
        filesystem until the DeviceAction instance's execute method is
        called. The DeviceAction instance's cancel method should reverse
        any modifications made to the Device instance's attributes.

        If the Device instance represents a pre-existing device, the
        constructor should call any methods or set any attributes that the
        action will eventually change. Device/DeviceFormat classes should verify
        that the requested modifications are reasonable and raise an
        exception if not.

        Only one action of any given type/object pair can exist for any
        given device at any given time. This is enforced by the
        DeviceTree.

        Basic usage:

            a = DeviceAction(dev)
            a.execute()

            OR

            a = DeviceAction(dev)
            a.cancel()


        XXX should we back up the device with a deep copy for forcibly
            cancelling actions?

            The downside is that we lose any checking or verification that
            would get done when resetting the Device instance's attributes to
            their original values.

            The upside is that we would be guaranteed to achieve a total
            reversal. No chance of, eg: resizes ending up altering Device
            size due to rounding or other miscalculation.
�cCsLtjj|�t|t�std��||_|jr2|j�t	|jdd�|_
d|_dS)Nz&arg 1 must be a StorageDevice instance�	containerF)r�ObjectID�__init__�
isinstancer�
ValueError�device�	is_device�_check_device_dependencies�getattrr3�_applied)�selfr8r+r+r,r5�s
zDeviceAction.__init__cCs8|jj}|r4djdd�|D��}td|jj|f��dS)Nz, css&|]}dt|�dj|j�fVqdS)z%s:
%sz, N)�str�joinZavailability_errors)�.0�dr+r+r,�	<genexpr>�sz:DeviceAction._check_device_dependencies.<locals>.<genexpr>z4device type %s requires unavailable_dependencies: %s)r8�unavailable_dependenciesr?r�type)r=rC�dependencies_strr+r+r,r:�sz'DeviceAction._check_device_dependenciescCs
d|_dS)z6 apply changes related to the action to the device(s) TN)r<)r=r+r+r,�apply�szDeviceAction.applyNcCs>|jstd��|r:|jr:td�dt|�i}|jt|��dS)z�
        Perform the action.

        :param callbacks: callbacks to be run when matching actions are
                          executed (see :meth:`~.blivet.Blivet.do_it`)

        zcannot execute unapplied actionzExecuting %(action)s�actionN)r<�RuntimeErrorZreport_progressrr>r)r=�	callbacks�msgr+r+r,�execute�s
	
zDeviceAction.executecCs
d|_dS)z cancel the action FN)r<)r=r+r+r,�cancel�szDeviceAction.cancelcCs
|jtkS)N)rD�ACTION_TYPE_DESTROY)r=r+r+r,�
is_destroy�szDeviceAction.is_destroycCs
|jtkS)N)rD�ACTION_TYPE_CREATE)r=r+r+r,�	is_create�szDeviceAction.is_createcCs
|jtkS)N)rD�ACTION_TYPE_RESIZE)r=r+r+r,�	is_resize�szDeviceAction.is_resizecCs|jo|jtkS)N)rR�dir�
RESIZE_SHRINK)r=r+r+r,�	is_shrink�szDeviceAction.is_shrinkcCs|jo|jtkS)N)rRrS�RESIZE_GROW)r=r+r+r,�is_grow�szDeviceAction.is_growcCs
|jtkS)N)rD�ACTION_TYPE_ADD)r=r+r+r,�is_add�szDeviceAction.is_addcCs
|jtkS)N)rD�ACTION_TYPE_REMOVE)r=r+r+r,�	is_remove�szDeviceAction.is_removecCs
|jtkS)N)rD�ACTION_TYPE_CONFIGURE)r=r+r+r,�is_configure�szDeviceAction.is_configurecCs
|jtkS)N)�obj�ACTION_OBJECT_DEVICE)r=r+r+r,r9�szDeviceAction.is_devicecCs
|jtkS)N)r^�ACTION_OBJECT_CONTAINER)r=r+r+r,�is_container�szDeviceAction.is_containercCs
|jtkS)N)r^�ACTION_OBJECT_FORMAT)r=r+r+r,�	is_format�szDeviceAction.is_formatcCs|jjS)N)r8�format)r=r+r+r,rd�szDeviceAction.formatcCs
t|jS)zB String indicating if this action is a create, destroy or resize. )r$rD)r=r+r+r,r(�szDeviceAction.type_stringcCs
t|jS)zA String indicating if this action's operand is device or format. )r.r^)r=r+r+r,�
object_stringszDeviceAction.object_stringcCsd}|jrt|j}|S)z7 String representing the direction of a resize action. r2)rRr0rS)r=�sr+r+r,�
resize_strings
zDeviceAction.resize_stringcCs|jr|jj}n|jj}|S)z? String representing the type of the operand device or format. )rcrd�namer8rD)r=rfr+r+r,�object_type_strings
zDeviceAction.object_type_stringcCs
t|j�S)N)r�
type_desc_str)r=r+r+r,�	type_descszDeviceAction.type_desccCs\d|j|jf}|jr$|d|j7}|jr:|d|jj7}|d|jj|jj	|jjf7}|S)Nz[%d] %sz (%s)z %s onz %s %s (id %d))
�idrjrRrgrcrdZdescr8rDrh)r=rfr+r+r,�
_to_stringszDeviceAction._to_stringcCstj|j��S)N)rZ	stringizerm)r=r+r+r,�__str__(szDeviceAction.__str__cCstj|j��S)N)rZ
unicodeizerm)r=r+r+r,�__unicode__+szDeviceAction.__unicode__cCs|jp
|jo|j|jkS)z& Return True if self requires action. )rarD)r=rGr+r+r,�requires.szDeviceAction.requirescCs4|jj|jjko2|j|jko2|j|jko2|j|jkS)z� Return True is self obsoletes action.

            DeviceAction instances obsolete other DeviceAction instances with
            lower id and same device.
        )r8rlrDr^)r=rGr+r+r,�	obsoletes3szDeviceAction.obsoletes)N)%�__name__�
__module__�__qualname__�__doc__�ACTION_TYPE_NONErD�ACTION_OBJECT_NONEr^rjr5r:rFrKrL�propertyrNrPrRrUrWrYr[r]r9rarcrdr(rergrirkrmrnrorprqr+r+r+r,r1ns>-

	

r1csFeZdZdZeZeZed�Z	dd�Z
d
�fdd�	Z�fdd	�Z�Z
S)�ActionCreateDevicez3 Action representing the creation of a new device. z
create devicecCs|jrtd��tj||�dS)Nzdevice already exists)�existsr7r1r5)r=r8r+r+r,r5FszActionCreateDevice.__init__Ncs tt|�j|d�|jj�dS)N)rI)�superryrKr8�create)r=rI)�	__class__r+r,rKMszActionCreateDevice.executecs�tt|�j|�}|jj|j�r$d}n�|jrz|jrzt|jt�rzt|jt�rz|jj	|jj	krz|jj
j}|jj
j}||kr�d}n�|jr�|jr�t|jt�r�t|jt�r�|jj
|jj
kr�|jjr�|jjr�d}q�|jjdkr�|jjdkr�d}n|jr�|j|jkr�d}|S)a� Return True if self requires action.

            Device create actions require other actions when either of the
            following is true:

                - this action's device depends on the other action's device
                - both actions are partition create actions on the same disk
                  and this partition has a higher number
                - the other action adds a member to this device's container
        TZlinear)r{ryrpr8�
depends_onrPr9r6r	�disk�parted_partition�numberr
Zvg�cachedZseg_typerYr3)r=rG�rc�self_num�	other_num)r}r+r,rpQs,

zActionCreateDevice.requires)N)rrrsrtrurOrDr_r^rrjr5rKrp�
__classcell__r+r+)r}r,ry?srycsreZdZdZeZeZed�Z	dd�Z
�fdd�Z�fdd�Zd�fd
d�	Z
�fdd
�Z�fdd�Zdd�Z�ZS)�ActionDestroyDevicez< An action representing the deletion of an existing device. zdestroy devicecCstj||�dS)N)r1r5)r=r8r+r+r,r5�szActionDestroyDevice.__init__csf|jjdkrdS|jjdkrTtj�}|rPdjdd�|D��}td|jj|f��dStt|�j�dS)	Nzbtrfs volume�
lvmvdopool�lvmvdolvz, css|]}t|�VqdS)N)r>)r@rAr+r+r,rB�szAActionDestroyDevice._check_device_dependencies.<locals>.<genexpr>z4device type %s requires unavailable_dependencies: %s)r�r�)	r8rDr
Zunavailable_type_dependenciesr?rr{r�r:)r=rCrE)r}r+r,r:�sz.ActionDestroyDevice._check_device_dependenciescs8|jr
dSt|jd�r&|jjd7_tt|�j�dS)z6 apply changes related to the action to the device(s) N�ignore_skip_activationr)r<�hasattrr8r�r{r�rF)r=)r}r+r,rF�s
zActionDestroyDevice.applyNcs tt|�j|d�|jj�dS)N)rI)r{r�rKr8�destroy)r=rI)r}r+r,rK�szActionDestroyDevice.executecs8|js
dSt|jd�r&|jjd8_tt|�j�dS)Nr�r)r<r�r8r�r{r�rL)r=)r}r+r,rL�s
zActionDestroyDevice.cancelcs�tt|�j|�}|jj|j�r*|jr*d}n�|jr�|jr�t|jt�r�|jj	r�t|jt�r�|jj	r�|jj
|jj
kr�|jjj}|jjj}||kr�d}n8|jr�|j
r�|jj|jjkr�d}n|jr�|j|jkr�d}|S)a� Return True if self requires action.

            Device destroy actions require other actions when either of the
            following is true:

                - the other action's device depends on this action's device
                - both actions are partition create actions on the same disk
                  and this partition has a lower number
                - the other action removes this action's device from a container
        T)r{r�rpr8r~rNr9r6r	�disklabel_supportedrr�r�rcrlr[)r=rGr�r�r�)r}r+r,rp�s"

zActionDestroyDevice.requirescCs�d}|jj|jjkrv|j|jkr0|jjr0d}q�|j|jkr^|jjr^|jrP|jpT|jr^d}q�|jr�|j|jkr�d}n|jr�|j|jkr�d}|S)a� Return True if self obsoletes action.

            - obsoletes all actions w/ lower id that act on the same device,
              including self, if device does not exist

            - obsoletes all but ActionDestroyFormat and ActionRemoveMember actions
              w/ lower id on the same device if device exists

            - obsoletes all actions that add a member to this action's
              (container) device

        FT)r8rlrzrNrcr[rYr3)r=rGr�r+r+r,rq�s
zActionDestroyDevice.obsoletes)N)rrrsrtrurMrDr_r^rrjr5r:rFrKrLrprqr�r+r+)r}r,r�zs
	r�cs^eZdZdZeZeZed�Z	dd�Z
�fdd�Zd�fdd	�	Z�fd
d�Z
�fdd
�Z�ZS)�ActionResizeDevicez< An action representing the resizing of an existing device. z
resize devicecCs�|jstd��|j|kr td��||jkr2td��|jrJ||jkrJtd��tj||�||jkrht|_nt	|_|j
td�kr�|j
|_n|j
|_||_dS)Nzdevice is not resizableznew size same as old sizeznew size is too smallznew size is too larger)�	resizabler7�current_sizeZmin_sizeZmax_sizer1r5rVrSrT�target_sizer�origsize�size�_target_size)r=r8�newsizer+r+r,r5�s 



zActionResizeDevice.__init__cs&|jr
dS|j|j_tt|�j�dS)z6 apply changes related to the action to the device(s) N)r<r�r8r�r{r�rF)r=)r}r+r,rF	s
zActionResizeDevice.applyNcs tt|�j|d�|jj�dS)N)rI)r{r�rKr8Zresize)r=rI)r}r+r,rKszActionResizeDevice.executecs&|js
dS|j|j_tt|�j�dS)N)r<r�r8r�r{r�rL)r=)r}r+r,rLs
zActionResizeDevice.cancelcs�tt|�j|�}|jr�|jj|jjkrD|j|jkrD|jrD|jrDd}q�|j	r^|jj
|j�r^d}q�|jrx|jj
|j�rxd}q�|j	r�|jr�t|jj�j
t|jj��r�dSn.|jr�|j|jkr�d}n|jr�|j|jkr�d}|S)aI Return True if self requires action.

            A device resize action requires another action if:

                - the other action is a format resize on the same device and
                  both are shrink operations
                - the other action grows a device (or format it contains) that
                  this action's device depends on
                - the other action shrinks a device (or format it contains)
                  that depends on this action's device
                - this action is a grow action and the other action is a shrink
                  action and the two actions' respective devices share one or more
                  ancestors
                - the other action removes this action's device from a container
                - the other action adds a member to this device's container
        T)r{r�rprRr8rlrSrcrUrWr~�setZ	ancestors�intersectionr[rYr3)r=rG�retval)r}r+r,rps$zActionResizeDevice.requires)N)rrrsrtrurQrDr_r^rrjr5rFrKrLrpr�r+r+)r}r,r��sr�csheZdZdZeZeZed�Z	ddd�Z
�fdd�Zd�fdd	�	Z�fd
d�Z
�fdd
�Zdd�Z�ZS)�ActionCreateFormatz6 An action representing creation of a new filesystem. z
create formatNcCsj|jrtd��tj||�|r(|j|_n
td�|_|p:|j|_|jjrNtd��|jj	sftd|jj
��dS)aw
            :param device: the device on which the format will be created
            :type device: :class:`~.devices.StorageDevice`
            :keyword fmt: the format to put on the device
            :type fmt: :class:~.formats.DeviceFormat`

            If no format is specified, it is assumed that the format is already
            associated with the device.
        z+this device's formatting cannot be modifiedNzspecified format already existsz0resource to create this format %s is unavailable)�format_immutabler7r1r5rd�orig_formatr�_formatrzZformattablerD)r=r8Zfmtr+r+r,r5Is


zActionCreateFormat.__init__cs&|jr
dS|j|j_tt|�j�dS)z6 apply changes related to the action to the device(s) N)r<r�r8rdr{r�rF)r=)r}r+r,rFds
zActionCreateFormat.applycs2tt|�j|d�|rF|jrFtd�|jjj|jjd�}|jt	|��t
|jt�r�|jjr�x.t
j�D]"}|t|jjgkrzqd|jj|�qdW|jjdk	r�|jj|jj_|jjdk	r�|jj|jj�|jjjj�tj�t
|jjtj��rL|jjj}t�}||k�rLd}|�r0|j�r0td�|}|jt||��}|�rLt j!dt�|�dt"_#|jj$�|jjj%|jj|jj&d�tj�|jj'�tj(|jj)�}|�r�|jjjd	k�r�tj*|�|jj_+tj,|�|j_-n|jjjd
k�r�t j.d|j�|�r|j/�rtd�|jjj|jjd�}|j/t0|��t1j2|jj�|j_3dS)
N)rIzCreating %(type)s on %(device)s)rDr8Fz=Not enough entropy to create LUKS format. %d bits are needed.zFForcing LUKS creation regardless of enough random data entropy (%d/%d)r)r8ZoptionsZbtrfsZtmpfsz!udev lookup failed for device: %szCreated %(type)s on %(device)s)4r{r�rKZcreate_format_prerr8rdrD�pathrr6r	r�r
�keysr�parted_flag�
unset_flagZ
parted_systemr��systemZset_flagr�commit_to_diskr�settlerZLUKSZmin_luks_entropyrZwait_for_entropyr�logZwarningrZmin_entropy�setupr|Zformat_argsZupdate_sysfs_pathZ
get_deviceZ
sysfs_pathZdevice_get_uuidZuuidZdevice_get_symlinksZdevice_links�errorZcreate_format_postr�copy�deepcopy�original_format)r=rIrJ�flagZmin_required_entropyZcurrent_entropyZ
force_cont�info)r}r+r,rKlsX





zActionCreateFormat.executecs&|js
dS|j|j_tt|�j�dS)N)r<r�r8rdr{r�rL)r=)r}r+r,rL�s
zActionCreateFormat.cancelcsTtt|�j|�pR|jj|j�r2|jr*|jp.|jpR|joR|jsD|j	oR|jj
|jj
kS)a� Return True if self requires action.

            Format create action can require another action if:

                - this action's device depends on the other action's device
                  and the other action is not a device destroy action or a
                  container action
                - the other action is a create or resize of this action's
                  device
        )r{r�rpr8r~rNr9rarPrRrl)r=rG)r}r+r,rp�szActionCreateFormat.requirescCs8|jj|jjko6|j|jko6|jo(|jjo6|j|jkS)a Return True if this action obsoletes action.

            Format create actions obsolete the following actions:

                - format actions w/ lower id on this action's device, other
                  than those that destroy existing formats
        )r8rlr^rNrdrz)r=rGr+r+r,rq�szActionCreateFormat.obsoletes)N)N)rrrsrtrurOrDrbr^rrjr5rFrKrLrprqr�r+r+)r}r,r�Bs
Ar�csreZdZdZeZeZed�Z	dd�Z
�fdd�Zd�fdd	�	Z�fd
d�Z
edd
��Z�fdd�Zdd�Z�ZS)�ActionDestroyFormatz? An action representing the removal of an existing filesystem. zdestroy formatcCs@|jrtd��tj||�|jj|_|jjs<td|jj��dS)Nz+this device's formatting cannot be modifiedz6resource to destroy this format type %s is unavailable)	r�r7r1r5r8rdr�ZdestroyablerD)r=r8r+r+r,r5�s
zActionDestroyFormat.__init__cs@|jr
dSd|j_t|jd�r.|jjd7_tt|�j�dS)Nr�r)r<r8rdr�r�r{r�rF)r=)r}r+r,rF�szActionDestroyFormat.applyNcs�tt|�j|d�|jj}|jjdd�t|jd�r>|jj�|jj	�t
j�t|jt
�r�|jjr�|jjr||jj|jj�|jjjj�t
j�|s�|jj�dS)z/ wipe the filesystem signature from the device )rIT)�orig�set_rwN)r{r�rKr8�statusr�r�r�rdr�rr�r6r	r�r�r�rr�r�Zteardown)r=rIr�)r}r+r,rK�s

zActionDestroyFormat.executecsB|js
dS|j|j_t|jd�r0|jjd8_tt|�j�dS)Nr�r)	r<r�r8rdr�r�r{r�rL)r=)r}r+r,rLs
zActionDestroyFormat.cancelcCs|jS)N)r�)r=r+r+r,rdszActionDestroyFormat.formatcsDtt|�j|�}|jj|j�r*|jr*d}n|jr@|j|jkr@d}|S)aG Return True if self requires action.

            Format destroy actions require other actions when:

                - the other action's device depends on this action's device
                  and the other action is a destroy action
                - the other action removes this action's device from a container
        T)r{r�rpr8r~rNr[)r=rGr�)r}r+r,rps	zActionDestroyFormat.requirescCs�d}|jj|jjk}|j|jk}|r�|r�|jr�|jjrF|jjrFd}q�|jjr^|jjr^d}q�|j|jkrz|jjrzd}q�|j|jk}n|j|jk}|S)a� Return True if this action obsoletes action.

            Format destroy actions obsolete the following actions:

            - non-destroy format actions w/ lower id on same device, including
              self if format does not exist

            - destroy format action w/ higher id on same device

            - format destroy action on a non-existent format shouldn't
              obsolete a format destroy action on an existing one
        FT)r8rlr^rNrdrz)r=rGr�Zsame_deviceZ
format_actionr+r+r,rq!s
zActionDestroyFormat.obsoletes)N)rrrsrtrurMrDrbr^rrjr5rFrKrLrxrdrprqr�r+r+)r}r,r��s

	r�cs^eZdZdZeZeZed�Z	dd�Z
�fdd�Zd�fdd	�	Z�fd
d�Z
�fdd
�Z�ZS)�ActionResizeFormatz� An action representing the resizing of an existing filesystem.

        XXX Do we even want to support resizing of a filesystem without
            also resizing the device it resides on?
    z
resize formatcCs�|jrtd��|jjstd��|jj|kr2td��tj||�||jjkrRt|_nt	|_|jj
td�krt|jj
|_n
|jj|_||_
dS)Nz+this device's formatting cannot be modifiedzformat is not resizableznew size same as old sizer)r�r7rdr�r�r1r5rVrSrTr�r�	orig_sizer�)r=r8r�r+r+r,r5Ls
zActionResizeFormat.__init__csD|jr
dS|j|jj_t|jd�r2|jjd7_tt|�j	�dS)Nr�r)
r<r�r8rdr�r�r�r{r�rF)r=)r}r+r,rFdszActionResizeFormat.applyNcs�tt|�j|d�|r>|jr>td�d|jji}|jt|��|jjdd�|jj	j
�|r�|jr�td�d|jji}|jt|��dS)N)rIz!Resizing filesystem on %(device)sr8T)r�z Resized filesystem on %(device)s)
r{r�rKZresize_format_prerr8r�rr�rdZ	do_resizeZresize_format_postr)r=rIrJ)r}r+r,rKns

zActionResizeFormat.executecsD|js
dS|j|jj_t|jd�r2|jjd8_tt|�j	�dS)Nr�r)
r<r�r8rdr�r�r�r{r�rL)r=)r}r+r,rL{szActionResizeFormat.cancelcs�tt|�j|�}|jrx|jj|jjkrD|j|jkrD|jrD|jrDd}q�|j	r^|jj
|j�r^d}q�|jr�|jj
|j�r�d}n|jr�|j|jkr�d}|S)a0 Return True if self requires action.

            A format resize action requires another action if:

                - the other action is a device resize on the same device and
                  both are grow operations
                - the other action shrinks a device (or format it contains)
                  that depends on this action's device
                - the other action grows a device (or format) that this
                  action's device depends on
                - the other action removes this action's device from a container
        T)r{r�rprRr8rlrSr9rWrUr~r[)r=rGr�)r}r+r,rp�s
zActionResizeFormat.requires)N)rrrsrtrurQrDrbr^rrjr5rFrKrLrpr�r+r+)r}r,r�As


r�csfeZdZdZeZeZed�Z	�fdd�Z
�fdd�Z�fdd�Zd�fd
d�	Z
dd
�Zdd�Z�ZS)�ActionAddMemberzD An action representing addition of a member device to a container. zadd container membercstt|�j|�||_dS)N)r{r�r5r3)r=r3r8)r}r+r,r5�szActionAddMember.__init__cs,|jr
dS|jjj|j�tt|�j�dS)N)r<r3�parents�appendr8r{r�rF)r=)r}r+r,rF�szActionAddMember.applycs,|js
dS|jjj|j�tt|�j�dS)N)r<r3r��remover8r{r�rL)r=)r}r+r,rL�szActionAddMember.cancelNcs$tt|�j|d�|jj|j�dS)N)rI)r{r�rKr3�addr8)r=rI)r}r+r,rK�szActionAddMember.executecCs|js|jo|j|jkS)z�
            requires
                - create/resize the same device

            required by
                - any create/grow action on a device in the same container
        )rPrRr8)r=rGr+r+r,rp�szActionAddMember.requirescCsZd}|jr(|j|jkr(|j|jkr(d}n.|jrV|j|jkrV|j|jkrV|j|jkrVd}|S)a9
            obsoletes
                - remove same member from same container
                - add same member to same container w/ higher id

            obsoleted by
                - destroy the container
                - destroy the device
                - remove same member from same container
        FT)r[r8r3rYrl)r=rGr�r+r+r,rq�szActionAddMember.obsoletes)N)rrrsrtrurXrDr`r^rrjr5rFrLrKrprqr�r+r+)r}r,r��sr�csfeZdZdZeZeZed�Z	�fdd�Z
�fdd�Z�fdd�Zd�fd
d�	Z
dd
�Zdd�Z�ZS)�ActionRemoveMemberzE An action representing removal of a member device from a container. zremove container membercstt|�j|�||_dS)N)r{r�r5r3)r=r3r8)r}r+r,r5�szActionRemoveMember.__init__cs,|jr
dS|jjj|j�tt|�j�dS)N)r<r3r�r�r8r{r�rF)r=)r}r+r,rF�szActionRemoveMember.applycs,|js
dS|jjj|j�tt|�j�dS)N)r<r3r�r�r8r{r�rL)r=)r}r+r,rL�szActionRemoveMember.cancelNcs$tt|�j|d�|jj|j�dS)N)rI)r{r�rKr3r�r8)r=rI)r}r+r,rK�szActionRemoveMember.executecCsJd}|js|jr0t|jd�r0|jj|jkr0d}n|jrF|j|jkrFd}|S)z�
            requires
                - any destroy/shrink action on a device in the same container
                - any add action on this container

            required by
                - any destroy/resize action on the device
        Fr3T)rUrNr�r8r3rY)r=rGr�r+r+r,rps	zActionRemoveMember.requirescCsZd}|jr(|j|jkr(|j|jkr(d}n.|jrV|j|jkrV|j|jkrV|j|jkrVd}|S)z�
            obsoletes
                - add same member to same container
                - remove same member from same container w/ higher id

            obsoleted by
                - add same member to same container
        FT)rYr8r3r[rl)r=rGr�r+r+r,rqs	zActionRemoveMember.obsoletes)N)rrrsrtrurZrDr`r^rrjr5rFrLrKrprqr�r+r+)r}r,r��sr�cs^eZdZdZeZeZed�Z	�fdd�Z
�fdd�Z�fdd�Zd�fd
d�	Z
dd
�Z�ZS)�ActionConfigureFormatz3 An action change of an attribute of device format zconfigure formatcs�tt|�j|�||_||_||_t|jjdd�}|dksH|j|j�kr`t	d|jjj
|jf��||jdkrvd|_n0t|jj||jd�|_t|j�s�t
d|j��t|jj|j�|_|jr�|jdd�dS)N�config_actions_mapzMFormat %s doesn't support changing '%s' attribute using configuration actionsz1Invalid method for changing format attribute '%s'T)�dry_run)r{r�r5r8�attr�	new_valuer;rdr�r7rD�_execute�callablerH�	old_value)r=r8r�r�r�)r}r+r,r50s 
zActionConfigureFormat.__init__csL|jr
dSt|jj|j|j�t|jd�r:|jjd7_tt	|�j
�dS)Nr�r)r<�setattrr8rdr�r�r�r�r{r�rF)r=)r}r+r,rFHszActionConfigureFormat.applycsL|js
dSt|jj|j|j�t|jd�r:|jjd8_tt	|�j
�dS)Nr�r)r<r�r8rdr�r�r�r�r{r�rL)r=)r}r+r,rLRszActionConfigureFormat.cancelNcs6tt|�j|d�|jdk	r2|jj�|jdd�dS)N)rIF)r�)r{r�rKr�r8r�)r=rI)r}r+r,rK\s

zActionConfigureFormat.executecCs@|jj|jjko>|j|jko>|j|jko>|j|jko>|j|jkS)z� Return True is self obsoletes action.

            ActionConfigureFormat instances obsolete other ActionConfigureFormat instances with
            lower id, same device and same attribute.
        )r8rlrDr^r�)r=rGr+r+r,rqcs
zActionConfigureFormat.obsoletes)N)rrrsrtrur\rDrbr^rrjr5rFrLrKrqr�r+r+)r}r,r�)s

r�cs^eZdZdZeZeZed�Z	�fdd�Z
�fdd�Z�fdd�Zd�fd
d�	Z
dd
�Z�ZS)�ActionConfigureDevicez. An action change of an attribute of a device zconfigure devicecs�tt|�j|�||_||_||_t|jdd�}|dksF|j|j�kr\td|jj	|jf��||jdkrrd|_
n.t|j||jd�|_
t|j
�s�td|j��t|j|j�|_
|j
r�d|j|j
d|j|jddi}|j
f|�dS)Nr�zMDevice %s doesn't support changing '%s' attribute using configuration actionsz*Invalid method for changing attribute '%s'zold_%sznew_%sr�T)r{r�r5r8r�r�r;r�r7rDr�r�rHr�)r=r8r�r�r��kwargs)r}r+r,r5ws&
zActionConfigureDevice.__init__cs.|jr
dSt|j|j|j�tt|�j�dS)N)r<r�r8r�r�r{r�rF)r=)r}r+r,rF�szActionConfigureDevice.applycs.|js
dSt|j|j|j�tt|�j�dS)N)r<r�r8r�r�r{r�rL)r=)r}r+r,rL�szActionConfigureDevice.cancelNcsLtt|�j|d�|jdk	rHd|j|jd|j|jddi}|jf|�dS)N)rIzold_%sznew_%sr�F)r{r�rKr�r�r�r�)r=rIr�)r}r+r,rK�s
zActionConfigureDevice.executecCs@|jj|jjko>|j|jko>|j|jko>|j|jko>|j|jkS)z� Return True is self obsoletes action.

            ActionConfigureDevice instances obsolete other ActionConfigureDevice instances with
            lower id, same device and same attribute.
        )r8rlrDr^r�)r=rGr+r+r,rq�s
zActionConfigureDevice.obsoletes)N)rrrsrtrur\rDr_r^rrjr5rFrLrKrqr�r+r+)r}r,r�ps	r�)Er�Zsixrr2rr�errorsrrZdevicesrr	r
ZformatsrrZpartedr
rZi18nrrrIrrrrrrr�rZthreadsrZstatic_datarZloggingZ	getLoggerr�rvrMrQrOrXrZr\r$rwrbr_r`r.rTrVr0r-r/r'r4r1ryr�r�r�r�r�r�r�r�r�r+r+r+r,�<module>sz
		
Q;oYmaAFG