
    W'Fg                         S SK r SSKJr  SSKJr  SSKJr  SSKJr  SSKJrJ	r	J
r
  SS	KJrJrJr  S
 r " S S\5      r " S S\	5      r " S S\5      r " S S\5      rg)    N   )log)diskbackend)progress)xmlutil   )DeviceDeviceAddressDeviceSeclabel)
XMLBuilderXMLChildPropertyXMLPropertyc                 ~    S/nU [         R                  :X  a  [         R                  $ X;   a  [         R                  $ U$ )zD
Sanitize libvirt storage volume format to a valid qemu driver type
iso)
DeviceDisk
TYPE_BLOCKDRIVER_TYPE_RAW)phystypefmtraw_lists      0/usr/share/virt-manager/virtinst/devices/disk.py_qemu_sanitize_drvtyper      s;     wH:((()))
)))J    c                   ^    \ rS rSr/ SQrSr\" S5      r\" SSS9r\" S5      r	\" S	5      r
S
rg)_Host!   )nameport	transportsockethost./@namez./@portTis_intz./@transportz	./@socket N)__name__
__module____qualname____firstlineno___XML_PROP_ORDERXML_NAMEr   r   r   r   r    __static_attributes__r%   r   r   r   r   !   s6    =OHy!Dy.DN+I%Fr   r   c                       \ rS rSrSrg)_DiskSourceAddress+   r%   N)r&   r'   r(   r)   r,   r%   r   r   r.   r.   +   s    r   r.   c                      \ rS rSrSr/ SQrSr\" S5      r\" S5      r	\" S5      r
\" S5      r\" S	5      r\" \5      r\" S
5      r\" S5      r\" S5      r\" S5      r\" SSS9r\" SSS9r\" \SS9rS rS rS rS rSrg)_DiskSource/   zd
Class representing disk <source> block, and various helpers
that only operate on <source> contents
)filedevdirvolumepoolprotocolr   hoststypemanaged	namespaceaddresssourcez./@filez./@devz./@dirz./@poolz	./@volumer"   z./@protocolz./@query./@typez
./@managedTis_yesnoz./@namespacer#   	is_singlec                    SSK Jn  U" U5      nUR                  (       a  UR                  U l        UR                  (       d"  UR
                  (       d  UR                  (       a+  U R                  (       d  U R                  R                  5         UR                  (       a  UR                  U R                  S   l        UR                  (       a  UR                  U R                  S   l	        UR
                  (       a  UR
                  U R                  S   l        UR                  (       a  U R                  (       a=  U R                  S   R                  (       a  UR                  U R                  S   l        OEUR                  U l	        U R                  R                  S5      (       a  U R                  SS U l	        UR                  (       a  UR                  U l        gg)zj
For a passed in path URI like gluster:// or https://, split it
up and set the <disk> properties directly
r   )URIr   /r   N)urirE   schemer8   hostnamer   r   r9   add_newr   pathr    
startswithquery)selfrG   rE   uriobjs       r   set_from_url_DiskSource.set_from_urlL   s   
 	S=="MMDM__v/?/?

JJ &,&6&6DJJqM#??!'DJJqM;;!'DJJqM;;zzdjjm55'-{{

1$"KK	99'',, $		!"DI<<DJ r   c                    [        U R                  5      nU R                  (       a  U R                  S   nU R                  =(       d    SnUR                  (       a  USUR                  -  -  nUS-  nUR
                  (       a:  X!R
                  -  nUR                  (       a  US[        UR                  5      -   -  nU R
                  (       a5  U R
                  R                  S5      (       d  US-  nX R
                  -  nU$ UR                  (       a3  UR                  R                  S5      (       d  US-  nX!R                  -  nU$ )z/
Build a URL from network contents of <source>
r   unknownz+%sz://:rF   )
r   connr9   r8   r   r   r   strrL   r    )rN   r!   rets      r   build_url_from_network"_DiskSource.build_url_from_networki   s     TYY::::a=Dmm(y>>54>>))Cu9999CyysS^++9999'',,s
99C
 
	 [[;;))#..s
;;C
r   c                     SU l         SU l        SU l        SU l        SU l        SU l        SU l        U R                  SS  H  nU R                  U5        M     g)z@
Unset all XML properties that describe the actual source media
N)	r3   r4   r5   r6   r7   r   r8   r9   remove_child)rN   hs     r   clear_source_DiskSource.clear_source   sU     			AAa  r   c                    UR                   S:H  nUR                   nU(       a  SnX@l        [        UR                  5       Hw  u  pV[	        U R                  5      US-   :  a  U R                  R                  5         UR                  U R                  U   l        UR                  U R                  U   l        My     SnU(       a0  SUR                  ;   a  UR                  R                  SS5      S   nOgUR                  (       aH  XrR                  -  nUR                  (       a  XrR                  -  nUR                  S5      (       d  US-  nXqR                  -  nU=(       d    S	U l        g	)
zj
For the passed pool + vol object combo representing a network
volume, set the <source> elements directly
ziscsi-directiscsir    z-iscsi-iqn.z-iscsi-rF   N)r:   r8   	enumerater9   lenrJ   r   r   target_pathsplitsource_namesource_pathendswith)rN   volxmlpoolxmlis_iscsi_directr8   idxpoolhostrK   s           r   set_network_from_storage$_DiskSource.set_network_from_storage   s   
 ",,.8<<H &w}}5MC4::#'*

""$#+==DJJsO #+==DJJsO 	 6   2 22))//	1=bA""+++&&///D}}S))CKDKKDLD	r   )r4   r5   r3   r   r7   r8   rM   r6   N)r&   r'   r(   r)   __doc__r*   r+   r   r3   r4   r5   r7   r6   r   r   r9   r   r8   rM   r:   r;   r<   r.   r=   rP   rX   r]   ro   r,   r%   r   r   r1   r1   /   s    3O Hy!D
h
C
h
Cy!D%FU#Ey!D=)H
#Ey!D,6GN48I1TBG&:4! !r   r1   c                   V   \ rS rSrSrSrSrSrSrSr	Sr
S	rS
r\\	\
\\/rSrSr\\/rSrSrSrSrSrSrSrSrSrSr\S 5       r\S 5       r\S 5       r\S 5       r\SS j5       r \SS j5       r!\SS j5       r"\ SS j5       r#\S 5       r$\S  5       r%/ S!Qr&S" r'\(" S#5      r)\(" S$5      r*\(" S%5      r+\(" S&5      r,\-" \.S'S(9r/\(" S)5      r0\(" S*5      r1\(" S+5      r2\(" S,5      r3\(" S-S'S.9r4\(" S/5      r5\(" S05      r6\(" S15      r7\(" S25      r8\(" S3S'S.9r9\(" S4S'S59r:\(" S6S'S79r;\(" S8S'S79r<\(" S9S'S79r=\(" S:S'S;9r>\(" S<5      r?\(" S=5      r@\(" S>5      rA\(" S?5      rB\(" S@S'S59rC\(" SAS'S59rD\(" SBS'S.9rE\(" SCS'S59rF\(" SD5      rG\(" SE5      rH\(" SF5      rI\(" SG5      rJ\(" SH5      rK\(" SI5      rL\(" SJ5      rM\(" SK5      rN\(" SLS'S59rO\(" SMS'S59rP\(" SNS'S59rQ\(" SOS'S59rR\(" SPS'S59rS\(" SQS'S59rT\-" \USRSS9rV\(" STS'S59rW\(" SUS'S59rX\(" SVS'S59rY\(" SW5      rZ\(" SX5      r[\(" SY5      r\\(" SZ5      r]\(" S[5      r^S\ r_S] r`S^ raS_ rbS` rc\d" \b\c5      reSa rfSb rg\d" \f\g5      rhSc riSd rjSe rkSf rlSg rmSh rnSi roSj rpSk rqSl rrSm rsSn rtSo ruSp rvSq rwSr rxSs rySt rzSu r{Sv r|Sw r}Sx r~Sy rSz rS{ rS| rS} rS~ rS rS rS rS rS rSrg)r      diskphyqemurawnonewritethrough	writeback
directsyncunsafeignoreunmapluncdromfloppyr3   blockr5   r6   networknativec                 .    [         R                  " X5      $ )a=  
Check if path exists.

return True if we are certain, False otherwise. Path may in fact
exist if we return False, but we can't exhaustively know in all
cases.

(In fact if cached storage volume data is out of date, the volume
 may have disappeared behind our back, but that shouldn't have bad
 effects in practice.)
)r   path_definitely_exists)rU   rK   s     r   r   !DeviceDisk.path_definitely_exists   s     11$==r   c                    [         R                  " SU5         " S S[        5      nU" 5       nU(       d  U$ U R                  5       (       a  U$ U R	                  5       (       d  U$ [
        R                  " U5      (       a  U$ [
        R                  " X5      (       a  U$ [        R                  R                  U5      nU R                  R                  R                  5       u  pEU(       d  U$ US:X  a  [        R                  " 5       (       d  U$ XCl        XSl        [
        R$                  " XU5      Ul        UR&                  R)                  5         U$ )a,  
Check if the connection DAC user has search permissions for all the
directories in the passed path.

:returns: Class with:
    - List of the directories the user cannot search, or empty list
    - username we checked for or None if not applicable
    - uid we checked for or None if not application
z$DeviceDisk.check_path_search path=%sc                       \ rS rSrS rSrg)0DeviceDisk.check_path_search.<locals>.SearchData   c                 .    S U l         S U l        / U l        g N)useruidfixlistrN   s    r   __init__9DeviceDisk.check_path_search.<locals>.SearchData.__init__   s     	!r   )r   r   r   N)r&   r'   r(   r)   r   r,   r%   r   r   
SearchDatar      s    "r   r   r   )r   debugobject	is_remoteis_qemu_privilegedr   path_is_urlpath_is_network_volosrK   abspathcapsr!   get_qemu_baselabelr   in_testsuiter   r   is_path_searchabler   reverse)rU   rK   r   
searchdatar   r   s         r   check_path_searchDeviceDisk.check_path_search   s    			8$?	" 	"  \
>>&&((""4((**466wwt$IINN557	!8G0022(;;DtL
""$r   c                 \    [         R                  " U R                  U R                  5      nU$ )z
Try to fix any permission problems found by check_path_search

:returns: Return a dictionary of entries {broken path : error msg}
)r   set_dirs_searchabler   r   )r   errdicts     r   fix_path_searchDeviceDisk.fix_path_search  s(     11""JOO5r   c                 B    [        S U R                  5        5       5      $ )Nc              3   b   #    U  H%  oR                   (       d  M  UR                   U4v   M'     g 7fr   )backing_store).0vols     r   	<genexpr>(DeviceDisk.get_volmap.<locals>.<genexpr>  s+      M!6#:K:K -S&&,!6s   //)dictfetch_all_vols)rU   s    r   
get_volmapDeviceDisk.get_volmap  s)     M!%!4!4!6M M 	Mr   c                 Z    [         R                  U 5      n[         R                  XXBU5      $ )az  
Return a list of VM names that are using the passed path.

:param conn: virConnect to check VMs
:param path: Path to check for
:param shareable: Path we are checking is marked shareable, so
    don't warn if it conflicts with another shareable source.
:param read_only: Path we are checking is marked read_only, so
    don't warn if it conflicts with another read_only source.
)r   r   _path_in_use_by)rU   rK   	shareable	read_onlyvolmaps        r   path_in_use_byDeviceDisk.path_in_use_by   s)     &&t,))$fSSr   c           
          [         R                  U 5      n/ nU H)  nUR                  [         R                  XXBU5      5        M+     U$ )a  
Return a list of lists of VM names that are using the passed paths.
When handling a list of paths, this method is faster than calling
path_in_use_by() separately as it takes time to call conn.fetch_all_vols().

:param conn: virConnect to check VMs
:param paths: Paths to check for
:param shareable: Path we are checking is marked shareable, so
    don't warn if it conflicts with another shareable source.
:param read_only: Path we are checking is marked read_only, so
    don't warn if it conflicts with another read_only source.
)r   r   appendr   )rU   pathsr   r   r   rW   rK   s          r   paths_in_use_byDeviceDisk.paths_in_use_by/  sD     &&t,DJJz11$fQZ[\ 
r   c                     U(       d  / $ / nUnXb;   a.  X&   nXu;   a  O$UR                   nUR                  U5        Xb;   a  M.  / nU R                  5       n	U	 GH$  n
U(       da  XR                  R                  U
R                  R
                  U
R                  R                  4;   a  UR                  U
R                  5        Ml  U
R                  R                   H  nUR                  5       nX;   a.  U
R                  U;  a  UR                  U
R                  5          M  X:w  a  MM  U(       a  UR                  (       a  Mg  U(       a  UR                  (       a  M  UR                  U
R                  5          GM"     GM'     U$ r   )re   r   fetch_all_domainsr   kernelinitrddtbr   devicesrt   get_source_pathr   r   )rU   rK   r   r   r   volsbackpathr   rW   vmsvmrt   	checkpaths                r   r   DeviceDisk._path_in_use_byC  s"   I  "C{HKK!   $$&BEELL"%%,,		BBJJrww'

 002	$);JJrww'$

277#! ( 0 
r   Nc                    SSK Jn  Uc  [        [        SU-  5      5      eU(       d  [	        [        S5      U-  5      e[
        R                  " SXR                  5       5        US-  S-  S-  n	U(       a  Sn
OU	n
U" U 5      nX+l        Xl        Xl	        Xl
        Xkl        X{l        U(       a/  UR                  5       (       d  [        [        S5      5      eX[l        U$ )	z
Helper for building a StorageVolume instance to pass to DeviceDisk
for eventual storage creation.

:param volname: name of the volume to be created
:param size: size in bytes
r   )StorageVolumez3Size must be specified for non existent volume '%s'zpDon't know how to create storage for path '%s'. Use libvirt APIs to manage the parent directory as a pool first.z!Creating volume '%s' on pool '%s'   r   z3Format attribute not supported for this volume type)storager   
ValueError_RuntimeErrorr   r   r   r7   capacity
allocationr   backing_formatsupports_formatformat)rU   volnamepoolobjsizesparser   r   r   r   capallocvolinsts               r   build_vol_installDeviceDisk.build_vol_installn  s     	,<Q  68? @ A B B q "#  $&- . / / 			5||~	/ d{T!D(EE%" -!/**,,  $1 "2 3 3 Nr   c                     / n[        SS5       H>  nU SUS-   -  -  SU-  -  nUS:X  a  U SUS-   -  :  a  SnX-  n UR                  SU5        M@     SnU H"  nUS:X  a  M  US[        S5      U-   S-
  -  -  nM$     U$ )zW
Convert an index in range (1, 1024) to a disk /dev number
(like hda, hdb, hdaa, etc.)
r         r   ra   z%ca)rangeinsertord)numdigitsfactoramtgen_tdigits         r   num_to_targetDeviceDisk.num_to_target  s     AqkF"!,-2<@CaxCB6A:$67JCMM!S! " EzTSX-122E 
 r   c                     SnSnU S   S:X  a  U SS n [        [        U SS 5      5       H0  u  p4US:w  a  SnU[        U5      [        S5      -
  U-   SU-  -  -  nM2     U$ )zB
Convert disk /dev number (like hda, hdb, hdaa, etc.) to an index
r   xr   Nr   r   r   )rc   reversedr   )tgtr   kics        r   target_to_numDeviceDisk.target_to_num  sx    
 q6S=ab'Chs12w/0DAAvCFSX%)bAg66C 1 
r   )_xmltype_devicesnapshot_policydriver_namedriver_typedriver_cachedriver_discarddriver_detect_zeroes	driver_iodriver_iothreaddriver_queueserror_policyauth_usernameauth_secret_typeauth_secret_uuidr>   targetbusc                     [         R                  " U /UQ70 UD6  S U l        SU l        [        R
                  " U R                  U R                  5       U R                  U R                  5      U l
        g )NF)r	   r   _source_volume_errstorage_was_createdr   StorageBackendStubrU   _get_xmlpathr   r   _storage_backend)rN   argskwargss      r   r   DeviceDisk.__init__  s\    .t.v."&#(  + > >IIt((*DMM4;K;K!Mr   r?   z	./@devicez./driver/@namez./driver/@typeTrB   z./auth/@usernamez./auth/secret/@typez./auth/secret/@uuidz./@snapshotz./driver/@copy_on_read)is_onoffz./@sgioz./@rawioz./target/@busz./target/@devz./target/@removablez./target/@rotation_rater#   z
./readonly)is_boolz./shareablez./transientz./transient/@shareBackingr@   z./driver/@cachez./driver/@discardz./driver/@detect_zeroesz./driver/@ioz./driver/@iothreadz./driver/@queuesz./driver/@discard_no_unrefz ./driver/metadata_cache/max_sizez&./driver/metadata_cache/max_size/@unitz./driver/@error_policyz./serialz./wwnz./source/@startupPolicyz./blockio/@logical_block_sizez./blockio/@physical_block_sizez./blockio/@discard_granularityz./iotune/read_bytes_secz./iotune/read_iops_secz./iotune/total_bytes_secz./iotune/total_iops_secz./iotune/write_bytes_secz./iotune/write_iops_secz./source)relative_xpathz./geometry/@cylsz./geometry/@headsz./geometry/@secsz./geometry/@transz./source/reservations/@managedz"./source/reservations/source/@typez"./source/reservations/source/@pathz"./source/reservations/source/@modec                 n   U R                   R                  (       d  U R                   R                  (       a  [        R                  $ U R
                  R                  5       (       d  U R
                  R                  5       $ U R                   R                  (       a  [        R                  $ U R                  $ r   )r>   r7   r6   r   TYPE_VOLUMEr  is_stubget_dev_typer8   TYPE_NETWORK	TYPE_FILEr   s    r   _get_default_typeDeviceDisk._get_default_type&  st    ;;t{{11)))$$,,..((5577;;***~~r   c                 $   U R                  5       (       a  g U R                  R                  5       (       a&  U R                  U R                  :X  a  U R
                  $ U R                  R                  R                  5       (       a  U R                  $ g r   )	is_emptyrU   is_xenr:   r   DRIVER_NAME_PHYsupportconn_disk_driver_name_qemuDRIVER_NAME_QEMUr   s    r   _get_default_driver_name#DeviceDisk._get_default_driver_name/  sh    ==??
 99$))t">'''997799(((r   c                     U R                   U R                  :w  a  gU R                  R                  5       n[	        U R
                  U5      $ )a0  
Set driver type from passed parameters

Where possible, we want to force /driver/@type = "raw" if installing
a QEMU VM. Without telling QEMU to expect a raw file, the emulator
is forced to autodetect, which has security implications:

https://lists.gnu.org/archive/html/qemu-devel/2008-04/msg00675.html
N)r   r&  r  get_driver_typer   r:   )rN   drvtypes     r   _get_default_driver_type#DeviceDisk._get_default_driver_type<  s@     t444''779%dii99r   c                 \    U R                   (       a  U R                   $ U R                  5       $ r   )r   r  r   s    r   	_get_typeDeviceDisk._get_typeL  s"    ==== %%''r   c                     Xl         g r   )r   rN   vals     r   	_set_typeDeviceDisk._set_typeP  s    r   c                 T    U R                   (       a  U R                   $ U R                  $ r   )r   DEVICE_DISKr   s    r   _get_deviceDeviceDisk._get_deviceT  s    <<<<r   c                     Xl         g r   )r   r2  s     r   _set_deviceDeviceDisk._set_deviceX  s    r   c                 T    [         R                  " U R                  UX#5      nX@l        g r   )r   StorageBackendrU   r  )rN   rK   
vol_objectparent_poolbackends        r   _change_backendDeviceDisk._change_backenda  s$    ,,TYY-7F 'r   c                 d    U R                   R                  5       (       a  U R                  5         g g r   )r  r  _resolve_storage_backendr   s    r   set_backend_for_existing_path(DeviceDisk.set_backend_for_existing_pathf  s*    
   ((**))+ +r   c                    SnSnSnSU l         U R                  5       nU R                  [        R                  :X  a  U R
                  R                  5       nU[        R                  :X  aU   U R                  R                  U R
                  R                  5      nUR                  U R
                  R                  5      nUc  Uc  U R#                  5       nU(       a2  U(       d+  U(       d$  [$        R&                  " U R                  U5      u  pbnU R)                  XU5        g! [         aY  n[        U5      U l         [        R                   " SU R
                  R                  U R
                  R                  SS9   SnANSnAff = f)zE
Convert the relevant <source> XML values into self._storage_backend
Nz$Error fetching source pool=%s vol=%sT)exc_info)r  r  r:   r   r  r>   rX   r  rU   storagePoolLookupByNamer7   storageVolLookupByNamer6   	ExceptionrV   r   r   r  r   manage_pathrB  )rN   rK   r?  r@  typedummys          r   rE  #DeviceDisk._resolve_storage_backendn  s;    
"&$$&99
///;;557D*(((I"ii??KK$$&(??KK&&(
 $,$$&D
;/:/F/FIIt0%,U 	T{;  I*-a&'		@KK$$dkk&8&84IIs   +AD! !
F+AE??Fc                     U R                   R                  5       (       a/  U R                   R                  5       (       d  U R                  5         U R                   R                  5       $ )z
Source path is a single string representation of the disk source
storage. For regular storage this is a FS path. For type=network
this is a reconstructed URL. In some cases like rbd:// this may
be an entirely synthetic URL format
)r  r  get_pathrE  r   s    r   r   DeviceDisk.get_source_path  sO     !!))++!!**,,))+$$--//r   c                 @   Ub  UR                  S5      nU R                  R                  5       (       a  [        R                  " S5      e[
        R                  " U R                  U5      u  pnU R                  XU5        U R                  U R                  5       5        g )Nzfile://z=Can't change disk path if storage creation info has been set.)removeprefixr  will_create_storager   DevErrorr   rM  rU   rB  _set_xmlpathr   )rN   newpathr?  r@  s       r   set_source_pathDeviceDisk.set_source_path  s     **95G  4466""$% % .9-D-D		7.$*k 	W+>$..01r   c                     [         R                  " SUR                  S5      5        [         R                  " SUR                  S5      5        U R                  S X5        U R	                  U R                  5       5        g )Nzdisk.set_vol_object: volxml=
%sr   z disk.set_vol_object: poolxml=
%s)r   r   XMLDescrB  rY  r   )rN   r?  r@  s      r   set_vol_objectDeviceDisk.set_vol_object  sc    		4q!	#		5"	$T:;$..01r   c                    [         R                  " SUR                  UR                  R	                  S5      5        [
        R                  " U R                  U5      U l        U R                  U R                  5       5        g )Nz)disk.set_vol_install: name=%s poolxml=
%sr   )r   r   r   r7   r^  r   ManagedStorageCreatorrU   r  rY  r   )rN   vol_installs     r   set_vol_installDeviceDisk.set_vol_install  s`    		>k..66q9	; + A AII{!$$..01r   c                 6    U R                   R                  5       $ r   )r  get_vol_objectr   s    r   rg  DeviceDisk.get_vol_object  s    $$3355r   c                 6    U R                   R                  5       $ r   )r  get_vol_installr   s    r   rj  DeviceDisk.get_vol_install      $$4466r   c                 6    U R                   R                  5       $ r   )r  get_parent_poolr   s    r   rn  DeviceDisk.get_parent_pool  rl  r   c                 6    U R                   R                  5       $ r   )r  get_sizer   s    r   rq  DeviceDisk.get_size  s    $$--//r   c                     SU l         UR                  (       a3  UR                  U l        UR                  U l        UR                  U l        U R
                  R                  X5        g Nr   )r:   	auth_typer  r  r	  r>   ro   rN   rj   rk   s      r    _set_source_network_from_storage+DeviceDisk._set_source_network_from_storage  sN    	!(!6!6D$+$5$5D!$+$<$<D!,,V=r   c                    U R                   R                  5       (       d  U R                   R                  5       (       aF  U R                   R                  5       nU R                   R	                  5       nU R                  X5        g U R                   R                  5       (       a4  U R                  R                  U R                   R                  5       5        g g r   )	r  rg  rj  get_vol_xmlget_parent_pool_xmlrw  rS  r>   rP   rv  s      r    _set_network_source_from_backend+DeviceDisk._set_network_source_from_backend  s    !!0022!!1133**668F++??AG11&B""++--KK$$T%:%:%C%C%EF .r   c                     U R                   nU[        R                  :X  a  gU[        R                  :X  a  gU[        R                  :X  a  gg )Nr4   r5   r3   )r:   r   r   TYPE_DIRr  )rN   	disk_types     r   _disk_type_to_object_prop_name)DeviceDisk._disk_type_to_object_prop_name  sA    II	
---*---*...r   c                 *   U R                   R                  (       a  U R                   R                  $ U R                   R                  (       a  U R                   R                  $ U R                   R                  (       a  U R                   R                  $ g r   )r>   r3   r4   r5   r   s    r   r  DeviceDisk._get_xmlpath  sT    ;;;;###;;??;;??";;??;;??"r   c                     U R                   R                  5         U R                  R                  5       S:X  a  U R	                  5         g U R                  5       nU(       d  g [        U R                   X!5      $ rt  )r>   r]   r  r  r|  r  setattr)rN   r3  propnames      r   rY  DeviceDisk._set_xmlpath  s]      "  --/9<113668t{{H22r   c                     [         R                  " U R                  U R                  5       UR                  5       UR	                  5       U5      U l        g)z;
Set a path to manually clone (as in, not through libvirt)
N)r   CloneStorageCreatorrU   r   rq  r  )rN   rt   r   s      r   set_local_disk_to_clone"DeviceDisk.set_local_disk_to_clone  s@     !, ? ?		  "  "MMOV!%r   c                 >    [        U R                  5       5      (       + $ r   )boolr   r   s    r   r!  DeviceDisk.is_empty  s    ,,.///r   c                 4    U R                   U R                  :H  $ r   )deviceDEVICE_CDROMr   s    r   is_cdromDeviceDisk.is_cdrom  s    {{d////r   c                 4    U R                   U R                  :H  $ r   )r  DEVICE_FLOPPYr   s    r   	is_floppyDeviceDisk.is_floppy  s    {{d0000r   c                 4    U R                   U R                  :H  $ r   )r  r7  r   s    r   is_diskDeviceDisk.is_disk  s    {{d....r   c                 |    U R                  5       (       d  U R                  5       (       a  gU R                  S;   a  gg)NT)r3   r   r5   r6   r   F)r  r  r:   r   s    r   can_be_emptyDeviceDisk.can_be_empty  s/    >>t}}99EEr   c                 @    U R                   R                  5       (       + $ )zL
If true, this disk needs storage creation parameters or things
will error.
)r  existsr   s    r   wants_storage_creation!DeviceDisk.wants_storage_creation  s    
 ((//111r   c                    U R                   R                  5       (       d  g[        R                  " U5      nU R                   R	                  U5      nSU l        U(       d  gU R                  5       R                  nU R                  SX#5        g)z
Build storage (if required)

If storage doesn't exist (a non-existent file 'path', or 'vol_install'
was specified), we create it.
NT)	r  rW  r   ensure_metercreater  rj  r7   rB  )rN   meterr?  r@  s       r   build_storageDeviceDisk.build_storage)  st     $$88::%%e,**11%8
#' **,11T:;r   c                    U R                  5       (       a]  U R                  (       a  [        U R                  5      eU R                  5       (       d!  [	        [        S5      U R                  -  5      eg U R                  R                  5       (       dD  U R                  R                  5       (       d%  [	        [        S5      U R                  5       -  5      eU R                  R                  5         g )Nz Device type '%s' requires a pathzDMust specify storage creation parameters for non-existent path '%s'.)r!  r  r   r  r   r   r  r  r  rW  r   validater   s    r   r  DeviceDisk.validateB  s    ==??&&"4#:#:;;$$&& #E!F!%"- . . %%,,..%%99;; , -/3/C/C/EFG G 	&&(r   c                 6    U R                   R                  5       $ )a9  
reports if disk size conflicts with available space

returns a two element tuple:
    1. first element is True if fatal conflict occurs
    2. second element is a string description of the conflict or None
Non fatal conflicts (sparse disk exceeds available space) will
return (False, "description of collision")
)r  is_size_conflictr   s    r   r  DeviceDisk.is_size_conflictU  s     $$5577r   c                     U R                  U R                  U R                  5       U R                  U R                  S9nU$ )zs
check if specified storage is in use by any other VMs on passed
connection.

:returns: list of colliding VM names
)r   r   )r   rU   r   r   r   )rN   rW   s     r   is_conflict_diskDeviceDisk.is_conflict_diska  s?     !!$))T-A-A-C,0NN,0NN " < 
r   c                     U R                  5       nU R                  5       U l        U R                  5       U l        U R                  5       U l        U(       a  U R                  U5        gg)z
Fills in the values of type, driver_type, and driver_name for
the associated backing storage. This needs to be manually called
if changing an existing disk's media.
N)r  r  r:   r'  r   r,  r   rY  )rN   rK   s     r   sync_path_propsDeviceDisk.sync_path_propsr  s\       "**,	88:88: d# r   c                    S nU R                   S:X  a  U" S5      $ U R                   S:X  a  U" S5      $ U R                   S:X  d  U R                  5       (       a  U" S5      $ U R                   S:X  a  U" S	5      $ U" S
5      $ )z
Returns the suggested disk target prefix (hd, xvd, sd ...) for the
disk.
:returns: str prefix, or None if no reasonable guess can be made
c                     SSSSSS.nXU    4$ )Nr   r      )vdxvdfdhdsdr%   )prefixnummaps     r   _return-DeviceDisk.get_target_prefix.<locals>._return  s'    F &>))r   virtior  xenr  fdcr  ider  r  )r  r  )rN   r  s     r   get_target_prefixDeviceDisk.get_target_prefix  sw    	* 88x4= XX5>!XX$.."2"24= XX4= t}r   c                 L  ^ ^^^ T R                  5       u  mmT Vs/ s H%  o"(       d  M  UR                  T5      (       d  M#  UPM'     snmTR                  5         UUU U4S jnU" 5       nU(       a	  UT l        U$ [	        [        SST5      TT R                  S.-  5      es  snf )z
Generate target device ('hda', 'sdb', etc..) for disk, excluding
any targets in 'skip_targets'.
Sets self.target, and returns the generated value.

:param skip_targets: list of targets to exclude
:returns: generated target
c                     > S n [        T5       HI  nTTR                  US-   5      -   nUT;   a  TR                  U5        M3  T(       d  Us  $ U (       a  MG  Un MK     U (       a  U $ g )Nr   )r   r   remove)first_foundr   r   maxnoder  rN   skip_targetss      r   
get_target.DeviceDisk.generate_target.<locals>.get_target  sj    K7^!3!3AE!::L( ''.# L$"'K $ "" r   z4Only %(number)s disk for bus '%(bus)s' are supportedz5Only %(number)s disks for bus '%(bus)s' are supported)numberr  )r  rL   sortr
  r   ngettextr  )rN   r  tr  rW   r  r  s   ``   @@r   generate_targetDeviceDisk.generate_target  s     002#/N<a1f9M<N	# 	# lDKJKL txx012 	2/ Os   
B!B!B!c                    U R                   U:X  a  gU R                  5       S   nX l         U R                  R                  5         X0R                  5       S   :X  a  gUR                  R
                   Vs/ s H  oDR                  PM     nnU R                  (       a  UR                  U R                  5        SU l        U R                  U5        gs  snf )zS
Change the bus value for an existing disk, which has some
follow on side effects.
Nr   )	r  r  r=   clearr   rt   r
  r  r  )rN   guestnewbus	oldprefixrt   useds         r   
change_busDeviceDisk.change_bus  s    
 88v**,Q/	..033(-(:(:;(:(:;;;KK$T" <s   4Cc                 Z   U R                  5       (       a  gUR                  R                  5       (       a  gUR                  R                  5       (       d  gU R	                  5       (       a  UR                  5       (       a  gU R                  5       (       a5  UR                  5       (       a   UR                  R                  5       (       d  gUR                  R                  5       (       a  gUR                  R                  5       (       a  gU R                  R                  5       (       a  gg)Nr  r  r  r  scsir  sata)r  r   is_xenpvis_hvmr  supports_virtiodiskr  supports_virtioscsiis_x86is_armis_q35rU   is_bhyve)rN   r  s     r   _default_busDeviceDisk._default_bus  s    >>88xx   <<>>e7799MMOO%%''!! 88??88??99r   c                 0   U R                   (       d  U R                  5       U l         U R                  (       d  U R                  5       U l        U R                  (       d  U R                  5       U l        U R                  (       d  U R                  5       U l        U R                  (       d  U R                  U5      U l        U R                  5       (       a  SU l        SnU R                  R                  5       (       a}  U R                  5       (       ah  U R                  R!                  5       (       aI  U R                  R#                  5       (       a*  U R                  R#                  5       R$                  S:X  a  SnU R                  R                  5       (       au  U R                  5       (       a`  U R&                  U R(                  :X  aF  SnU R*                  (       d  U R,                  U l        U R.                  (       d  U R0                  U l        U(       a  U R2                  (       d  SU l        U R4                  (       dT  UR6                  R8                   Vs/ s H!  o3R4                  (       d  M  UR4                  PM#     nnU R;                  U5        g g s  snf )NTFr   r~   )r   r8  r   r  r   r'  r   r,  r  r  r  r   rU   is_qemur  r  rW  rj  r   r:   r   r   CACHE_MODE_NONEr  IO_MODE_NATIVEr  r
  r   rt   r  )rN   r  discard_unmapdused_targetss        r   set_defaultsDeviceDisk.set_defaults  s   ||++-DL}} 224DM#<<>D#<<>Dxx((/DH==??!DNIILLNN!!5577!!1133!!113>>!C MIILLNNII( M$$$($8$8!>>!%!4!4&&&-#{{.3mm.@.@M.@HHHAHH.@LM  . Ms   J.J)r   r  r  r   r  r	  r  r  r   r  r  r   r   r   r  r
  r:   )FF)NNN)r&   r'   r(   r)   r+   r#  r&  r   r  CACHE_MODE_WRITETHROUGHCACHE_MODE_WRITEBACKCACHE_MODE_DIRECTSYNCCACHE_MODE_UNSAFECACHE_MODESDISCARD_MODE_IGNOREDISCARD_MODE_UNMAPDISCARD_MODESr7  
DEVICE_LUNr  r  r  r   r  r  r  r  staticmethodr   r   r   r   r   r   r   r   r   r   r*   r   r   r   r   r   r   r   r1   r>   r  r  r	  r   driver_copy_on_readsgiorawior  r
  	removablerotation_rater   r   	transienttransient_shareBackingr   r  r  r  r  r  driver_discard_no_unrefdriver_metadata_cache_max_size#driver_metadata_cache_max_size_unitr  serialwwnstartup_policylogical_block_sizephysical_block_sizediscard_granularity
iotune_rbs
iotune_ris
iotune_tbs
iotune_tis
iotune_wbs
iotune_wisr   	seclabelsgeometry_cylsgeometry_headsgeometry_secsgeometry_transreservations_managedreservations_source_typereservations_source_pathreservations_source_moder  r'  r,  r/  r4  propertyr:   r8  r;  r  rB  rF  rE  r   r[  r_  rd  rg  rj  rn  rq  rw  r|  r  r  rY  r  r!  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r,   r%   r   r   r   r      s   HOOO,&( "$;35FHK # (*<=MKJLMIJHKLN > > ) )V   M M T T  & ( (T GK, ,\  ,   OM 9%H+&G./K./KkT:F 23M"#89"#89!-0O%&>Ny!D
#E
o
&C)F1DAI 9$GML$7IM48IM48I()DtT01L !45N&'@AN+I!"6tDO 24@M)*FQUV%0*4&9"*50+2' 78L$F
g
C !:;N$%DE%&FG%&FG6tDJ5dCJ7EJ6tDJ7EJ6tDJ 
KI 24@M !4TBN 24@M !45N&'GH*+OP*+OP*+OP: (Iy)D k;/F(
, <D
02&226770>G
3%001/2<2)&
8
"$ :%2N#:6%/r   r   )r   loggerr   ra   r   r   r   r  r	   r
   r   
xmlbuilderr   r   r   r   r   r.   r1   r   r%   r   r   <module>r     s\    
     9 9 B B
&J &	 	B!* B!Jo/ o/r   