
                             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 dddZdZdZdZ G d dej.                        Zy)zList operation command.    )absolute_import)division)unicode_literalsN)
list_pager)	constants)dataproc)util)base)flags)
propertiesACTIVE
NON_ACTIVE)activeinactiveoperation_state_matchercluster_name
project_idc                   &    e Zd ZdZed        Zd Zy)ListaX  View the list of all operations.

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

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

  where `field` is either of `status.state` or `labels.[KEY]`, where `[KEY]` is
  a label key. `value` can be ```*``` to match all values. `status.state` is
  one of: `PENDING`, `ACTIVE`, `DONE`. 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 operations in Dataproc's 'us-central1' region, run:

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

  To see the list of all create cluster operations in Dataproc's 'global'
  region, run:

    $ {command} --region='global' --filter='operationType = CREATE'

  To see the list of all active operations in a cluster named 'mycluster'
  located in Dataproc's 'global' region, run:

    $ {command} --region='global' --filter='status.state = RUNNING AND
      clusterName = mycluster'

  To see a list of all pending operations with the label `env=staging` on
  cluster `mycluster` located in Dataproc's 'us-central1' region, run:

    $ {command} --region='us-central1' --filter='status.state = PENDING
      AND labels.env = staging AND clusterName = mycluster'
  c                 v   t         j                  j                  |        t         j                  j	                  | t
        j                         t        j                  |        | j                  dd       | j                  dt        t        j                               d       t        j                  |        y )Nz	--clusterzRestrict to the operations of this Dataproc cluster. This flag is ignored when --filter is specified. The equivalent term in a --filter expression is: `clusterName = myclustername`)helpz--state-filterzFilter by cluster state. This flag is ignored when --filter is specified. The equivalent term in a --filter expression is: `status.state = ACTIVE`)choicesr   )r
   URI_FLAGRemoveFromParserPAGE_SIZE_FLAG
SetDefaultr   DEFAULT_PAGE_SIZEr   AddRegionFlagadd_argumentsortedSTATE_MATCHER_MAPkeysAddListOperationsFormat)parsers    'lib/surface/dataproc/operations/list.pyArgsz	List.ArgsO   s    MM""6*""69+F+FG	
H  J (--/0(  * 
!!&)    c                    t        j                  | j                               }t        j                  }t
        j                  j                  j                  j                  }|j                  j                  d ||dd      }t               }|j                  rt        |j                     |t        <   |j                   r|j                   |t"        <   d }|j$                  r|j$                  }d |_        nt'        j(                  |      }|j*                  j-                  |j/                         |      }t1        j2                  |j4                  j6                  ||j8                  d|j:                  d      S )N)regionId	projectIdz)dataproc.projects.regions.operations_list)params
collection)namefilter
operationspageSize)limitfield
batch_sizebatch_size_attribute)dpDataprocReleaseTrackr	   ResolveRegionr   VALUEScoreproject	GetOrFail	resourcesParsedictstate_filterr!   STATE_MATCHER_FILTERclusterCLUSTER_NAME_FILTERr.   jsondumpsmessages,DataprocProjectsRegionsOperationsListRequestRelativeNamer   YieldFromListclientprojects_regions_operationsr1   	page_size)	selfargsr   region_callbackproject_callbackoperation_list_reffilter_dict	op_filterrequests	            r%   RunzList.Rune   s;   {{4,,./H((O!((--55??!++11+:JK> 2 @
 &K*;D<M<M*Nk&'||)-k%&I{{++i dk**[)iLL,,.y M BG ##33jj>>') )r'   N)__name__
__module____qualname____doc__staticmethodr&   rU    r'   r%   r   r   (   s!    $L * **$)r'   r   )rY   
__future__r   r   r   rD   apitools.base.pyr   googlecloudsdk.api_lib.dataprocr   r   r5   r	   googlecloudsdk.callioper
   #googlecloudsdk.command_lib.dataprocr   googlecloudsdk.corer   r!   rA   rC   PROJECT_FILTERListCommandr   r[   r'   r%   <module>rd      s]      &  '  ' 5 : 0 ( 5 *  (\B 0 $ a)4 a)r'   