
                             d 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 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)zList clusters command.    )absolute_import)division)unicode_literals)
exceptions)
transforms)util)base)	constants)log)
properties)UpgradeHelpText)VersionVerifierc                   6    e Zd ZdZdddZed        Zd Zd Zy)	Listz.List existing clusters for running containers.z          {description}

          This command queries cluster across all locations unless either
          '--location', '--region', or '--zone' are specified.
      z^          To list existing clusters in all locations, run:

            $ {command}
          )DESCRIPTIONEXAMPLESc                 V    | j                   j                  t        j                         y N)display_info	AddFormatr   CLUSTERS_FORMAT)parsers    &lib/surface/container/clusters/list.pyArgsz	List.Args3   s    
!!$"6"67    c           	      ^   | j                   d   }| j                   d   } ||dd      }t        j                  j                  j                  j                  d      }d }	 |j                  ||      }t        |j                  |      |_        |j                  r=t        j                  d	j                  d
j                  |j                                     d}d}	d}
d}d| _        d| _        d| _        t#               }|j                  D ]  }t%        j&                  |j(                        }|r|j*                  t,        j.                  k  rd}|j1                  |      rM| xj                   t,        j2                  j                  |j4                  |j7                  |            z  c_        |j8                  r|j:                  r|j=                  |j>                  |j@                        }|t"        jB                  k(  r;|jD                  r|jD                  jF                  s|xj@                  dz  c_         d}/|t"        jH                  k(  r|xj@                  dz  c_         d}	[|t"        jJ                  k(  sp|xj@                  dz  c_         d}
d|_          |r#| xj                  tL        jB                  z  c_        |	r#| xj                  tL        jH                  z  c_        |
r#| xj                  tL        jJ                  z  c_        | j                  r3| xj                  tL        jN                  j                  d      z  c_        |rt,        jP                  | _        |j                  S # tR        jT                  $ r)}tW        jX                  |tZ        j\                        d}~ww xY w)zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    api_adapterlocation_getTF)ignore_propertyrequired)r    c                 2    | j                   | j                  fS r   )zonename)clusters    r   sort_keyzList.Run.<locals>.sort_keyF   s    llGLL))r   )keyzIThe following zones did not respond: {0}. List results may be incomplete.z,  )cluster_namecluster_degraded_warningz *z **z ***NAME)r#   N)/contextr   VALUEScoreprojectGetListClusterssortedclustersmissingZonesr   warningformatjoin_upgrade_hint_expire_warning_degraded_warningr   r   ParseExpireTime
expireTimedaysr
   EXPIRE_WARNING_DAYS
IsDegradedDEGRADED_WARNINGr#   GetDegradedWarningenableKubernetesAlpha	nodePoolsComparecurrentMasterVersioncurrentNodeVersionUPGRADE_AVAILABLE	autopilotenabledSUPPORT_ENDINGUNSUPPORTEDr   UPGRADE_COMMANDEXPIRE_WARNINGapitools_exceptions	HttpErrorr   HttpExceptionr   HTTP_ERROR_FORMAT)selfargsadapterr   locationr.   r%   r2   upgrade_availablesupport_endingunsupportedexpiringvvc	time_left
ver_statuserrors                    r   RunzList.Run7   s    ll=)G<</LD$GH$$,,00$0?G*@D%%gx8h !2!2Ah			 &8+@+@!AB	D  nkhdd!db  !..q||<	)*G*GG(a 

 
 I$>$>$E$E66'.'A'A!'D %F %F F
  "" ;;zz!"8"8!:N:NO* ?<<<kkakk11  D(  $_;;;  E) !N_888  F* K "$!
? !B 
o???	o<<<	o999			o==DD E  		(77(( D$$UD,B,BCCDs    "HM0 <C3M0 0N,$N''N,c                    | j                   r)t        j                  j                  | j                          | j                  rt        j
                  | j                         | j                  r t        j
                  | j                         y y r   )r7   r   statusPrintr8   r4   r9   )rQ   resources_were_displayeds     r   EpilogzList.Epilog   s^    	jjt))*	kk$&&'	kk$(() r   N)	__name__
__module____qualname____doc__detailed_helpstaticmethodr   r^   rc    r   r   r   r   "   s7    6
- 8 8RDh*r   r   N)rg   
__future__r   r   r   apitools.base.pyr   rM    googlecloudsdk.api_lib.containerr   r   googlecloudsdk.callioper	   $googlecloudsdk.command_lib.containerr
   googlecloudsdk.corer   r   "surface.container.clusters.upgrader   r   ListCommandr   rj   r   r   <module>rs      sE     &  ' > 7 1 ( . : # * > >o*4 o*r   