
    5dI                         d dl mZ d dlZd dlZd dlmZmZmZmZ de	ddfdZ
 G d de          Z G d	 d
e          ZdS )    )OrderedDictN)OptionalListAnyDictnamereturnc                    t          j        d          }	 t          |           dk    s
J d            |                     d          D ][}t          |          dk    s
J d            t          |          dk    s
J d            |                    |          s
J d	            \d S # t
          $ r(}t          t          |          d
|  dz             d }~ww xY w)Nz^[a-zA-Z0-9-]+$   z name is too long (max 250 chars).r   z,.-delimited name component must not be empty?   z9.-delimited name component must not be more than 63 charsz0name component must include only a-z, 0-9, and -z. Got "")recompilelensplitmatchAssertionErrorSpecValidationErrorstr)r   ppartes       :/usr/lib/python3/dist-packages/ceph/deployment/hostspec.pyassert_valid_hostr      s    

$%%A>4yyC!CJJsOO 	U 	UDt99q==="P===t99???$_???774==TT"TTTTT	U 	U  > > >!#a&&+<T+<+<+<"<===>s   BB& &
C0#CCc                   <     e Zd ZdZej         fd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.
    msgerrnoc                 f    t          t          |                               |           || _        d S N)superr   __init__r   )selfr   r   	__class__s      r   r"   zSpecValidationError.__init__   s/     	!4((11#666


    )
__name__
__module____qualname____doc__r   EINVALr   intr"   __classcell__)r$   s   @r   r   r      se           %|m          r%   r   c                      e Zd ZdZ	 	 	 	 ddedee         deee                  dee         deeeef                  f
dZdd
Z	d	eee
f         fdZeded	d fd            Zeded	efd            Zd	efdZd	efdZde
d	efdZdS )HostSpeczB
    Information about hosts. Like e.g. ``kubectl get nodes``
    Nhostnameaddrlabelsstatuslocationc                 f    d| _         || _        |p|| _        |pg | _        |pd| _        || _        d S )Nhost )service_typer/   r0   r1   r2   r3   )r#   r/   r0   r1   r2   r3   s         r   r"   zHostSpec.__init__#   sH     # ! $H	 l l r%   r	   c                 .    t          | j                   d S r    )r   r/   r#   s    r   validatezHostSpec.validate:   s    $-(((((r%   c                     | j         | j        t          t          j        | j                            | j        d}| j        r
| j        |d<   |S )N)r/   r0   r1   r2   r3   )r/   r0   listr   fromkeysr1   r2   r3   )r#   rs     r   to_jsonzHostSpec.to_json=   sQ    I;/>>??k	
 
 = 	* MAjMr%   	host_specc           
         |                      |          } | |d         d|v r|d         nd d|v r't          t          j        |d                             nd d|v r|d         nd |                    d                    }|S )Nr/   r0   r1   r2   r3   )normalize_jsonr<   r   r=   get)clsr@   _clss      r   	from_jsonzHostSpec.from_jsonH   s    &&y11	sj!!'9!4!4If$)1Y)>)> %(#% % & & &DH#+y#8#8IhdMM*%%
 
 r%   c                    |                      d          }|]t          |t                    r|g| d<   nAt          |t                    rt	          d |D                       rt          d| d          |                      d          }|~t          |t                    rVt	          d |                                D                       s+t	          d |                                D                       rt          d| d	          | S )
Nr1   c              3   B   K   | ]}t          |t                     V  d S r    
isinstancer   .0vs     r   	<genexpr>z*HostSpec.normalize_json.<locals>.<genexpr>]   s/      BBaz!S111BBBBBBr%   zLabels (z%) must be a string or list of stringsr3   c              3   B   K   | ]}t          |t                     V  d S r    rI   )rL   ks     r   rN   z*HostSpec.normalize_json.<locals>.<genexpr>g   s/      FFaz!S111FFFFFFr%   c              3   B   K   | ]}t          |t                     V  d S r    rI   rK   s     r   rN   z*HostSpec.normalize_json.<locals>.<genexpr>h   s/      HHaz!S111HHHHHHr%   z
Location (z,) must be a dictionary of strings to strings)	rC   rJ   r   r<   anyr   dictkeysvalues)r@   r1   locs      r   rB   zHostSpec.normalize_jsonU   s1   x((&#&& '-h	(##"6400BB6BBBBB *LvLLL   mmJ''?"3--FF388::FFFFF HH3::<<HHHHH
 *RRRR   r%   c                    | j         g}| j        |                    | j                   | j        r|                    | j                   | j        r|                    | j                   | j        r|                    | j                   d                    d                    t          t          |                              S )NzHostSpec({})z, )
r/   r0   appendr1   r2   r3   formatjoinmaprepr)r#   argss     r   __repr__zHostSpec.__repr__p   s    9 KK	"""; 	%KK$$$; 	%KK$$$= 	'KK&&&$$TYYs4%?%?@@@r%   c                 T    | j         | j        k    r| j          d| j         dS | j         S )Nz ())r/   r0   r9   s    r   __str__zHostSpec.__str__}   s4    =DI%%m33ty3333}r%   otherc                     t          |t                    st          S | j        |j        k    oI| j        |j        k    o9t          | j                  t          |j                  k    o| j        |j        k    S r    )rJ   r.   NotImplementedr/   r0   sortedr1   r3   )r#   rb   s     r   __eq__zHostSpec.__eq__   sp    %** 	"!!}. ,I#,4;6%,#7#77, MU^+	,r%   )NNNN)r	   N)r&   r'   r(   r)   r   r   r   r   r"   r:   r   r?   classmethodrS   rF   staticmethodrB   r^   ra   boolrf    r%   r   r.   r.      s        
 (,/3)-6:! !!}! "$s),! "#	!
 $DcN3! ! ! !.) ) ) )	c3h 	 	 	 	 
$ 
: 
 
 
 [
 $ 4    \4A# A A A A    
,C ,D , , , , , ,r%   r.   )collectionsr   r   r   typingr   r   r   r   r   r   	Exceptionr   objectr.   rj   r%   r   <module>ro      s    # # # # # #  				 , , , , , , , , , , , ,	>C 	>D 	> 	> 	> 	>	 	 	 	 	) 	 	 	j, j, j, j, j,v j, j, j, j, j,r%   