
    Hgx;                         d dl Z d dlZd dlmZ d dlmZmZmZ d dlm	Z	 	 d dl
mZmZmZmZmZ n# e$ r Y nw xY w G d dee j                  Z G d d	e          Z G d
 de	          Z G d de          Z ej        eej                   dS )    N)Device)ServiceSpecPlacementSpecCustomConfig)SpecValidationError)OptionalListDictAnyUnionc                   "    e Zd ZdZdZdefdZdS )	OSDMethodrawlvmreturnc                     | j         S N)value)selfs    =/usr/lib/python3/dist-packages/ceph/deployment/drive_group.pyto_jsonzOSDMethod.to_json   s
    z    N)__name__
__module____qualname__r   r   strr    r   r   r   r      s9        
C
C      r   r   c                   x    e Zd ZdZg dZ	 	 	 	 	 	 	 ddZdeddfdZed	             Z	d
 Z
defdZdedefdZdS )DeviceSelectionz
    Used within :class:`ceph.deployment.drive_group.DriveGroupSpec` to specify the devices
    used by the Drive Group.

    Any attributes (even none) can be included in the device
    specification structure.
    )pathssizevendormodel
rotationallimitallNFc           
         g | _         ||D ]}t          |t                    rT|                    dd          }	| j                             t          |	|                    dd                               k| j                             t          t          |                               || _        || _        || _	        || _
        || _        || _        dS )z<
        ephemeral drive group device specification
        Npath crush_device_class)r*   )r    
isinstancedictgetappendr   r   r#   r"   r!   r$   r%   r&   )
r   r    r#   r!   r$   r%   r"   r&   devicer(   s
             r   __init__zDeviceSelection.__init__#   s     
 ; ;fd++ ; &

62 6 6DJ%%fTfjjQegkFlFl&m&m&mnnnnJ%%fS[[&9&9:::: 
 
 %)	 % 
 r   namer   c                    | j         | j        | j        | j        g}| j        r)t          d |D                       rt          |d          t          d | j        g|z   D                        }| j        s|rt          |d          | j        r2|s2t          |d                    t          |                               d S d S )Nc              3      K   | ]}|d uV  	d S r   r   .0ps     r   	<genexpr>z+DeviceSelection.validate.<locals>.<genexpr>R   s&      ;;atm;;;;;;r   zEdevice selection: `paths` and other parameters are mutually exclusivec              3   *   K   | ]}|d uo|g k    V  d S r   r   r4   s     r   r7   z+DeviceSelection.validate.<locals>.<genexpr>V   s/      SS1D=4Q"WSSSSSSr   z device selection cannot be emptyzGdevice selection: `all` and other parameters are mutually exclusive. {})
