o
    ÑÊb@_  ã                   @   sH  d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZm	Z	 ddl
mZ dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ ZG d+d,„ d,eƒZ G d-d.„ d.e ƒZ!G d/d0„ d0e!ƒZ"G d1d2„ d2e!ƒZ#G d3d4„ d4e ƒZ$G d5d6„ d6e ƒZ%dS )7é    Né   )Úlog)ÚStoragePoolÚStorageVolume)Úxmlutilc              
   C   sd   z|   |¡}| ¡  |dfW S  tjy1 } z| ¡ r#| ¡ tjkr#‚ d|fW  Y d}~S d}~ww )z
    Try to find a volume matching the full passed path. Call info() on
    it to ensure the volume wasn't removed behind libvirt's back
    N)ÚstorageVolLookupByPathÚinfoÚlibvirtÚlibvirtErrorÚget_error_codeÚVIR_ERR_NO_STORAGE_VOL)ÚconnÚpathÚvolÚe© r   ú//usr/share/virt-manager/virtinst/diskbackend.pyÚ_lookup_vol_by_path   s   

€÷r   c                 C   s&   t j |¡}||  ¡ v r|  |¡S dS )zÙ
    Try to lookup a volume for 'path' in parent 'pool' by it's filename.
    This sometimes works in cases where full volume path lookup doesn't,
    since not all libvirt storage backends implement path lookup.
    N)Úosr   ÚbasenameÚlistVolumesÚstorageVolLookupByName)Úpoolr   Únamer   r   r   Ú_lookup_vol_by_basename*   s   
ÿr   c                 C   sF   zt  | t j¡}t  |dd¡}t  |¡ W |S  ty"   d}Y |S w )Nr   é   )r   ÚopenÚO_RDONLYÚlseekÚcloseÚ	Exception)r   ÚfdÚsizer   r   r   Ú_get_block_size5   s   þþr#   c                 C   s,   t j | ¡sdS t| ƒrt| ƒS t j | ¡S ©Nr   )r   r   ÚexistsÚ_stat_is_blockr#   Úgetsize©r   r   r   r   Ú	_get_size@   s
   r)   c                 C   s&   t j | ¡sdS t t  | ¡tj ¡S ©NF)r   r   r%   ÚstatÚS_ISBLKÚST_MODEr(   r   r   r   r&   H   s   r&   c              
   C   sà   t | |ƒ\}}|r|| ¡ fS t | tj |¡¡}|sdS z#tj|dd t | |ƒ\}}|r?zt||ƒ}W n	 t	y>   Y nw W n t	yZ } zd}d}t
|ƒ}W Y d}~nd}~ww |sl|sl|rlttdƒ||dœ ƒ‚||fS )z€
    Try to lookup storage objects for the passed path.

    Returns (volume, parent pool). Only one is returned at a time.
    ©NNT)ÚrefreshNz$Cannot use storage %(path)s: %(err)s)r   Úerr)r   ÚstoragePoolLookupByVolumer   Úlookup_pool_by_pathr   r   ÚdirnameÚensure_pool_is_runningr   r    ÚstrÚ
ValueErrorÚ_)r   r   r   Úignorer   Úverrr   r   r   r   Ú_check_if_path_managedN   s6   ÿ€€ýÿr:   c                 C   sF   | pd} g d¢}t | ƒrdS |D ]}|  |d ¡s| |kr  dS qdS )NÚ )z/devz/sysz/procFú/T)Úpath_is_urlÚ
startswith)r   Úskip_prefixesÚprefixr   r   r   Ú_can_auto_manages   s   ÿrA   c                 C   s.   ddl m} || ƒ}|jdkr|j d¡S | S )Nr   )ÚURIÚrbdr<   )ÚurirB   Úschemer   Ústrip)r   rB   Úuriobjr   r   r   Ú_get_storage_search_path€   s
   
rH   c                 C   sæ   | j  ¡ sdS |sdS t|ƒst| |ƒstj |¡}t|ƒ}t| |ƒ\}}|s-|s-t	|ƒs2|||fS tj 
|¡}tj |¡ dd¡}|sFd}t | |¡}t d||¡ t| ƒ}||_|j|_||_|jdddd}t||ƒ}|||fS )	zP
    If path is not managed, try to create a storage pool to probe the path
    )NNNú r7   Údirpoolz%Attempting to build pool=%s target=%sFT)ÚbuildÚcreateÚ	autostart)ÚsupportÚconn_storager=   Úpath_is_network_volr   r   ÚabspathrH   r:   rA   r3   r   Úreplacer   Úfind_free_namer   Údebugr   ÚTYPE_DIRÚtypeÚtarget_pathÚinstallr   )r   r   Ú
