Mini Shell
3
{)c� � @ s~ d dl Z d dlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
d dlZejd�Z
d d
lmZ ee
�G dd� de��ZdS )
� N)�
add_metaclass� )�errors)�log_method_call)�get_device_format_class)�SynchronizedABCMetaZblivet� )�
StorageDevicec s� e Zd ZdZejdd� dd�Zejdd� dd�Z� fdd �Zddd�Z � fd
d�Z
ejdd� �Zdd� Z
ejdd� �Zdd� Zddd�Z� ZS )�ContainerDevicea� A device that aggregates a set of member devices.
The only interfaces provided by this class are for addition and removal
of member devices -- one set for modifying the member set of the
python objects, and one for writing the changes to disk.
The member set of the instance can be manipulated using the methods
:meth:`~.ParentList.append` and :meth:`~.ParentList.remove` of the
instance's :attr:`~.Device.parents` attribute.
:meth:`add` and :meth:`remove` remove a member from the container's on-
disk representation. These methods should normally only be called from
within :meth:`.deviceaction.ActionAddMember.execute` and
:meth:`.deviceaction.ActionRemoveMember.execute`.
c C s d S )N� )�sr r �/usr/lib/python3.6/container.py�<lambda>8 s zContainerDevice.<lambda>z+The type of member devices' required format)�docc C s d S )Nr )r r r r
r : s z7The container UUID attribute in the member format classc s8 t | j�| _| js"tjd| j ��tt| �j||� d S )Nzcannot find '%s' class)r �_format_class_name�format_classr ZStorageError�superr
�__init__)�self�args�kwargs)� __class__r r
r = s zContainerDevice.__init__Tc C s� | j stjd� dS t|j| j �s6tjd| j |� dS t|j| j �}| jrf| sX| j rftjd� dS |rx|jj rxdS || jk}|r�| r�d|| jf S | r�|r�d|| jf S dS )a Whether the member's array UUID has the proper relationship
with its array's UUID.
:param member: the member device to add
:type member: :class:`.StorageDevice`
:param bool expect_equality: if True, expect UUIDs to be equal, otherwise, expect them to be unequal
:param bool require_existence: if True, checking UUIDs is only meaningful if member format exists
:returns: error msg if the UUIDs lack the correct relationship
:rtype: str or NoneType
z7No attribute name corresponding to member's array UUID.NzcAttribute name (%s) which specifies member format's array UUID does not exist for this object (%s).zAt least one UUID missing.z8Member format's UUID %s does not match expected UUID %s.z1Member format's UUID %s matches expected UUID %s.) �_format_uuid_attr�log�info�hasattr�formatZwarning�getattr�existsZuuid)r �member�expect_equality�require_existenceZmember_fmt_uuidZuuids_equalr r r
�_verify_member_uuidD s$
z#ContainerDevice._verify_member_uuidc sR t | | j|jd� t|j| j�s(td��| j|�}|r>td��tt| �j |� dS )z� Add a parent device to the container.
:param parent: the parent device to add
:type parent: :class:`.StorageDevice`
This operates on the in-memory model and does not alter disk
contents at all.
)�parentzparent has wrong formatz&cannot add parent with mismatched UUIDN)
r �name�
isinstancer r �
ValueErrorr"