
                             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  G d
 de	j                        Zy)z#The configs waiters create command.    )absolute_import)division)unicode_literals)util)arg_parsers)base)flags)logc                   4    e Zd ZdZddiZed        Zd Zd Zy)CreatezsCreate waiter resources.

  This command creates a new waiter resource with the specified name and
  parameters.
  EXAMPLESa  
          To create a waiter in "my-config" with success and failure paths
          nested under "/status", run:

            $ {command} my-waiter --config-name=my-config --timeout=15m --success-cardinality-path=/status/success --success-cardinality-number=5 --failure-cardinality-path=/status/failure --failure-cardinality-number=1

          This waiter will wait for at most 15 minutes for the first of two
          possible scenarios: 1) five or more variables are written to the
          /status/success/ path; or 2) one or more variables are written to the
          /status/failure/ path.

          To create a waiter without a failure path, run:

            $ {command} my-waiter --config-name=my-config --timeout=15m --success-cardinality-path=/status/success --success-cardinality-number=5

          This waiter will wait until 5 or more success variables are written,
          or the 15 minute timeout elapses.
          c           	         t        j                  |        t        j                  j	                  |        | j                  dt        j                  ddj                  t        j                              dd       | j                  dd	d
       | j                  ddt        j                  d      d       | j                  dd       | j                  ddt        j                  d      d       | j                  dd       y)zArgs is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use to add arguments that go
          on the command line after this command. Positional arguments are
          allowed.
    z	--timeout1s{0}s)lower_boundupper_boundTz        The amount of time to wait before failing with DEADLINE_EXCEEDED.
        See $ gcloud topic datetimes for information on duration formats.
        )typerequiredhelpz--success-cardinality-pathz-The path where success variables are written.)r   r   z--success-cardinality-numberz1The minimum required number of success variables.   )r   )r   r   defaultz--failure-cardinality-pathz-The path where failure variables are written.)r   z--failure-cardinality-numberz1The minimum required number of failure variables.namezThe waiter name.N)r	   AddRequiredConfigFlagr   
ASYNC_FLAGAddToParseradd_argumentr   Durationformatr   MAX_WAITER_TIMEOUT
BoundedInt)parsers    4lib/surface/runtime_config/configs/waiters/create.pyArgszCreate.Args9   s    
'OO'
!!d.4mm&*&=&=/?@   	 $<   &@##2	   $<  > &@##2	   %78    c                    t        j                         }t        j                         }t        j                  |j                  |      }|j
                  }|j                  }|j                  |j                  |j                  |j                              }|j                  r8|j                  |j                  |j                  |j                              }nd}|j                  |j                  t        j                  ||      |j!                  |j#                         dj%                  |j&                        ||                  }	t)        j*                  |       |j,                  rM|| _        |j0                  j2                  j5                  |j#                               }
|j7                  |
      }	n8d| _        t        j8                  |      }	t        j:                  |	      rd| _        t        j>                  |	      S )	a3  Run 'runtime-configs waiters create'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The associated waiter operation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    )pathnumber)cardinalityNr   )r   timeoutsuccessfailure)parentwaiter)r      ) r   WaiterClientMessagesParseWaiterNamer   
projectsId	configsIdEndConditionCardinalitysuccess_cardinality_pathsuccess_cardinality_numberfailure_cardinality_pathfailure_cardinality_numberr   0RuntimeconfigProjectsConfigsWaitersCreateRequest
ConfigPathWaiterRelativeNamer   r)   r
   CreatedResourceasync__async_resourceclientMESSAGES_MODULE-RuntimeconfigProjectsConfigsWaitersGetRequestGetWaitForWaiterIsFailedWaiter	exit_codeFormatWaiter)selfargswaiter_clientmessageswaiter_resourceprojectconfigr*   r+   resultrequests              r"   Runz
Create.Rune   s    %%'M}}H**499d;O((G&&F##((..22 ) 
 $ G $$%%**0044 +  & g g!!AA??7F3??$113dll3	 #  	B 	

F ({{
 -d%%55??)668 @ :    )f!d!!/2f			V	$V$$r$   c                     | j                   ret        j                  j                          t        j                  j                  dj	                  | j                   j                                      yy)zCalled after resources are displayed if the default format was used.

    Args:
      unused_resources_were_displayed: Unused.
    zEThe wait command can be used to monitor the progress of waiter [{0}].N)r@   r
   statusPrintr   Name)rI   unused_resources_were_displayeds     r"   EpilogzCreate.Epilog   sS     	jj	jj%vd&:&:&?&?&ABD r$   N)	__name__
__module____qualname____doc__detailed_helpstaticmethodr#   rR   rX    r$   r"   r   r      s:      -* )9 )9VD%L
Dr$   r   N)r\   
__future__r   r   r   %googlecloudsdk.api_lib.runtime_configr   googlecloudsdk.callioper   r   )googlecloudsdk.command_lib.runtime_configr	   googlecloudsdk.corer
   CreateCommandr   r_   r$   r"   <module>rf      s8     * &  ' 6 / ( ; #XDT XDr$   