Mini Shell

Direktori : /lib/python3.6/site-packages/blivet/devices/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/blivet/devices/__pycache__/disk.cpython-36.opt-1.pyc

3

{)ce�@s|ddlZejdd�ddlmZddlZddlmZddlmZddl	m
Zdd	lmZdd
l
mZddlmZddlmZdd
lmZddlmZddlZejd�ZddlmZddlmZddlmZddlmZddl m!Z!Gdd�de�Z"Gdd�de"�Z#Gdd�de!e�Z$Gdd�de!�Z%Gdd�de"e�Z&Gd d!�d!e"e�Z'Gd"d#�d#e"�Z(Gd$d%�d%e"�Z)Gd&d'�d'e"�Z*dS)(�N�BlockDevz2.0)r�)�errors)�util)�disk)�flags)�log_method_call)�udev)�Size)�availability)�fcoeZblivet�)�Tags)�
StorageDevice)�ContainerDevice)�NetworkStorageDevice)�DMDevicec
@s�eZdZdZdZdZdZddd�Zdd	�Zd
d�Z	e
dd
��Ze
dd��Zdd�Z
e
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��ZdS)�
DiskDevicez� A local/generic disk.

        This is not the only kind of device that is treated as a disk. More
        useful than checking isinstance(device, DiskDevice) is checking
        device.is_disk.
    rTN�cCs�tj|||||||||||
|	||
d�|p,d|_yttj|jd��dk}Wntk
rbd}YnX|jj	t
j�|r�|jj	t
j�|dkr�|jj	t
j
�|jr�|jj	t
j�dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword fmt: this device's formatting
            :type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword uuid: universally unique identifier (device -- not fs)
            :type uuid: str
            :keyword sysfs_path: sysfs device path
            :type sysfs_path: str
            :keyword removable: whether or not this is a removable device
            :type removable: bool
            :keyword serial: the ID_SERIAL_RAW, ID_SERIAL or ID_SERIAL_SHORT for
                             this device (which one is available)
            :type serial: str
            :keyword vendor: the manufacturer of this Device
            :type vendor: str
            :keyword model: manufacturer's device model string
            :type model: str
            :keyword bus: the interconnect this device uses
            :type bus: str
            :keyword str wwn: the disk's WWN

            DiskDevices always exist.
        )�fmt�size�major�minor�exists�
sysfs_path�parents�serial�model�vendor�bus�uuidNzqueue/rotationalrF�usb)r�__init__�wwn�intrZget_sysfs_attrr�	TypeError�tags�addr�local�ssdr!�	removable)�self�namerrrrrrrrrrr#r rr)�r-�/usr/lib/python3.6/disk.pyr"?s" 