searchpathr   r   r3   ÚpoolnameÚpoolxmlr   r   r   Úmanage_path‹   s.   



r\   c                 C   s   t t d| pd¡ƒS )z!
    Detect if path is a URL
    z[a-zA-Z]+(\+[a-zA-Z]+)?://.*r;   )ÚboolÚreÚmatchr(   r   r   r   r=   ­   s   r=   c                 C   s.   |   ¡ D ]}|r|j|kr|jdk  S qdS )zF
    Detect if path is a network volume such as rbd, gluster, etc
    ÚnetworkF)Úfetch_all_volsrW   rV   )r   r   Úvolxmlr   r   r   rP   ´   s
   €rP   c                 C   s¶   |r|j r|j S |r| ¡ }|tjkrdS |tjkrdS |r9| ¡ d }|tjkr+dS |tjkr2dS |tjkr9dS | rYt| ƒrAdS |rKt| ƒsIdS dS t	j
 | ¡rSdS t| ƒrYdS dS )z,
    Try to get device type for volume.
    Úblockr`   r   ÚfileÚdir)rV   Úget_disk_typer   Ú
TYPE_BLOCKÚTYPE_NETWORKr   Ú	TYPE_FILEr=   rA   r   r   Úisdirr&   )r   Úvol_xmlÚ
vol_objectÚpool_xmlÚremoteÚtr   r   r   Ú_get_dev_type¾   s8   





ûrp   c                 C   sZ   |du rdS zt | |ƒ\}}|}|rW dS |  ¡ s tj |¡W S W dS  ty,   Y dS w )z{
    Return True if the path certainly exists, False if we are unsure.
    See DeviceDisk entry point for more details
    NFT)r:   Ú	is_remoter   r   r%   r    )r   r   r   r   r8   r   r   r   Úpath_definitely_existsë   s   ÿýýrr   Úsetfaclc                 C   sh   t dd| | g}tj|tjtjd}| ¡ \}}t d|¡ |s"|r)t d||¡ |jdkr2t|ƒ‚d S )Nz--modifyz	user:%s:x©ÚstdoutÚstderrzRan command '%s'zout=%s
err=%sr   )	ÚSETFACLÚ
subprocessÚPopenÚPIPEÚcommunicater   rT   Ú
returncoder6   )r3   ÚusernameÚcmdÚprocÚoutr0   r   r   r   Ú_fix_perms_acl  s   þ
ÿr   c                 C   sR   t  d| ¡ t | ¡j}|tjB }t | |¡ t | ¡j|kr'ttdƒ|  ƒ‚d S )NzSetting +x on %sz!Permissions on '%s' did not stick)	r   rT   r   r+   Úst_modeÚS_IXOTHÚchmodr6   r7   )r3   ÚmodeÚnewmoder   r   r   Ú_fix_perms_chmod  s   

ÿýr‡   c                 C   s¤   d}i }| D ]I}|r1zt ||ƒ W q ty0 } zt d|¡ t d¡ d}W Y d }~nd }~ww zt|ƒ W q tyO } zt|ƒ||< W Y d }~qd }~ww |S )NTzsetfacl failed: %sztrying chmodF)r   r    r   rT   r‡   r5   )Údirlistr}   ÚuseaclÚerrdictr3   r   r   r   r   Úset_dirs_searchable#  s(   

€ý€ÿr‹   c           
      C   sè   zt  | ¡}W n
 ty   Y dS w ||jkrtj}n||jkr$tj}ntj}t|j	|@ ƒr0dS d| g}zt
j|t
jt
jd}| ¡ \}}W n tyU   t d¡ Y dS w |jdkrdt d||¡ dS d| }	tt |	 d	d
¡|¡ƒS )z8
    Check if passed directory is searchable by uid
    FTÚgetfaclrt   z Didn't find the getfacl command.r   zCmd '%s' failed: %szuser:%s:..xzutf-8rR   )r   r+   ÚOSErrorÚst_uidÚS_IXUSRÚst_gidÚS_IXGRPrƒ   r]   r‚   rx   ry   rz   r{   r   rT   r|   r^   ÚsearchÚencode)
r3   Úuidr}   ÚstatinfoÚflagr~   r   r€   r0   Úpatternr   r   r   Ú_is_dir_searchable9  s8   ÿ

þ
þ
r˜   c                 C   s\   t j | ¡r| }d}nt j | ¡\}}g }|r,t|||ƒs"| |¡ t j |¡\}}|s|S )z¡
    Check each dir component of the passed path, see if they are
    searchable by the uid/username, and return a list of paths
    which aren't searchable
    ú-)r   r   rj   Úsplitr˜   Úappend)r   r”   r}   r3   ÚbaseÚfixlistr   r   r   Úis_path_searchable_  s   
ýrž   c                   @   ó€   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú_StorageBasezA
    Storage base class, defining the API used by DeviceDisk
    c                 C   s   || _ d | _d S ©N)Ú_connÚ_parent_pool_xml©Úselfr   r   r   r   Ú__init__|  s   
z_StorageBase.__init__c                 C   ó   t ƒ ‚r¡   ©ÚNotImplementedError©r¥   r   r   r   Úget_size€  ó   z_StorageBase.get_sizec                 C   r§   r¡   r¨   rª   r   r   r   Úget_dev_type‚  r¬   z_StorageBase.get_dev_typec                 C   r§   r¡   r¨   rª   r   r   r   Úget_driver_type„  r¬   z_StorageBase.get_driver_typec                 C   r§   r¡   r¨   rª   r   r   r   Úget_vol_install†  r¬   z_StorageBase.get_vol_installc                 C   r§   r¡   r¨   rª   r   r   r   Úget_vol_objectˆ  r¬   z_StorageBase.get_vol_objectc                 C   r§   r¡   r¨   rª   r   r   r   Úget_parent_poolŠ  r¬   z_StorageBase.get_parent_poolc                 C   s.   | j s|  ¡ rt| j|  ¡  d¡d| _ | j S ©Nr   ©Úparsexml)r£   r±   r   r¢   ÚXMLDescrª   r   r   r   Úget_parent_pool_xmlŒ  s
   ÿz _StorageBase.get_parent_pool_xmlc                 C   r§   r¡   r¨   rª   r   r   r   Úvalidate‘  r¬   z_StorageBase.validatec                 C   r§   r¡   r¨   rª   r   r   r   Úget_path“  r¬   z_StorageBase.get_pathc                 C   ó   dS r*   r   rª   r   r   r   Úis_stub•  ó   z_StorageBase.is_stubc                 C   r§   r¡   r¨   rª   r   r   r   Úis_size_conflict™  r¬   z_StorageBase.is_size_conflictc                 C   r§   r¡   r¨   rª   r   r   r   Úwill_create_storage›  r¬   z _StorageBase.will_create_storagec                 C   s   |}t  d| jj ¡‚)Nz%s can't create storage)r   ÚDevErrorÚ	__class__Ú__name__)r¥   Úmeterr8   r   r   r   rL   ž  s   
ÿz_StorageBase.createN)rÀ   Ú
__module__Ú__qualname__Ú__doc__r¦   r«   r­   r®   r¯   r°   r±   r¶   r·   r¸   rº   r¼   r½   rL   r   r   r   r   r    x  s     r    c                   @   óx   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú_StorageCreatorzK
    Base object for classes that will actually create storage on disk
    c                 C   s.   t  | |¡ d | _d | _d | _d | _d | _d S r¡   )r    r¦   Ú_poolÚ_vol_installÚ_pathÚ_sizeÚ	_dev_typer¤   r   r   r   r¦   ¨  ó   
z_StorageCreator.__init__c                 C   ó   t ‚r¡   r¨   ©r¥   rÁ   r   r   r   rL   ¶  r»   z_StorageCreator.createc                 C   rÍ   r¡   r¨   rª   r   r   r   r·   ¸  r»   z_StorageCreator.validatec                 C   rÍ   r¡   r¨   rª   r   r   r   r«   º  r»   z_StorageCreator.get_sizec                 C   s\   | j r+| js+t| j| j j d¡d}|  ¡ dkr | j j| _| jS tj	 
|j| j j¡| _| jS )Nr   r³   r`   )rÈ   rÉ   r   r¢   r   rµ   r­   r   r   r   ÚjoinrW   )r¥   Úxmlobjr   r   r   r¸   ½  s   ÿ
þ
ÿz_StorageCreator.get_pathc                 C   ó   | j S r¡   ©rÈ   rª   r   r   r   r¯   È  r¬   z_StorageCreator.get_vol_installc                 C   rÑ   r¡   rÒ   rª   r   r   r   Úget_vol_xmlÊ  r¬   z_StorageCreator.get_vol_xmlc                 C   s,   | j st| j| jd |  ¡ | j ¡ ƒ| _ | j S r¡   )rË   rp   rÉ   rÈ   r¶   r¢   rq   rª   r   r   r   r­   Í  s   þz_StorageCreator.get_dev_typec                 C   s   | j r| j  ¡ r| j jS dS ©NÚraw)rÈ   Úsupports_formatÚformatrª   r   r   r   r®   Ô  s   
z_StorageCreator.get_driver_typec                 C   r¹   ©NTr   rª   r   r   r   r½   Ú  r»   z#_StorageCreator.will_create_storagec                 C   ó   d S r¡   r   rª   r   r   r   r°   Ü  r»   z_StorageCreator.get_vol_objectc                 C   s   | j r| j jS d S r¡   )rÈ   r   rª   r   r   r   r±   Þ  s   z_StorageCreator.get_parent_poolc                 C   r¹   r*   r   rª   r   r   r   r%   â  r»   z_StorageCreator.existsN)rÀ   rÂ   rÃ   rÄ   r¦   rL   r·   r«   r¸   r¯   rÓ   r­   r®   r½   r°   r±   r%   r   r   r   r   rÆ   ¤  s    rÆ   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚManagedStorageCreatorzÐ
    Handles storage creation via libvirt APIs. All the actual creation
    logic lives in StorageVolume, this is mostly about pulling out bits
    from that class and mapping them to DeviceDisk elements
    c                 C   s   t  | |¡ |j| _|| _d S r¡   )rÆ   r¦   r   rÇ   rÈ   )r¥   r   Úvol_installr   r   r   r¦   ì  s   
