
    #                         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 Z
d	 Z	 	 dd
ZddZddZd Zd ZddZd Zd Zy)z1Code for making shared messages between commands.    )absolute_import)division)print_function)unicode_literals)
k8s_object)logc                     dj                  | j                  |      }|D ]K  }d|z   }|| j                  v r| j                  |   j                  d      nd}|dj                  ||      z  }M |S )zReturns a user message for a successful synchronous deploy.

  Args:
    service: googlecloudsdk.api_lib.run.service.Service, Deployed service for
      which to build a success message.
    regions: list of regions that we deployed to.
  zmMulti-Region Service [{{bold}}{s}{{reset}}] has been deployed to regions {{bold}}{r}{{reset}}.
Regional URLs:)srzMultiRegionReady/message z.
{{bold}}{url}{{reset}} ({{bold}}{r}{{reset}}))r   url)formatname
conditionsget)serviceregionsmsgregion	conditionr   s         3lib/googlecloudsdk/command_lib/run/messages_util.py0GetSuccessMessageForMultiRegionSynchronousDeployr      s     F  	  f#f,I *** 	9%)))4 
 <CC
c D  C  
*    c                 .   | j                   j                  }| j                   j                  }|rdn| j                  }d}|r|dz  }| j                  }d}|rdj                  |      }|j                  | j                  |r|n|| j                  |      |z   S )a  Returns a user message for a successful synchronous deploy.

  Args:
    service: googlecloudsdk.api_lib.run.service.Service, Deployed service for
      which to build a success message.
    no_traffic: bool, whether the service was deployed with --no-traffic flag.
  r   zService [{{bold}}{serv}{{reset}}] revision [{{bold}}{rev}{{reset}}] has been deployed and is serving {{bold}}{latest_percent_traffic}{{reset}} percent of traffic.z$
Service URL: {{bold}}{url}{{reset}}r   z+
The revision can be reached directly at {})servrevr   latest_percent_traffic)statuslatestReadyRevisionNamelatestCreatedRevisionNamer   
latest_urlr   r   domain)r   
no_trafficlatest_readylatest_createdr   r   r"   tag_url_messages           r   %GetSuccessMessageForSynchronousDeployr(   7   s     77, >>;;. *10N0NF  22C!!*/DKKO 
jj|| *nnn!7	   	r   c                     d}|| j                   z  }|dk(  r|j                  n|j                         j                         }|j	                  || j
                  || j                  |j                         |      S )a  Returns a user mesage for starting a deploy.

  Args:
    conn_context: connection_context.ConnectionInfo, Metadata for the run API
      client.
    resource_ref: protorpc.messages.Message, A resource reference object for the
      resource. See googlecloudsdk.core.resources.Registry.ParseResourceId for
      details.
    operation: str, what deploy action is being done.
    resource_kind_lower: str, resource kind being deployed, e.g. "service"
  zj{operation} {operator} {resource_kind} [{{bold}}{resource}{{reset}}] in {ns_label} [{{bold}}{ns}{{reset}}]zworker pool)	operationoperatorresource_kindns_labelresourcens)location_label
projectsIdParentNamer   r+   r-   )conn_contextresource_refr*   resource_kind_lowerr   r/   s         r   GetStartDeployMessager7   ^   s    $L  	$	$$#
 
	-  %%' 
 
$$'$$  "	 
 
 r   c                     d}|j                  ||j                         | j                  |j                         j                         | j                        S )az  Returns a user mesage for resource not found.

  Args:
    conn_context: connection_context.ConnectionInfo, Metadata for the run API
      client.
    resource_ref: protorpc.messages.Message, A resource reference object for the
      resource. See googlecloudsdk.core.resources.Registry.ParseResourceId for
      details.
    resource_kind: str, resource kind, e.g. "Service"
  zW{resource_kind} [{resource}] could not be found in {ns_label} [{ns}] region [{region}].)r,   r.   r-   r/   r   )r   r3   r-   r2   r   )r4   r5   r,   r   s       r   GetNotFoundMessager9      sZ    1 
 