zDiskDevice.__init__cCs*ttjtjtjtjg�}|jj|�|_dS)N)�setrr(r)r!r*r&�
difference)r+Z
local_tagsr-r-r.�_clear_local_tagstszDiskDevice._clear_local_tagscCs$tj|�}|d|j|jd�7}|S)Nz*  removable = %(removable)s  wwn = %(wwn)s)r*r#)r�__repr__r*r#)r+�sr-r-r.r2xs
zDiskDevice.__repr__cCstjr
dS|jo|jtd�kS)NTr)rZtestingrZcurrent_sizer
)r+r-r-r.�
media_present~szDiskDevice.media_presentcCs djdd�|j|j|jfD��S)N� css|]}|r|VqdS)Nr-)�.0r3r-r-r.�	<genexpr>�sz)DiskDevice.description.<locals>.<genexpr>)�joinrrr#)r+r-r-r.�description�szDiskDevice.descriptioncCs0t||j|jd�|js"tjd��tj|�dS)z Destroy the device. )�statusz!cannot destroy disk with no mediaN)rr,r:r4rZDeviceErrorr�_pre_destroy)r+r-r-r.r;�s
zDiskDevice._pre_destroycCstjj|j�S)N)�disklibZvolumes�get�path)r+r-r-r.�_volume�szDiskDevice._volumecCs|jdk	r|jjSdS)N)r?�system)r+r-r-r.�raid_system�szDiskDevice.raid_systemcCs|jdk	r|jjSdS)N)r?Z	raid_type)r+r-r-r.�
raid_level�szDiskDevice.raid_levelcCs|jdk	r|jjSdS)N)r?�raid_stripe_size)r+r-r-r.rC�szDiskDevice.raid_stripe_sizecCs|jdk	r|jjSdS)N)r?�raid_disk_count)r+r-r-r.rD�szDiskDevice.raid_disk_count)
NNNNrNNrrrNNT)�__name__�
__module__�__qualname__�__doc__�_type�_partitionable�_is_diskr"r1r2�propertyr4r9r;r?rArBrCrDr-r-r-r.r3s$
2
rcsPeZdZdZdZd�fdd�	Zedd��Zejd	d��Zd
d�Z	dd
�Z
�ZS)�DiskFilea[ This is a file that we will pretend is a disk.

        This is intended only for testing purposes. The benefit of this class
        is that you can instantiate a disk-like device with a working disklabel
        class as a non-root user. It is not known how the system will behave if
        partitions are committed to one of these disks.
    rNTc
sFtjj|�}
tjj|�|_tt|�j|
||||||||	|
||d�dS)z�
            :param str name: the full path to the backing regular file
            :keyword :class:`~.formats.DeviceFormat` fmt: the device's format
        )rrrrrrrrrrrN)�osr>�basename�dirname�_dev_dir�superrMr")r+r,rrrrrrrrrrr�_name)�	__class__r-r.r"�szDiskFile.__init__cCsdS)Nrr-)r+r-r-r.r�szDiskFile.sysfs_pathcCsdS)Nr-)r+�valuer-r-r.r�scCsdS)Nr-)r+r-r-r.�update_sysfs_path�szDiskFile.update_sysfs_pathcCs6td�}|jr2tjj|j�r2tj|j�}t|j�}|S)Nr)r
rrNr>�stat�st_size)r+r�str-r-r.�read_current_size�s

zDiskFile.read_current_size)NNNNrNNrrrT)rErFrGrHrQr"rLr�setterrVrZ�
__classcell__r-r-)rTr.rM�srMcs�eZdZdZdZdgZdZdZedd��Z	edd��Z
ejgZ
d!�fd
d�	Zedd
��Zdd�Zdd�Zd"dd�Zd#dd�Zdd�Zdd�Zedd��Zedd��Zdd �Z�ZS)$�DMRaidArrayDevicez& A dmraid (device-mapper RAID) device z
dm-raid arrayZdmraidTcCsdS)NZdmraidmemberr-)r3r-r-r.�<lambda>�szDMRaidArrayDevice.<lambda>cCsdS)Nr-)r3r-r-r.r^�sNrcs8tt|�j||||d|d�|p"d|_|jjtj�dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword fmt: this device's formatting
            :type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword sysfs_path: sysfs device path
            :type sysfs_path: str
            :keyword str wwn: the device's WWN

            DMRaidArrayDevices always exist. Blivet cannot create or destroy
            them.
        T)rrrrrN)rRr]r"r#r&r'rr()r+r,rrrrr#)rTr-r.r"�s

zDMRaidArrayDevice.__init__cCs|jS)z8 Return a list of this array's member device instances. )r)r+r-r-r.�devices�szDMRaidArrayDevice.devicescCs$t||j|jd�tjj|j�dS)z Deactivate the raid set. )r:N)rr,r:�blockdev�dmZdeactivate_raid_set)r+r-r-r.�
deactivateszDMRaidArrayDevice.deactivatecCs,t||j|jd�tjj|j�tj�dS)z Activate the raid set. )r:N)rr,r:r`raZactivate_raid_setr	�settle)r+r-r-r.�activate	szDMRaidArrayDevice.activateFcCs$t||j||j|jd�|j�dS)z Open, or set up, a device. )�origr:�controllableN)rr,r:rfrd)r+rer-r-r.�_setups
zDMRaidArrayDevice._setupcCs8t||j|j|jd�|j|d�s&dStjd|j�dS)z  Close, or tear down, a device. )r:rf)�	recursiveNz!not tearing down dmraid device %s)rr,r:rfZ
_pre_teardown�log�debug)r+rhr-r-r.�teardowns

zDMRaidArrayDevice.teardowncCs
t��dS)N)�NotImplementedError)r+�memberr-r-r.�_addszDMRaidArrayDevice._addcCs
t��dS)N)rl)r+rmr-r-r.�_remove"szDMRaidArrayDevice._removecCsdtjj|j�S)NzBIOS RAID set (%s))r`raZget_raid_set_typer,)r+r-r-r.r9%szDMRaidArrayDevice.descriptioncCs|jS)N)r9)r+r-r-r.r)szDMRaidArrayDevice.modelcCstd|jg�S)Nz
rd.dm.uuid=%s)r/r,)r+r-r-r.�dracut_setup_args-sz#DMRaidArrayDevice.dracut_setup_args)NNNrN)F)N)rErFrGrHrI�	_packagesrJrKrLZ_format_class_nameZ_format_uuid_attrrZBLOCKDEV_DM_PLUGIN_RAID�_external_dependenciesr"r_rbrdrgrkrnror9rrpr\r-r-)rTr.r]�s(

	r]cs�eZdZdZdZdgZdZdZej	gZ