zManagedStorageCreator.__init__c                 C   s   | j j|dS )N)rÁ   )rÈ   rX   rÎ   r   r   r   rL   ò  s   zManagedStorageCreator.createc                 C   ó
   | j  ¡ S r¡   )rÈ   r¼   rª   r   r   r   r¼   ô  ó   
z&ManagedStorageCreator.is_size_conflictc                 C   rÜ   r¡   )rÈ   r·   rª   r   r   r   r·   ö  rÝ   zManagedStorageCreator.validatec                 C   s   t | jjƒd d d S )Nç      @)ÚfloatrÈ   Úcapacityrª   r   r   r   r«   ø  s   zManagedStorageCreator.get_sizeN)	rÀ   rÂ   rÃ   rÄ   r¦   rL   r¼   r·   r«   r   r   r   r   rÚ   æ  s    rÚ   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚCloneStorageCreatorzŸ
    Handles manually copying local files for Cloner

    Many clone scenarios will use libvirt storage APIs, which will use
    the ManagedStorageCreator
    c                 C   s.   t  | |¡ || _|| _|| _|| _|| _d S r¡   )rÆ   r¦   rÉ   Ú_output_pathÚ_input_pathrÊ   Ú_sparse)r¥   r   Úoutput_pathÚ
input_pathr"   Úsparser   r   r   r¦     rÌ   zCloneStorageCreator.__init__c                 C   rÑ   r¡   )rÊ   rª   r   r   r   r«     r¬   zCloneStorageCreator.get_sizec                 C   s´   d}d }|   ¡ dkrt| jƒ}nt tj tj | j¡¡¡}|j|j	 }t
| jƒd d d }||krV| jr;tdƒ}nd}tdƒ}|rV|d7 }|tdƒ|d	 |d	 d
œ 7 }||fS )NFrc   é   zkThe filesystem will not have enough free space to fully allocate the sparse file when the guest is running.Tz2There is not enough free space to create the disk.rI   z+%(mem1)s M requested > %(mem2)s M availablei   )Úmem1Úmem2)r­   r)   rÉ   r   Ústatvfsr   r3   rQ   Úf_frsizeÚf_bavailÚintrÊ   rä   r7   )r¥   ÚretÚmsgÚavailÚvfsÚneedr   r   r   r¼     s(   
ÿÿz$CloneStorageCreator.is_size_conflictc                 C   sL   | j d u rttd|  ¡  ƒƒ‚|  ¡ \}}|rt|ƒ‚|r$t |¡ d S d S )Nz+size is required for non-existent disk '%s')rÊ   r6   r7   r¸   r¼   r   Úwarning)r¥   r0   rð   r   r   r   r·   )  s   
ÿÿzCloneStorageCreator.validatec                 C   sN   t dƒdtj | j¡i }t|  ¡ d d d ƒ}| ||¡ |  ||¡ d S )NzCloning %(srcfile)sÚsrcfilerè   )	r7   r   r   r   rã   rî   r«   ÚstartÚ_clone_local)r¥   rÁ   ÚtextÚ
size_bytesr   r   r   rL   4  s   ÿzCloneStorageCreator.createc              
   C   s  | j dkrt d¡ d S | j | jkrt d¡ d S tj | j¡sN| jrNd}d}d }zt | jtj	tj