r#   r"   r!   r$   r    anyDriveGroupValidationErrorr&   formatrepr)r   r1   propsis_emptys       r   validatezDeviceSelection.validateP   s   T[$)T_E: 	Y#;;U;;;;; 	Y+WY Y Y SStzlU>RSSSSSSx 	VH 	V+D2TUUU8 	!H 	!+Y``JJ   ! ! !	! 	! 	! 	!r   c                     |sd S t          |                                          D ]}|| j        vrt          |           | di |S )Nr   )listkeys_supported_filtersKeyError)clsdevice_specapplied_filters      r   	from_jsonzDeviceSelection.from_json`   sm      	4";#3#3#5#566 	/ 	/NS%;;;~... < s!![!!!r   c                    i }| j         rd | j         D             |d<   | j        r
| j        |d<   | j        r
| j        |d<   | j        r
| j        |d<   | j        
| j        |d<   | j        r
| j        |d<   | j        r
| j        |d<   |S )	Nc                     g | ]	}|j         
S r   )r(   r4   s     r   
<listcomp>z+DeviceSelection.to_json.<locals>.<listcomp>o   s    777qAF777r   r    r#   r"   r!   r$   r%   r&   )r    r#   r"   r!   r$   r%   r&   )r   rets     r   r   zDeviceSelection.to_jsonk   s     : 	877DJ777CL: 	&:CL; 	( KCM9 	$)CK?& $C: 	&:CL8 	"CJ
r   c                       fd j         dgz   D             }d|v r  j        g k    r|                    d           d                    d                     fd|D                                 S )Nc                 4    g | ]}t          |          |S r   getattrr5   keyr   s     r   rK   z,DeviceSelection.__repr__.<locals>.<listcomp>   s0     
 
 
'$PSBTBTB`CB`B`B`r   r%   r    zDeviceSelection({})z, c           
   3   z   K   | ]5}d                      |t          t          |                              V  6dS )z{}={}N)r;   r<   rP   rQ   s     r   r7   z+DeviceSelection.__repr__.<locals>.<genexpr>   sC      TTgnnS$wtS/A/A*B*BCCTTTTTTr   )rC   r    remover;   join)r   rB   s   ` r   __repr__zDeviceSelection.__repr__   s    
 
 
 
2gY>
 
 
 d??tzR//KK   $++IITTTTtTTTTT
 
 	
r   otherc                 B    t          |           t          |          k    S r   )r<   )r   rW   s     r   __eq__zDeviceSelection.__eq__   s    DzzT%[[((r   )NNNNNNF)r   r   r   __doc__rC   r0   r   r?   classmethodrH   r   rV   r   boolrY   r   r   r   r   r      s           
  + + + +Z!S !T ! ! ! !  " " ["  (
# 
 
 
 
)C )D ) ) ) ) ) )r   r   c                   8     e Zd ZdZdee         def fdZ xZS )r:   z
    Defining an exception here is a bit problematic, cause you cannot properly catch it,
    if it was raised in a different mgr module.
    r1   msgc                 l    |pd}t          t          |                               d| d|            d S )N	<unnamed>zFailed to validate OSD spec "z": )superr:   r0   )r   r1   r^   	__class__s      r   r0   z"DriveGroupValidationError.__init__   sM    "{'..77:D::S::	< 	< 	< 	< 	<r   )r   r   r   rZ   r   r   r0   __classcell__rb   s   @r   r:   r:      sY         
<Xc] < < < < < < < < < < <r   r:   c                        e Zd ZdZg dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeee                  f fdZe	 fd	            Z
e	d
ededefd            Z fdZ xZS )DriveGroupSpeczS
    Describe a drive group in the same form that ceph-volume
    understands.
    )	encryptedblock_wal_sizeosds_per_devicedb_slots	wal_slotsblock_db_size	placement
service_idservice_typedata_devices
db_deviceswal_devicesjournal_devicesdata_directoriesri   objectstoreosd_id_claimsjournal_size	unmanagedfilter_logicpreview_onlyextra_container_argsextra_entrypoint_argsdata_allocate_fractionmethodr*   configN	bluestoreFANDr|   c                    ||dk    sJ t          t          |                               d||||||||	  	         || _        || _        || _        || _        || _        || _        || _	        || _
        || _        |	| _        |
| _        || _        || _        |pt!                      | _        |                                | _        || _        || _        || _        || _        d S )Nosd)rn   rm   r   rx   rz   r{   r|   custom_configs)ra   rf   r0   rp   rq   rr   rs   rh   rl   rw   ri   rt   ru   rg   rj   rk   r,   rv   upperry   rz   r}   r~   r*   )r   rm   rn   rp   rq   rr   rs   rt   ri   ru   rg   rj   rk   rv   rl   rh   rw   ro   rx   ry   rz   r{   r|   r}   r~   r   r   r*   rb   s                               r   r0   zDriveGroupSpec.__init__   s3   : #|u'<'<'<'<nd##,,Uz7@4:7@:FBVCX<J 	- 	L 	L 	L ) % '  / 6D 5B 4@
  / !1 ' # ! # +4dff )..00 ) '=# #5r   c                    |                                 }d|v rd|vrd|d         i|d<   |d= |                    dd          }d|v r5|d                             |                     ||d                              |                    |                     |d |                                D                                  t          t          |                               |          S )z
        Initialize 'Drive group' structure

        :param json_drive_group: A valid json string with a Drive Group
               specification
        host_patternrm   rn   r`   specc                 &    i | ]\  }}|d k    ||S )r   r   )r5   kvs      r   
<dictcomp>z2DriveGroupSpec._from_json_impl.<locals>.<dictcomp>   s#    HHHDAqAKK1aKKKr   )copyr-   update_drive_group_spec_from_jsonitemsra   rf   _from_json_impl)rE   json_drive_groupargss_idrb   s       r   r   zDriveGroupSpec._from_json_impl  s      04466T!!k&=&=!/n1E FD^$xxk22 T>>L ? ?d6l S STTTC33HHDJJLLHHHJ J 	K 	K 	K ^S))99$???r   r1   r   r   c                    t          |                                          D ].}|| j        vr#t          d                    |                    /	 dt
          dt          dt          t                   ffdfd|	                                D             }|st          d          |S # t          t          f$ r"}t          t          |                    d }~ww xY w)NzFeature `{}` is not supportedrR   valsr   c                     	 t                               |          S # t          $ r)}t           d|  d|j        d          d          d }~ww xY w)N.zFiltering for `r   z` is not supported)r   rH   rD   r:   r   )rR   r   er1   s      r   to_selectionz@DriveGroupSpec._drive_group_spec_from_json.<locals>.to_selection-  sv    I*44T::: I I I3#G!&)GGGI I IIs    