!  "$$					#	#	%   
 
 r   c                     dj                  |rdnd| j                  !dj                  | j                        |      S d|      S )z,Returns a user message for how to run a job.zT
To execute this job{repeat}, use:
gcloud{release_track} run jobs execute {job_name}z againr    {})repeatrelease_trackjob_name)r   prefix)r=   r>   r<   s      r   GetRunJobMessager@      sb    ::@&# %%1 ll=//0  ;A ;  ;A ;r   c                     dj                  | j                  dj                  | j                        nd|j                        }|j                  r'|j                  j                  r|dt        |      z   z  }|S )zAReturns a user message with execution details when running a job.zr
View details about this execution by running:
gcloud{release_track} run jobs executions describe {execution_name}r;   r   )r=   execution_namez

Or visit )r   r?   r   r   logUri_GetExecutionUiLink)r=   	executionr   s      r   GetExecutionCreatedMessagerF      s{    L
F !!- ,,}++
,^^    )**11?0;;;C	*r   c                 f    dj                  | j                  | j                  | j                        S )Nzhhttps://console.cloud.google.com/run/jobs/executions/details/{region}/{execution_name}?project={project})r   rB   project)r   r   r   	namespace)rE   s    r   rD   rD      s4    <
F^^!!  r   c                 <    |rdnd}d}|j                  | |||      S )aw  Returns a user message for equivalent gcloud commands for source deploy.

  Args:
    name: name of the source target, which is either a service, a job or a
      worker
    pack: the pack arguments used to build the container image
    source: the location of the source
    subgroup: subgroup name for this command. Either 'jobs ', 'workers ' or
      empty for services
  z--pack image=[IMAGE]z--tag [IMAGE]zThis command is equivalent to running `gcloud builds submit {build_flag} {source}` and `gcloud run {subgroup}deploy {name} --image [IMAGE]`
)r   
build_flagsourcesubgroup)r   )r   packrL   rM   rK   r   s         r   %GetBuildEquivalentForSourceRunMessagerO      s9     *.%?*? 
 
Jv 
 
 r   c                    d| v xr | j                   }d| v xr | j                  }d| v rB| j                  r6| j                  j                         D ]  \  }}d|v s|j                   sd} |xrY |j                  xrK |j                  j
                  xr3 |j                  j
                  j                  t        j                        }|r&|s#|s t        j                  j                  d       yyyyzELogs a user message for GPU type default value if it is not provided.gpugpu_type
containersTzYNo GPU type is provided, defaulting to nvidia-l4. To specify the GPU type use --gpu-type.N)rR   rS   rT   itemstemplatenode_selectorr   r   GPU_TYPE_NODE_SELECTORr   r   Printargsr.   gpu_setgpu_type_set_container_argshas_gpu_types          r   MaybeLogDefaultGpuTypeMessagera      s    TM&dhh't#5,Tdoo!__224>	.	 ^%7%7 5  Q


Q



)
)Q 


)
)
-
-j.O.O
P	  \,JJ	$ +7\Wr   c                    d| v xr | j                   }d| v xr | j                  }d| v rB| j                  r6| j                  j                         D ]  \  }}d|v s|j                   sd} |xrF |j                  xr8 |j                  j
                  xr  |j                  j
                  j                  }|r&|s#|s t        j                  j                  d       yyyyrQ   )
rR   rS   rT   rU   rV   rW   acceleratorr   r   rY   rZ   s          r   *MaybeLogDefaultGpuTypeMessageForV2Resourcerd      s    TM&dhh't#5,Tdoo!__224>	.	 ^%7%7 5  6


6



)
)6 


)
)
5
5	  \,JJ	$ +7\Wr   N)zDeploying container tor   )Service)F)r   )__doc__
__future__r   r   r   r   googlecloudsdk.api_lib.runr   googlecloudsdk.corer   r   r(   r7   r9   r@   rF   rD   rO   ra   rd    r   r   <module>rk      sX    8 &  % ' 1 #:$T '!	$N2 $,*r   