B d¡}t ||¡ W |rDt |¡ n|rMt |¡ w w d}d}t d	| j | j||¡ d
}d\}}z•zWt | j tj¡}t | jtj	tj
B d¡}d}		 t ||¡}
t|
ƒ}|dkr| ¡  n+|r||
krt ||d¡ nt ||
¡}||kr¬| ¡  n|	|7 }	|	|k r¹| |	¡ q|W n& tyá } ztjddd tdƒ| j | jt|ƒdœ }t|ƒd ‚d }~ww W |d urìt |¡ |d ur÷t |¡ d S d S |d urt |¡ |d urt |¡ w w )Nz	/dev/nullz"Source dev was /dev/null. Skippingz.Source and destination are the same. Skipping.i   Ti   i    Fz0Local Cloning %s to %s, sparse=%s, block_size=%ss                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   r.   r   r   zError while cloning)Úexc_infozBError cloning diskimage %(inputpath)s to %(outputpath)s: %(error)s)Ú	inputpathÚ
outputpathÚerror)rã   r   rT   râ   r   r   r%   rä   r   ÚO_WRONLYÚO_CREATÚ	ftruncater   r   ÚreadÚlenÚendr   ÚwriteÚupdater   r7   r5   ÚRuntimeError)r¥   rÁ   rù   Úclone_block_sizerç   r!   ÚzerosÚsrc_fdÚdst_fdÚiÚlÚsÚbr   rð   r   r   r   r÷   >  s–   