ddd�Zed	d
��Z
edd��Zed
d��Zdd�Z�fdd�Z�fdd�Zddd�Zdd�Z�ZS)�MultipathDevicez A multipath device zdm-multipathzdevice-mapper-multipathTNrc	Cs&tj||||||dd�|pd|_dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword fmt: this device's formatting
            :type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword sysfs_path: sysfs device path
            :type sysfs_path: str
            :keyword str wwn: the device's WWN

            MultipathDevices always exist. Blivet cannot create or destroy
            them.
        T)rrrrrN)rr"r#)r+r,rrr#rrr-r-r.r":szMultipathDevice.__init__cCs|js
dS|jdjS)Nrr)rr)r+r-r-r.rQszMultipathDevice.modelcCs|js
dS|jdjS)Nrr)rr)r+r-r-r.rWszMultipathDevice.vendorcCs
d|jS)NzWWID %s)r#)r+r-r-r.r9]szMultipathDevice.descriptioncCsFt||j|jd�|jr6|j�|jj|�|j�n|jj|�dS)z# Add a parent device to the mpath. )r:N)rr,r:rkr�appendZsetup)r+�parentr-r-r.�
add_parentas
zMultipathDevice.add_parentcs:tt|�j|�tj|jkr6tj|jkr6|jjtj�dS)N)rRrs�_add_parentr�remoter&r')r+ru)rTr-r.rwkszMultipathDevice._add_parentcsTtt|�j��tj|jkrPtj�jkrPt�fdd�|jD��rP|jjtj�dS)Nc3s&|]}tj|jkr|�kr|VqdS)N)rrxr&)r6�p)rur-r.r7ssz1MultipathDevice._remove_parent.<locals>.<genexpr>)	rRrs�_remove_parentrrxr&�anyr�remove)r+ru)rT)rur.rzpszMultipathDevice._remove_parentFcCsLt||j||j|jd�tj�tjd|jg�}|rHtj	d|jdd��dS)z Open, or set up, a device. )rer:rfZ	multipathz$multipath activation failed for '%s'T)Zhardware_faultN)
rr,r:rfr	rcrZrun_programrZ
MPathError)r+reZrcr-r-r.rgvs
zMultipathDevice._setupcCstj|�|j�tj�dS)N)r�_post_setupZsetup_partitionsr	rc)r+r-r-r.r}�s
zMultipathDevice._post_setup)NNNNr)F)rErFrGrHrIrqrJrKrZ
MULTIPATH_APPrrr"rLrrr9rvrwrzrgr}r\r-r-)rTr.rs1s 



rsc@s,eZdZdZdZddgZdd�Zdd�Zd	S)
�iScsiDiskDevicez An iSCSI disk. Ziscsiziscsi-initiator-utilszdracut-networkcKs |jd�|_|jd�|_|jd�|_|jd�|_|jd�|_|jd�}|jd�|_yt|jd��|_Wn4t	k
r�}zt
jd	|�d
|_WYd
d
}~XnX|jd�|_|jd�|_
|jd
�|_|jd�|_tj||f|�tj||j|jd�t
jd||j|j|j|j
|j|j�|j�d
S)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword exists: does this device exist?
            :type exists: bool
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword format: this device's formatting
            :type format: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword str wwn: the disk's WWN
            :keyword target: the name of the iscsi target
            :type target: str
            :keyword lun: lun of the target
            :type node: str
            :keyword iface: name of network interface to use for operation
            :type iface: str
            :keyword initiator: initiator name
            :type initiator: str
            :keyword offload: a partial offload device (qla4xxx)
            :type: bool
            :keyword address: ip address of the target
            :type: str
            :keyword port: port of the target
            :type: str
        �node�ibft�nic�	initiator�offloadr,�target�lunz-Failed to set lun attribute of iscsi disk: %sN�address�port�iface�id_path)Zhost_addressr�zbcreated new iscsi disk %s from target: %s lun: %s portal: %s:%s interface: %s partial offload: %s))�poprr�r�r�r�r�r$r�r%ri�warningr�r�r�r�rr"rrjr1)r+�device�kwargsr,�er-r-r.r"�s*
