Mini Shell
3
{)c
0 � @ st d dl Z d dlmZ ddlmZ ddlmZ ddlmZ d dl Z e j
d�Zdd lm
Z
ee�G d
d� dej��ZdS )� N)�
add_metaclass� )�util)�log_method_call)�SynchronizedMetaZblivet� )�
ParentListc @ s� e Zd ZdZdZg Zg ZdTdd�Zdd� Zdd � Z d
d� Z
dd
� Zdd� Zdd� Z
dd� Zdd� Zedd� �Zejdd� �Zedd� �Zedd� �Zdd� Zdd � ZdUd"d#�ZdVd$d%�Zd&d'� Zd(d)� ZdWd*d+�ZdXd,d-�Zd.d/� Zd0d1� Zed2d3� �Zd4d5� Z d6d7� Z!ed8d9� d:d9� d;d<�Z"ed=d>� �Z#ed?d@� �Z$edAdB� �Z%edCdD� �Z&edEdF� �Z'edGdH� �Z(e(jdIdH� �Z(dJdK� Z)e*dLdM� �Z+e*dNdO� �Z,edPdQ� �Z-edRdS� �Z.dS )Y�Devicea A generic device.
Device instances know which devices they depend upon (parents
attribute). They do not know which devices depend upon them, but
they do know whether or not they have any dependent devices
(isleaf attribute).
A Device's setup method should set up all parent devices as well
as the device itself. It should not run the resident format's
setup method.
Which Device types rely on their parents' formats being active?
DMCryptDevice
A Device's teardown method should accept the keyword argument
recursive, which takes a boolean value and indicates whether or
not to recursively close parent devices.
A Device's create method should create all parent devices as well
as the device itself. It should also run the Device's setup method
after creating the device. The create method should not create a
device's resident format.
Which device type rely on their parents' formats to be created
before they can be created/assembled?
VolumeGroup
DMCryptDevice
A Device's destroy method should destroy any resident format
before destroying the device itself.
ZdeviceNc C sJ t jj| � || _|dk r.t|t� r.td��t� | _|p<g | _ g | _
dS )z�
:param name: the device name (generally a device node's basename)
:type name: str
:keyword parents: a list of parent devices
:type parents: list of :class:`Device` instances
Nz*parents must be a list of Device instances)r �ObjectID�__init__�_name�
isinstance�list�
ValueError�set�_tags�parents� _children)�self�namer � r �/usr/lib/python3.6/device.pyr L s
zDevice.__init__c C s t j| |ddd�S )z� Create a deep copy of a Device instance.
We can't do copy.deepcopy on parted objects, which is okay.
For these parted objects, we just do a shallow copy.
�node�_parted_partition)ZomitZshallow)r )r )r Z
variable_copy)r �memor r r �__deepcopy__\ s zDevice.__deepcopy__c
C sR d| j jdt| � | j| j| jtjdd� | jD ��tjdd� | jD ��d� }|S )Nz�%(type)s instance (%(id)s) --
name = %(name)s status = %(status)s id = %(dev_id)s
children = %(children)s
parents = %(parents)s
z%#xc S s g | ]}t |��qS r )�str)�.0�cr r r �
<listcomp>o s z#Device.__repr__.<locals>.<listcomp>c S s g | ]}t |��qS r )r )r �pr r r r p s )�type�idr �statusZdev_id�childrenr ) � __class__�__name__r"