
                             d Z ddlmZ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
eeef   defdZd
eeef   defdZej(                   G d dej*                               Zy)zList cluster command.    )AnyDict)
list_pager)	constants)dataproc)util)base)flags)
propertiesclusterreturnc                 D    d| v rd| d   v r| d   d   }d|v sd|v sd|v ryy)NconfiglifecycleConfigidleDeleteTtlautoDeleteTtlautoDeleteTimeenabled  r   lifecycle_configs     %lib/surface/dataproc/clusters/list.py_HasScheduledDeleter      sI    .'(2CCx():;++..//	    c                 D    d| v rd| d   v r| d   d   }d|v sd|v sd|v ryy)Nr   r   idleStopTtlautoStopTtlautoStopTimer   r   r   r   s     r   _HasScheduledStopr    (   sI    .'(2CCx():;)),,--	r   c                   6    e Zd ZdZed        Zd Zed        Zy)Lista  View a list of clusters in a project.

  View a list of clusters in a project. An optional filter can be used to
  constrain the clusters returned. Filters are case-sensitive and have the
  following syntax:

    field = value [AND [field = value]] ...

  where `field` is one of `status.state`, `clusterName`, or `labels.[KEY]`,
  and `[KEY]` is a label key. `value` can be ```*``` to match all values.
  `status.state` can be one of the following: `ACTIVE`, `INACTIVE`,
  `CREATING`, `RUNNING`, `ERROR`, `DELETING`, or `UPDATING`. `ACTIVE`
  contains the `CREATING`, `UPDATING`, and `RUNNING` states. `INACTIVE`
  contains the `DELETING` and `ERROR` states. `clusterName` is the name of the
  cluster provided at creation time. Only the logical `AND` operator is
  supported; space-separated items are treated as having an implicit `AND`
  operator.

  ## EXAMPLES

  To see the list of all clusters in Dataproc's 'us-central1' region, run:

    $ {command} --region='us-central1'

  To show a cluster in Dataproc's 'global' region with the name 'mycluster',
  run:

    $ {command} --region='global' --filter='clusterName = mycluster'

  To see the list of all clusters in Dataproc's 'global' region with specified
  labels, run:

    $ {command} --region='global' --filter='labels.env = staging AND
      labels.starred = *'

  To see a list of all active clusters in Dataproc's 'europe-west1' region with
  specified labels, run:

    $ {command} --region='europe-west1' --filter='status.state = ACTIVE AND
      labels.env = staging AND labels.starred = *'
  c                 J   t        j                  |        t        j                  j	                  |        t        j
                  j                  | t        j                         | j                  j                  d       | j                  j                  t        t        d       y )Na  
          table(
            clusterName:label=NAME,
            config.gceClusterConfig.yesno(yes=GCE, no=GKE):label=PLATFORM,
            config.workerConfig.numInstances:label=PRIMARY_WORKER_COUNT,
            config.secondaryWorkerConfig.numInstances:label=SECONDARY_WORKER_COUNT,
            status.state:label=STATUS,
            config.firstof(
                gkeClusterConfig.namespacedGkeDeploymentTarget.targetGkeCluster,
                gceClusterConfig.zoneUri
              ).scope('locations').segment(0):label=ZONE,
            has_scheduled_delete():label=SCHEDULED_DELETE,
            has_scheduled_stop():label=SCHEDULED_STOP
          )
    )has_scheduled_deletehas_scheduled_stop)r
   AddRegionFlagr	   URI_FLAGRemoveFromParserPAGE_SIZE_FLAG
SetDefaultr   DEFAULT_PAGE_SIZEdisplay_info	AddFormatAddTransformsr   r    )parsers    r   Argsz	List.Args`   sx    	MM""6*""69+F+FG
!! # 	 %% 3/' r   c                    t        j                  | j                               }t        j                  j
                  j                  j                         }t        j                         }| j                  |j                  |||      }t        j                  |j                  j                  ||j                   d|j"                  d      S )NclusterspageSize)limitfield
batch_sizebatch_size_attribute)dpDataprocReleaseTrackr   VALUEScoreproject	GetOrFailr   ResolveRegion
GetRequestmessagesr   YieldFromListclientprojects_regions_clustersr4   	page_size)selfargsr   r=   regionrequests         r   RunzList.Runy   s    {{4,,./H$$,,668G!Fooh//&$GG##11jj>>' r   c                 l    d }|j                   r|j                   }d |_         | j                  |||      S )N)	projectIdrH   filter)rM   *DataprocProjectsRegionsClustersListRequest)rA   r=   rH   rG   backend_filters        r   r@   zList.GetRequest   s?     N{{{{ndk>>& ?  r   N)__name__
__module____qualname____doc__staticmethodr0   rJ   r@   r   r   r   r"   r"   4   s5    (T  0" 
 
r   r"   N)rS   typingr   r   apitools.base.pyr   googlecloudsdk.api_lib.dataprocr   r   r8   r   googlecloudsdk.callioper	   #googlecloudsdk.command_lib.dataprocr
   googlecloudsdk.corer   strr   r    UniverseCompatibleListCommandr"   r   r   r   <module>r^      s       ' 5 : 0 ( 5 *	c3h 	C 		tCH~ 	# 	 `4 ` `r   