
    Hg                         d dl Z d dlmZmZmZm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  e j        e          Zd	ed
edeed         ged         f         fdZ G d de          ZdS )    N)ListOptionalDictCallable   )Device)DriveGroupSpecDeviceSelectionDriveGroupValidationError   )FilterGenerator)_MatchInvalidfreturnDriveSelectionr
   r   c           	      d     dddt           dt          d         dt          t                   f fd}|S )Nselfr   namedsr
   r   c                     	  | |          S # t           $ r/}t          | j        j         d| |j        d                   d }~ww xY w)N.r   )r   r   spec
service_idargs)r   r   r   er   s       J/usr/lib/python3/dist-packages/ceph/deployment/drive_selection/selector.pywrapperz to_dg_exception.<locals>.wrapper   sf    	Y1T2;; 	Y 	Y 	Y+ty/C,L,Ld,L,LafUViXXX	Ys    
A*AA)strr   r   r   )r   r   s   ` r   to_dg_exceptionr      s\    Y& Yc Yx@Q7R YW[\bWc Y Y Y Y Y Y
 N    c                       e Zd Z	 ddZd Zd Zd Zd Zdede	e
         d	ed
efdZed             Zed             Zd
efdZdS )r   Nc                    |                                 | _        || _        |pd| _        |                     d| j        j                  | _        |                     d| j        j                  | _        |                     d| j        j	                  | _
        |                     d| j        j                  | _        d S )Nr   data_deviceswal_devices
db_devicesjournal_devices)copydisksr   existing_daemonsassign_devicesr#   _datar$   _walr%   _dbr&   _journal)r   r   r(   r)   s       r   __init__zDriveSelection.__init__   s    
 ZZ\\
	 0 5A((9OPP
''ty7LMM	&&|TY5IJJ++,=ty?XYYr    c                     | j         S N)r+   r   s    r   r#   zDriveSelection.data_devices(   s
    zr    c                     | j         S r1   )r,   r2   s    r   r$   zDriveSelection.wal_devices,   s
    yr    c                     | j         S r1   )r-   r2   s    r   r%   zDriveSelection.db_devices0   s	    xr    c                     | j         S r1   )r.   r2   s    r   r&   zDriveSelection.journal_devices4   s
    }r    device_filterdevices	disk_pathr   c                     |j         pd}d |D             }|dk    rKt          |          | j        z   |k    r0t                              d                    ||                     dS dS )a   Check for the <limit> property and apply logic

        If a limit is set in 'device_attrs' we have to stop adding
        disks at some point.

        If limit is set (>0) and len(devices) >= limit

        :param List[Device] devices: Already populated device set/list
        :param str disk_path: The disk identifier (for logging purposes)
        :return: True/False if the device should be added to the list of devices
        :rtype: bool
        r   c                      g | ]}|j         	|S  )ceph_device.0ds     r   
<listcomp>z1DriveSelection._limit_reached.<locals>.<listcomp>Q   s    DDD!amDADDDr    z,Refuse to add {} due to limit policy of <{}>TF)limitlenr)   loggerdebugformat)r   r6   r7   r8   rA   non_ceph_devicess         r   _limit_reachedzDriveSelection._limit_reached8   s    $ #(q EDwDDD199#.//$2GG5PPLLGNN5" " # # #4ur    c                     | j         r4t                              d                    | j                              dS t	          d                    |                     )z3 Check for mandatory identification fields
        zFound matching disk: {}Tz(Disk {} doesn't have a 'path' identifier)pathrC   rD   rE   	Exception)disks    r   _has_mandatory_identsz$DriveSelection._has_mandatory_identsY   s]    
 9 	ILL299$)DDEEE4:AA$GGI I Ir    c                 B   |st                               d           g S | j        j        st                               d           g S |j        r!t                               d           |j        S t                      }| j        D ]֊t                               d                    j                             j	        s@j
        s9t                               d                    j        j                             |j	        sj
        rj        rd}j        D ]E}d|                                v r-|d         t          | j        j                  k    r
|d         } nF|r5t                               d                    j        |                     |                               s4t                               d	                    j                             `|                     ||j                  r5t                               d
                    j                              n'|v r| j        j        dk    r\t'          fdt)          |          D                       s4t                               d                    j                             #| j        j        dk    r\t+          fdt)          |          D                       s4t                               d                    j                             t                               d                    j                             |                               |D ]%}|| j        v r| j                            |           &t1          d |D             d           S )a   Assign drives based on used filters

        Do not add disks when:

        1) Filter didn't match
        2) Disk doesn't have a mandatory identification item (path)
        3) The set :limit was reached

        After the disk was added we make sure not to re-assign this disk
        for another defined type[wal/db/journal devices]

        return a sorted(by path) list of devices
        zdevice_filter is Nonezdata_devices is Nonez%device filter is using explicit pathszProcessing disk {}z/Ignoring disk {}. Disk is unavailable due to {} osdspec_affinityz+{} is already used in spec {}, skipping it.z*Ignoring disk {}. Missing mandatory identszIgnoring disk {}. Limit reachedANDc              3   B   K   | ]}|                               V  d S r1   comparer>   mrK   s     r   	<genexpr>z0DriveSelection.assign_devices.<locals>.<genexpr>   -      SSq199T??SSSSSSr    z3Ignoring disk {}. Not all filter did match the diskORc              3   B   K   | ]}|                               V  d S r1   rR   rT   s     r   rV   z0DriveSelection.assign_devices.<locals>.<genexpr>   rW   r    z,Ignoring disk {}. No filter matched the diskzAdding disk {}c                     g | ]}|S r;   r;   )r>   xs     r   r@   z1DriveSelection.assign_devices.<locals>.<listcomp>   s    ***Qq***r    c                     | j         S r1   rI   )devs    r   <lambda>z/DriveSelection.assign_devices.<locals>.<lambda>   s    CH r    )key)rC   rD   r   r#   pathslistr(   rE   rI   	availabler<   rejected_reasonslvskeysr   r   rL   rG   filter_logicallr   anyappendremovesorted)r   r6   r7   other_osdspec_affinitylvtaken_devicerK   s         @r   r*   zDriveSelection.assign_devicese   s   "  	LL0111Iy% 	LL/000I 	'LL@AAA &&&&J 4	! 4	!DLL-44TY??@@@> $*: 55;VDItG\5]5]   > 
