
    `                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	K	Jr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKr " S S\R(                  5      r " S S\R,                  5      rg)z*`gcloud app services set-traffic` command.    )absolute_import)division)unicode_literals)appengine_api_client)operations_util)service_util)arg_parsers)base)
exceptions)log)
console_io)resource_printerNc                       \ rS rSrSrSrg)TrafficSplitError!   z-Errors occurring when setting traffic splits. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       'lib/surface/app/services/set_traffic.pyr   r   !   s    5r   r   c                   6    \ rS rSrSrSS0r\S 5       rS rSr	g)	
SetTraffic&   zpSet traffic splitting settings.

This command sets the traffic split of versions across a service or a project.
EXAMPLESaO            To send all traffic to 'v2' of service 's1', run:

            $ {command} s1 --splits=v2=1

          To split traffic evenly between 'v1' and 'v2' of service 's1', run:

            $ {command} s1 --splits=v2=.5,v1=.5

          To split traffic across all services:

            $ {command} --splits=v2=.5,v1=.5
          c                     U R                  SSSS9  U R                  SS[        R                  " SS9S	S
9  U R                  S/ SQSSS9  U R                  SSSSS9  g )Nservices*zThe services to modify.)nargshelpz--splitsT   )
min_lengtha           Key-value pairs describing what proportion of traffic should go to
        each version. The split values are added together and used as
        weights. The exact values do not matter, only their relation to each
        other. For example, v1=2,v2=2 is equivalent to v1=.5,v2=.5)requiredtyper#   z
--split-by)cookieiprandomr)   z?Whether to split traffic based on cookie, IP address or random.)choicesdefaultr#   z	--migrate
store_trueFal  The migrate flag determines whether or not to use traffic migration
during the operation. Traffic migration will attempt to automatically
migrate traffic from the previous version to the new version, giving
the autoscaler time to respond. See the documentation here:
[](https://cloud.google.com/appengine/docs/python/console/trafficmigration)
for more information.)actionr,   r#   )add_argumentr	   ArgDict)parsers    r   ArgsSetTraffic.Args<   s    

#!  $
  A.F	  G *N	  P
 	  
r   c           
         UR                   (       a$  [        UR                  5      S:  a  [        S5      e[        R
                  " U R                  5       5      nUR                  5       n[        R                  " X1R                  5      n[        R                  " UR                  UR                  5      n/ nU HY  n[        R                  " U5       H<  u  pUR                  SR!                  UR"                  UR$                  UU	5      5        M>     M[     Sn
[&        R(                  " Xj[*        R,                  S9  [*        R,                  R)                  SR!                  UR                  5      5        [*        R,                  R)                  S5        [.        R0                  " SS	9  0 nU HT  n [2        R4                  " UR6                  UR$                  UUR                  R9                  5       UR                   5        MV     U(       a  0 nUR?                  5        H	  u  p~XU'   M     [        S
R!                  SRA                  [C        URE                  5       5      5      5      SRA                  [C        URG                  5       5      5      -   5      eg ! [2        R:                   a.  n[        R<                  " U5      XR$                  '    S nAGM%  S nAff = f)Nr$   zBThe migrate flag can only be used with splits to a single version.z{0}/{1}/{2}: {3}z7list[title="Setting the following traffic allocation:"])outzNOTE: Splitting traffic by {0}.zFAny other versions of the specified service will receive zero traffic.T)cancel_on_noz*Issue setting traffic on service(s): {0}

z, z

)$migratelensplitsr   r   GetApiClientForTrackReleaseTrackListServicesr   GetMatchingServicesr    ParseTrafficAllocationssplit_bysix	iteritemsappendformatprojectidr   Printr   statusr   PromptContinuer   CallAndCollectOpErrorsSetTrafficSplitupperMiscOperationError	text_typeitemsjoinlistkeysvalues)selfargs
api_clientall_servicesr    allocationsdisplay_allocationsserviceversionsplitfmterrorserrprintable_errors	error_msgs                  r   RunSetTraffic.RunZ   s?   ||DKK(1, 5 6 6 &::4;L;L;NOJ**,L//mmLH66T]]$K MM+6.'""#5#<#<JJ	$ 	 7  DC.DJJ)00?AJJ - .40F0..&&

KMM!4<<	1   &
'$-! !/
8
?
?ii-224568
++d+2245
678 8	  // 0 ]]3/zz0s   .AJK&"KKr   N)
r   r   r   r   r   detailed_helpstaticmethodr2   ra   r   r   r   r   r   r   &   s1      -   :-8r   r   )r   
__future__r   r   r   googlecloudsdk.api_lib.appr   r   r   googlecloudsdk.callioper	   r
   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r@   Errorr   Commandr   r   r   r   <module>rm      sU    1 &  ' ; 6 3 / ( * # 2 9 

(( 
a8 a8r   