ÿ
€ÿÿþÿ
ð€þþ
€ù€	
ÿ
þ

ÿz CloneStorageCreator._clone_localN)
rÀ   rÂ   rÃ   rÄ   r¦   r«   r¼   r·   rL   r÷   r   r   r   r   rá   ü  s    	
rá   c                   @   rŸ   )ÚStorageBackendStubz‚
    Class representing a storage path for a parsed XML disk, that we
    don't want to do slow resolving of unless requested
    c                 C   s"   t  | |¡ || _|| _|| _d S r¡   )r    r¦   rÉ   rË   Ú_driver_type)r¥   r   r   Údev_typeÚdriver_typer   r   r   r¦     s   
zStorageBackendStub.__init__c                 C   rÑ   r¡   )rÉ   rª   r   r   r   r¸   ”  r¬   zStorageBackendStub.get_pathc                 C   rÙ   r¡   r   rª   r   r   r   r°   –  r»   z!StorageBackendStub.get_vol_objectc                 C   rÙ   r¡   r   rª   r   r   r   rÓ   ˜  r»   zStorageBackendStub.get_vol_xmlc                 C   rÙ   r¡   r   rª   r   r   r   r±   š  r»   z"StorageBackendStub.get_parent_poolc                 C   r¹   r$   r   rª   r   r   r   r«   œ  r»   zStorageBackendStub.get_sizec                 C   r¹   rØ   r   rª   r   r   r   r%   ž  r»   zStorageBackendStub.existsc                 C   rÑ   r¡   )rË   rª   r   r   r   r­      r¬   zStorageBackendStub.get_dev_typec                 C   rÑ   r¡   )r  rª   r   r   r   r®   ¢  r¬   z"StorageBackendStub.get_driver_typec                 C   rÙ   r¡   r   rª   r   r   r   r·   ¥  r»   zStorageBackendStub.validatec                 C   rÙ   r¡   r   rª   r   r   r   r¯   §  r»   z"StorageBackendStub.get_vol_installc                 C   r¹   ©N)FNr   rª   r   r   r   r¼   ©  r»   z#StorageBackendStub.is_size_conflictc                 C   r¹   rØ   r   rª   r   r   r   rº   «  r»   zStorageBackendStub.is_stubc                 C   r¹   r*   r   rª   r   r   r   r½   ­  r»   z&StorageBackendStub.will_create_storageN)rÀ   rÂ   rÃ   rÄ   r¦   r¸   r°   rÓ   r±   r«   r%   r­   r®   r·   r¯   r¼   rº   r½   r   r   r   r   r  ˆ  s     r  c                   @   rÅ   )ÚStorageBackendza
    Class that carries all the info about any existing storage that
    the disk references
    c                 C   sf   t  | |¡ || _|| _|| _| jd urd | _| jr"| js"t d¡‚d | _d | _d | _	d | _