d&6 
48 
)+&( " "B)RWWYY6601S9M5N5NNN578J5K2!E) LL "006tyBX0Y0Y[ [ [--d33 @GG	# #$ $ $  ""='49EE >EEI       wy%..SSSSOM4R4RSSSSS LLMTT I' '( ( ( y%--SSSSOM4R4RSSSSS LLFMM I' '( ( ( LL)00;;<<<NN4     $ 	0 	0Ltz))
!!,///**'***0D0DEEEEr    c                    d | j         D             d | j        D             d | j        D             d | j        D             dd                    d                    fd                                D                                 S )	Nc                     g | ]	}|j         
S r;   r]   r=   s     r   r@   z+DriveSelection.__repr__.<locals>.<listcomp>   s    888QV888r    c                     g | ]	}|j         
S r;   r]   r=   s     r   r@   z+DriveSelection.__repr__.<locals>.<listcomp>   s    666qAF666r    c                     g | ]	}|j         
S r;   r]   r=   s     r   r@   z+DriveSelection.__repr__.<locals>.<listcomp>   s    444a16444r    c                     g | ]	}|j         
S r;   r]   r=   s     r   r@   z+DriveSelection.__repr__.<locals>.<listcomp>   s    >>>1>>>r    )zdata devicesr$   z
db deviceszjournal deviceszDeviceSelection({})z, c              3   P   K   | ] }d                      ||                   V  !dS )z{}={}N)rE   )r>   r`   	selections     r   rV   z*DriveSelection.__repr__.<locals>.<genexpr>   s5      VVcgnnS)C.99VVVVVVr    )r+   r,   r-   r.   rE   joinrf   )r   rv   s    @r   __repr__zDriveSelection.__repr__   s    88TZ88866DI6664448444>>>>>	+
 +
	 %++IIVVVVY^^EUEUVVVVV
 
 	
r    r1   )__name__
__module____qualname__r/   r#   r$   r%   r&   r
   r   r   r   boolrG   staticmethodrL   r   r*   rx   r;   r    r   r   r      s        #'Z Z Z Z        & f 	
 
   B 	I 	I \	I XF XF _XFt	
# 	
 	
 	
 	
 	
 	
r    )loggingtypingr   r   r   r   	inventoryr   drive_groupr	   r
   r   filterr   matchersr   	getLoggerry   rC   r   r   objectr   r;   r    r   <module>r      s    1 1 1 1 1 1 1 1 1 1 1 1       T T T T T T T T T T # # # # # # # # # # # #		8	$	$x H.>.67H.I.K-1(^.< %=    p
 p
 p
 p
 p
V p
 p
 p
 p
 p
r    