
    <                     `   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rSSKr " S S\R$                  5      r\
R(                  " \
R*                  R,                  \
R*                  R.                  5       " S S\
R0                  5      5       rg)zThe Migrate command.    )absolute_import)division)unicode_literals)appengine_api_client)operations_util)service_util)base)
exceptions)log)
console_ioNc                       \ rS rSrSrSrg)VersionsMigrateError!   zErrors when migrating versions. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       #lib/surface/app/versions/migrate.pyr   r   !   s    'r   r   c                   6    \ rS rSrSrSS0r\S 5       rS rSr	g)	Migrate%   zBMigrate traffic from one version to another for a set of services.EXAMPLESaw            This only works for automatically scaled Standard versions.
          To migrate from one version to another for all services where there
          is a version v2 and shut down the previous version, run:

            $ {command} v2

          To migrate from one version to another for a specific service, run:

            $ {command} v2 --service="s1"
          c                 F    U R                  SSS9  U R                  SSSS9  g )NversionzThe version to migrate to.)helpz	--servicez-sz;If specified, only migrate versions from the given service.)add_argument)parsers    r   ArgsMigrate.Args7   s2    
	(DE
T.  /r   c           	      B  ^^ [         R                  " U R                  5       5      nTR                  (       a  UR	                  TR                  5      n0 nUR
                  (       a?  UR
                  R                  R                   H  nUR                  XER                  '   M     [        R                  " UR                  UR                  U5      /nOUR                  5       nUR                  U5      nTR                   U Vs1 s H  oR                  iM     sn;  ad  TR                  (       a/  [#        SR%                  TR                  TR                   5      5      e[#        SR%                  TR                   5      5      eU Vs1 s H*  oR                  TR                   :X  d  M  UR                  iM,     snmUU4S jn	['        [(        R*                  R-                  X5      5      n
U
 H}  nSR%                  UR                  UR                  5      nSR%                  UR                  TR                   5      n[.        R0                  R3                  SR%                  X5      5        M     [4        R6                  " SS9  0 n[9        [;        U
 Vs/ s H  oR                  PM     sn5      5       H3  nTR                   S0n [<        R>                  " UR@                  X?S	SS
9  M5     U(       ai  SR%                  SRG                  ['        URI                  5       5      5      SRG                  ['        URK                  5       5      5      5      n[#        U5      eg s  snf s  snf s  snf ! [<        RB                   a#  n[(        RD                  " U5      X'    S nAM  S nAff = f)Nz!Version [{0}/{1}] does not exist.zVersion [{0}] does not exist.c                    > U R                   T;   =(       aB    U R                  =(       a/    U R                  S:  =(       a    U R                  TR                  :g  $ )Nr   )servicetraffic_splitidr   )vargsservice_namess    r   WillBeMigrated#Migrate.Run.<locals>.WillBeMigratedT   sE    ii=( ;Q__ ;oo!;&'dddll&:<r   z{0}/{1}z1Migrating all traffic from version [{0}] to [{1}]T)cancel_on_nog      ?ip)shard_bymigratez6Issues migrating all traffic of service(s): [{0}]

{1}z, z

)&r   GetApiClientForTrackReleaseTrackr&   GetServiceResourcesplitallocationsadditionalPropertiesvaluekeyr   Serviceprojectr(   ListServicesListVersionsr   r   formatlistsixmovesfilterr   statusPrintr   PromptContinuesortedsetr   CallAndCollectOpErrorsSetTrafficSplitMiscOperationError	text_typejoinkeysvalues)selfr*   clientr&   r'   r5   servicesall_versionsr)   r,   versions_to_migrater   
short_namepromoted_nameerrorsr6   errerror_stringr+   s    `                @r   RunMigrate.Run>   s   !66t7H7H7JKF||))$,,7gm	]]..CCE%*[[-		
" D&&v~~wzz'46 7h $$&h&&x0L||,7,QDD,77	"#F#M#MLL$,,$( ) 	) ##B#I#ILL$  	(4M18LYQYYMM<
 syy//MN&##GOOWZZ@j&&wEm	jj ((.%)67 ' 40F#2EF2EQyy2EFGH\\3'k-..""G4	 I 117))D$78 ++d6==?&;<2>  !.. G 8 N& G 00 ---,-s0   MM'MM"!M''N;NNr   N)
r   r   r   r   r   detailed_helpstaticmethodr"   rY   r   r   r   r   r   r   %   s/    J  
- / /5/r   r   )r   
__future__r   r   r   googlecloudsdk.api_lib.appr   r   r   googlecloudsdk.callioper	   googlecloudsdk.corer
   r   googlecloudsdk.core.consoler   r@   	six.movesErrorr   ReleaseTracksr3   BETAGACommandr   r   r   r   <module>rh      s      &  ' ; 6 3 ( * # 2 
 (:++ ( D%%**D,=,=,@,@AM/dll M/ BM/r   