ziScsiDiskDevice.__init__cCs�|jrtdg�S|jdkr t�S|jj}d|kr8d|}d}|jjr�|jjr�|d|jj|jjf7}|jjr�|jjr�|d|jj|jjf7}d}|jdkr�d|jj	|jf}|d	||jj
||jjf7}d
|j}t||g�S)Nzrd.iscsi.firmware�:z[%s]znetroot=iscsi:z%s:%sz:%s:%sr�defaultz
@%s::%d%s::%szrd.iscsi.initiator=%s)
r�r/rr�ZusernameZpasswordZ
r_usernameZ
r_passwordr�r�r�r,r�)r+r�ZnetrootZ
iface_specr�r-r-r.rp�s,




z!iScsiDiskDevice.dracut_setup_argsN)rErFrGrHrIrqr"rpr-r-r-r.r~�s
6r~c@s,eZdZdZdZddgZdd�Zdd�Zd	S)
�FcoeDiskDevicez An FCoE disk. rz
fcoe-utilszdracut-networkcKsd|jd�|_|jd�|_|jd�|_tj||f|�tj||jd�tjd||j|j�|j	�dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword exists: does this device exist?
            :type exists: bool
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword format: this device's formatting
            :type format: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword str wwn: the disk's WWN
            :keyword nic: name of NIC to use
            :keyword identifier: ???
        r��
identifierr�)r�z"created new fcoe disk %s (%s) @ %sN)
r�r�r�r�rr"rrirjr1)r+r�r�r-r-r.r"�szFcoeDiskDevice.__init__cCspd}x(t�jD]\}}}||jkrPqWt�S|r8d}nd}|jt�jkr^td|j|fg�Std|g�SdS)NT�dcbZnodcbz
fcoe=%s:%szfcoe=edd:%s)rZnicsr�r/Z
added_nics)r+r�r�Z
_auto_vlanZdcb_optr-r-r.rps
z FcoeDiskDevice.dracut_setup_argsN)rErFrGrHrIrqr"rpr-r-r-r.r��s
r�c@s8eZdZdZdZdd�Zdd�Zedd��Zd	d
�Z	dS)�ZFCPDiskDevicez A mainframe ZFCP disk. �zfcpcKsN|jd�|_|jd�|_|jd�|_tj||f|�|j�|jjt	j
�dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword exists: does this device exist?
            :type exists: bool
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword format: this device's formatting
            :type format: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword str wwn: the disk's WWN
            :keyword hba_id: ???
            :keyword wwpn: ???
            :keyword fcp_lun: ???
        �hba_id�wwpn�fcp_lunN)r�r�r�r�rr"r1r&r'rrx)r+r�r�r-r-r.r"szZFCPDiskDevice.__init__cCs(tj|�}|d|j|j|jd�7}|S)Nz=  hba_id = %(hba_id)s  wwpn = %(wwpn)s  fcp_lun = %(fcp_lun)s)r�r�r�)rr2r�r�r�)r+r3r-r-r.r24s
zZFCPDiskDevice.__repr__cCsd|j|j|jd�S)Nz8FCP device %(device)s with WWPN %(wwpn)s and LUN %(lun)s)r�r�r�)r�r�r�)r+r-r-r.r9<szZFCPDiskDevice.descriptioncCsFddlm}||j�r(td|jg�}ntd|j|j|jfg�}|S)Nr)�has_auto_lun_scanz
rd.zfcp=%szrd.zfcp=%s,%s,%s)r�r�r�r/r�r�)r+r�Zdracut_argsr-r-r.rpCs