d | _d S )Nzparent_pool must be specified)r    r¦   Ú_vol_objectÚ_parent_poolrÉ   r   r¾   Ú_vol_xmlr£   Ú_existsrÊ   rË   )r¥   r   r   rl   Úparent_poolr   r   r   r¦   ¶  s   
ÿ
zStorageBackend.__init__c                 C   s   | j r|  ¡ jS | jS r¡   )r  rÓ   rW   rÉ   rª   r   r   r   r¸   Ð  s   
zStorageBackend.get_pathc                 C   rÑ   r¡   )r  rª   r   r   r   r°   Õ  r¬   zStorageBackend.get_vol_objectc                 C   s2   | j d u rt| j| j d¡d| _ | j| j _| j S r²   )r  r   r¢   r  rµ   r  r   rª   r   r   r   rÓ   ×  s   

ÿ
zStorageBackend.get_vol_xmlc                 C   rÑ   r¡   )r  rª   r   r   r   r±   Þ  r¬   zStorageBackend.get_parent_poolc                 C   sL   | j du r#d}| jr|  ¡ j}n| jrt| jƒ}t|ƒd d d | _ | j S )z1
        Return size of existing storage
        Nr   rÞ   )rÊ   r  rÓ   rà   rÉ   r)   rß   )r¥   rï   r   r   r   r«   á  s   

zStorageBackend.get_sizec                 C   s¸   | j d u rY| jrd| _ | j S | jd u rd| _ | j S |  ¡ dks1| j ¡ s1tj | j¡r1d| _ | j S | j	r:d| _ | j S |  ¡ dkrFd| _ | j S | j ¡ rVt
| jƒsVd| _ | j S d| _ | j S )NTr`   F)r  r  rÉ   r­   r¢   rq   r   r   r%   r  rA   rª   r   r   r   r%   î  s6   

íïÿþóõ

÷ÿÿzStorageBackend.existsc                 C   sB   | j du rd}| jr|  ¡ }t| j|| j|  ¡ | j ¡ ƒ| _ | j S )z?
        Return disk 'type' value per storage settings
        N)rË   r  rÓ   rp   rÉ   r¶   r¢   rq   )r¥   rk   r   r   r   r­     s   
þzStorageBackend.get_dev_typec                 C   s$   | j r|  ¡  ¡ r|  ¡ jS dS d S rÔ   )r  rÓ   rÖ   r×   rª   r   r   r   r®     s
   
zStorageBackend.get_driver_typec                 C   rÙ   r¡   r   rª   r   r   r   r·     r»   zStorageBackend.validatec                 C   rÙ   r¡   r   rª   r   r   r   r¯     r»   zStorageBackend.get_vol_installc                 C   r¹   r  r   rª   r   r   r   r¼     r»   zStorageBackend.is_size_conflictc                 C   r¹   r*   r   rª   r   r   r   r½   !  r»   z"StorageBackend.will_create_storageN)rÀ   rÂ   rÃ   rÄ   r¦   r¸   r°   rÓ   r±   r«   r%   r­   r®   r·   r¯   r¼   r½   r   r   r   r   r  ±  s    r  )&r   r^   r+   rx   r	   Úloggerr   Ústorager   r   r;   r   r   r   r#   r)   r&   r:   rA   rH   r\   r=   rP   rp   rr   rw   r   r‡   r‹   r˜   rž   Úobjectr    rÆ   rÚ   rá   r  r  r   r   r   r   Ú<module>   sD   %"
-&,B )