
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
lmZ ddlmZ ddlmZ  G d dej&                        Zy)z4The command to enable Multi-cluster Ingress Feature.    )absolute_import)division)unicode_literalsN)
enable_api)	resources)base)info)
exceptions)progress_tracker)retryc                   0    e Zd ZdZdZed        Zd Zd Zy)EnablezEnable Multi-cluster Ingress Feature.

  This command enables Multi-cluster Ingress Feature in a fleet.

  ## EXAMPLES

  To enable the Ingress Feature, run:

    $ {command} --config-membership=CONFIG_MEMBERSHIP
  multiclusteringressc                 2    t        j                  |d       y )Nz--config-membership)flag_override)r   AddMembershipResourceArg)clsparsers     -lib/surface/container/fleet/ingress/enable.pyArgszEnable.Args.   s    &&35    c                    t        j                  |dd      }t        j                  d      j                  }t        j                  | j                         |       | j                  j                  | j                  j                  | j                  j                  |                  }| j                  |      }|| j                          y y )NTconfig_membership)promptr   multiclusterservicediscovery)configMembership)r   )spec)r   ParseMembershipr	   Getapir   EnableServiceIfDisabledProjectmessagesFeatureCommonFeatureSpecMultiClusterIngressFeatureSpecr   PollForUsability)selfargsr   mcsd_apifresults         r   Runz
Enable.Run3   s    ,,T)<> xx67;;H&&t||~x@]],, $ L L!2 !M !4 - 5 	 	6A [[^F 
 r   c                    	
 d}d}d}d} j                   j                  j                  j                  		 t	        j
                  ||      5 
t        j                  d       
fd}t        j                  |d|	      } fd
}	fd}|j                  ||d      cd d d        S # 1 sw Y   y xY w# t        j                  $ r) t        j                  dj                  |dz  |            w xY w)Nz"Waiting for controller to start...z'Aborting wait for controller to start.
i zSPlease use the `describe` command to check Featurestate for debugging information.
)aborted_message   c                 &    j                          y N)Tick)unused_resultunused_statustrackers     r   _StatusUpdatez.Enable.PollForUsability.<locals>._StatusUpdate[   s    
,,.r   i  )max_wait_mswait_ceiling_msstatus_update_funcc                  $     j                         S r2   )
GetFeature)r(   s   r   	_PollFuncz*Enable.PollForUsability.<locals>._PollFunce   s    "
"r   c                     | j                   | j                   j                   y| j                   j                   j                  k7  S )NT)statecode)featureunused_stateok_codes     r   
_IsNotDonez+Enable.PollForUsability.<locals>._IsNotDoneh   s:    ]]"gmm&9&9&A$$))W4
4r   i  )funcshould_retry_ifsleep_msz*Controller did not start in {} minutes. {}i`  )r#   FeatureStateCodeValueValuesEnumOKr   ProgressTrackertimesleepr   RetryerRetryOnResultWaitExceptionr
   Errorformat)r(   messager/   timeouttimeout_messager7   retryerr=   rD   rC   r6   s   `        @@r   r'   zEnable.PollForUsabilityJ   s    2G@OG<Omm((<<??G!1++
?47> 	

1	 -- ,.	#	5
 $$J % F54 4 4:  1
6
=
=o01 11s*   B4 AB(	B4 (B1-B4 1B4 4<C0N)	__name__
__module____qualname____doc__feature_nameclassmethodr   r-   r'    r   r   r   r       s*    	 ',5 5.)1r   r   )rZ   
__future__r   r   r   rL   googlecloudsdk.api_lib.servicesr   *googlecloudsdk.command_lib.container.fleetr   3googlecloudsdk.command_lib.container.fleet.featuresr   r	   googlecloudsdk.corer
   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   EnableCommandr   r]   r   r   <module>rf      s?    ; &  '  6 @ D D * 8 *S1T S1r   