A$AAc                 ^    i | ])\  }}||                     d           r ||          n|*S )_devices)endswith)r5   r   r   r   s      r   r   z>DriveGroupSpec._drive_group_spec_from_json.<locals>.<dictcomp>5  sP     . . .QUQRTUAajj.D.DKQ***! . . .r   zDidn't find drive selections)rA   rB   _supported_featuresr:   r;   r   r,   r   r   r   rD   	TypeError)rE   r1   r   rG   r   r   r   s    `    @r   r   z*DriveGroupSpec._drive_group_spec_from_json$  s9   "#3#8#8#:#:;; 	L 	LNS%<<</3::>JJL L L =
	:I# IT Ih6O I I I I I I. . . .$**,,. . .D V/6TUUUK)$ 	: 	: 	:+D#a&&999	:s   AB. .C!?CC!c                     t          t                                                       j                                        rt           j        d           j        t           j        d          d                                }t          t          | fd|D                                 }d |                                D             D ](\  }}|J |                     j         d|            )t          d  j         j         j        g          D ]}|j        rt           j        d           j        dvrt           j         j         d	           j        7t'           j                  t(          t*          fvrt           j        d
           j        7t'           j                  t(          t*          fvrt           j        d           j        7t'           j                  t(          t*          fvrt           j        d           j        dvrt           j        d           j        dvrt           j        d           j        dk    r  j        dk    rt           j        d           j        j        8t7           j        j                  D ] }|j        st           j        d          d S d S )Nz`placement` requiredz#`data_devices` element is required.z3data_devices db_devices wal_devices journal_devicesc                 0    g | ]}t          |          S r   rO   )r5   r   r   s     r   rK   z+DriveGroupSpec.validate.<locals>.<listcomp>H  s#    &M&M&MAwtQ'7'7&M&M&Mr   c                 "    g | ]}|d          
|S )   r   )r5   kss     r   rK   z+DriveGroupSpec.validate.<locals>.<listcomp>I  s!    EEEB2a53DR3D3D3Dr   r   z&`all` is only allowed for data_devicesr   z/ is not supported. Must be one of ('bluestore')z,block_wal_size must be of type int or stringz+block_db_size must be of type int or stringz*journal_size must be of type int or string)r   ORz)filter_logic must be either <AND> or <OR>)Nr   r   z$method must be one of None, lvm, rawr   	filestorez"method raw only supports bluestorezDevice path cannot be empty)ra   rf   r?   rm   r>   r:   rn   rp   splitr,   zipr   filterrq   rr   rs   r&   ru   rh   typeintr   rl   rw   ry   r~   r    rA   r(   )r   specs_namesspecsr   sr/   rb   s   `     r   r?   zDriveGroupSpec.validate=  s=   nd##,,...>""$$ 	U+DO=STTT$+DO=bcccKQQSSS&M&M&M&M&M&M&MNNOOEE%++--EEE 	1 	1DAq===JJ$///A//0000t0@$BVWXX 	> 	>Au >/O<> > >>
 K00+DO/3/? -D -D -DE E E *tD4G/H/HQTVYPZ/Z/Z+>@ @ @ )d43E.F.FsTWj.X.X+=? ? ? (T$2C-D-DSRUJ-V-V+<> > > M11+;= = = ;222+68 8 8 ;%D$4$C$C+46 6 6 ".t0677 d d{ d3DOEbcccd /.d dr   )NNNNNNNNr   FNNNNNNNFr   FNNNNNNN)r   r   r   rZ   r   r   r	   r   r0   r[   r   r,   r   r?   rc   rd   s   @r   rf   rf      sN        
     " !!%"&!%( ## $"" ##&*>B(, $$(7a5 a5, )1c(;-a5 a5 a5 a5 a5 a5F @ @ @ @ [@0 :s :d :t : : : [:08d 8d 8d 8d 8d 8d 8d 8d 8dr   rf   )enumyamlceph.deployment.inventoryr   ceph.deployment.service_specr   r   r   ceph.deployment.hostspecr   typingr   r	   r
   r   r   ImportErrorr   Enumr   objectr   r:   rf   add_representeryaml_representerr   r   r   <module>r      s     , , , , , , Q Q Q Q Q Q Q Q Q Q 8 8 8 8 8 8	777777777777777 	 	 	D	    TY   t) t) t) t) t)f t) t) t)n	< 	< 	< 	< 	< 3 	< 	< 	<\d \d \d \d \d[ \d \d \d~  ^^%D E E E E Es   / 77