z ZFCPDiskDevice.dracut_setup_argsN)
rErFrGrHrIr"r2rLr9rpr-r-r-r.r�sr�c@s8eZdZdZdZdd�Zedd��Zdd�Zd	d
�Z	dS)�
DASDDevicez A mainframe DASD. ZdasdcKs,|jd�|_|jd�|_tj||f|�dS)a�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword exists: does this device exist?
            :type exists: bool
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword format: this device's formatting
            :type format: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword str wwn: the disk's WWN
            :keyword busid: bus ID
            :keyword opts: options
            :type opts: dict with option name keys and option value values
        �busid�optsN)r�r�r�rr")r+r�r�r-r-r.r"TszDASDDevice.__init__cCs
d|jS)NzDASD device %s)r�)r+r-r-r.r9iszDASDDevice.descriptioncCsdd�|jj�D�S)NcSs$g|]\}}|dkrd||f�qS)�1z%s=%sr-)r6�k�vr-r-r.�
<listcomp>nsz'DASDDevice.get_opts.<locals>.<listcomp>)r��items)r+r-r-r.�get_optsmszDASDDevice.get_optsc
Cs&d}d}tjj|�rLt|�}x&|j�D]}|j|j�r&|j�}Pq&W|j�|st|j}x|j	�D]}|d|7}q`Wddddd�}g}|j
�}xb|dd�D]R}	y(|	j
d	�\}
}t|�r�|j||
�Wq�t
tfk
r�tjd
|	�Yq�Xq�W|�rtd|jdj|�fg�Std
|jg�SdS)Nz/etc/dasd.confz %sZdiagZro�erplog�failfast)Zuse_diag�readonlyr�r�r
�=zfailed to parse dasd feature %szrd.dasd=%s(%s)r�z
rd.dasd=%s)rNr>�isfile�open�	readlines�
startswithr��rstrip�closer��splitr$rt�
ValueError�KeyErrorrir�r/r8)r+Zconf�line�f�lZdevopt�	translater��parts�chunkZfeat�valr-r-r.rpps<zDASDDevice.dracut_setup_argsN)
rErFrGrHrIr"rLr9r�rpr-r-r-r.r�Osr�c@sBeZdZdZdZdgZdd�Zdd�Zedd	��Z	ed
d��Z
dS)
�NVDIMMNamespaceDevicez Non-volatile memory namespace �nvdimmZndctlcKsh|jd�|_|jd�|_|jd�|_|jd�|_tj||f|�|j�|jj	t
j�|jj	t
j�dS)a=
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword exists: does this device exist?
            :type exists: bool
            :keyword size: the device's size
            :type size: :class:`~.size.Size`
            :keyword parents: a list of parent devices
            :type parents: list of :class:`StorageDevice`
            :keyword format: this device's formatting
            :type format: :class:`~.formats.DeviceFormat` or a subclass of it
            :keyword mode: mode of the namespace
            :type mode: str
            :keyword devname: name of the namespace (e.g. 'namespace0.0')
            :type devname: str
            :keyword sector_size: sector size of the namespace in sector mode
            :type sector_size: str
        �mode�devnamer��sector_sizeN)
r�r�r�r��_sector_sizerr"r1r&r'rr(r�)r+r�r�r-r-r.r"�szNVDIMMNamespaceDevice.__init__cCs<tj|�}|d|j|jd�7}|jr8|dd|ji7}|S)Nz(  mode = %(mode)s  devname = %(devname)s)r�r�z  sector size = %(sector_size)sr�)rr2r�r�r�)r+r3r-r-r.r2�s
zNVDIMMNamespaceDevice.__repr__cCsd|j|j|jd�S)NzBNVDIMM namespace %(devname)s in %(mode)s mode exported as %(path)s)r�r�r>)r�r�r>)r+r-r-r.r9�sz!NVDIMMNamespaceDevice.descriptioncCs|jS)N)r�)r+r-r-r.r��sz!NVDIMMNamespaceDevice.sector_sizeN)rErFrGrHrIrqr"r2rLr9r�r-r-r-r.r��s	r�)+ZgiZrequire_versionZ
gi.repositoryrr`rNrrrZ
devicelibsrr<rZstorage_logrr	rr
ZtasksrrZloggingZ	getLoggerri�librZstoragerZ	containerrZnetworkrrarrrMr]rsr~r�r�r�r�r-r-r-r.�<module>s8
v2VU]48R