
    G4                     .   S r SSKJr  SSKJr  SSKJr  SSK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r " S S\5      r " S S\R2                  \5      r " S S\R6                  \5      r " S S\R:                  \5      rg)z7Base class for Cluster Upgrade Feature CRUD operations.    )absolute_import)division)unicode_literalsN)
exceptions)base)util)log)resource_projector)timesclusterupgradec                   :    \ rS rSrSrS r\S 5       rS rS r	Sr
g)	ClusterUpgradeCommand#   z0Base class for Cluster Upgrade Feature commands.c                 &    [         U l        Xl        g N)CLUSTER_UPGRADE_FEATUREfeature_nameargs)selfr   s     Plib/googlecloudsdk/command_lib/container/fleet/scopes/rollout_sequencing/base.py__init__ClusterUpgradeCommand.__init__&   s    /DI    c                 ,   SnU R                  U5      n[        U5      S:w  d	  US   S:w  a%  [        R                  " SR	                  U 5      5      eUS   n[
        R                  " U5      n[        R                  " U5      US'   UR                  U5      $ )z6Rebuilds scope name with project number instead of ID./   r   projectsz%{} is not a valid Scope resource name   )
splitlenr   Errorformatproject_utilGetProjectNumbersix	text_typejoin)name	delimitertokens
project_idproject_numbers        r   GetScopeNameWithProjectNumber3ClusterUpgradeCommand.GetScopeNameWithProjectNumber*   s     IZZ	"F
6{a6!9
2
1
8
8
>@ @J!22:>Nn-F1I>>&!!r   c                 J    U R                   R                  R                  5       $ )z:Required to initialize HubClient. See calliope base class.)r   calliope_commandReleaseTrackr   s    r   r1   "ClusterUpgradeCommand.ReleaseTrack7   s    99%%2244r   c                 z   ^ 1 Skm[        U4S jU R                  R                  R                  5        5       5      $ )zDChecks if any Cluster Upgrade Feature related arguments are present.>   upstream_scopeupgrade_selectorreset_upstream_scopeshow_cluster_upgradedefault_upgrade_soakingshow_linked_cluster_upgradeadd_upgrade_soaking_override remove_upgrade_soaking_overridesc              3   D   >#    U  H  u  pU=(       a    UT;   v   M     g 7fr    ).0flag	has_valuecluster_upgrade_flagss      r   	<genexpr>@ClusterUpgradeCommand.IsClusterUpgradeRequest.<locals>.<genexpr>G   s)      B&@?4 :T%:::&@s    )anyr   __dict__items)r   rB   s    @r   IsClusterUpgradeRequest-ClusterUpgradeCommand.IsClusterUpgradeRequest;   s>    	  B&*ii&8&8&>&>&@B B Br   )r   r   N)__name__
__module____qualname____firstlineno____doc__r   staticmethodr-   r1   rH   __static_attributes__r>   r   r   r   r   #   s)    8 
" 
"5Br   r   c                   `    \ rS rSrSr\S 5       r\S 5       r\S 5       rS r	S r
S rS	 rS
rg)DescribeCommandK   z9Command for describing a Scope's Cluster Upgrade Feature.c                 *    U R                  S5      S   $ )z<Extracts the project name from the full Scope resource name.r   r   )r   )r(   s    r   GetProjectFromScopeName'DescribeCommand.GetProjectFromScopeNameN   s     ::c?1r   c                 \   U R                   b=  U R                   R                  nUb$  [        R                  U5      U R                   l        U R                   HQ  nUR                   c  M  UR                   R                  nUc  M-  [        R                  U5      UR                   l        MS     U $ )z@Formats display strings for all cluster upgrade duration fields.)postConditionssoakingrR   DisplayDurationgkeUpgradeOverrides)cluster_upgrade_specdefault_soakingoverrideoverride_soakings       r   FormatDurationsDescribeCommand.FormatDurationsS   s     **6,;;CCo		$6E6U6U7++3(<<		 	 	,#22::',;,K,K- (
!
!
)	 =  r   c                     [         R                  " U 5      n[         R                  " U5      n[        R                  " SSU5      R                  5       $ )z0Returns the display string for a duration value.z[-PT] )r   ParseDurationFormatDurationresublower)proto_duration_stringdurationiso_durations      r   rZ   DescribeCommand.DisplayDurationc   sA     ""#89H''1L66'2|,2244r   c                    [         R                  UR                  5      nU R                  R	                  S5      (       a-  U R                  R
                  (       a  U R                  XU5      $ U R                  R	                  S5      (       aG  U R                  R                  (       a,  [        R                  " U5      nU R                  X25      US'   U$ U$ )zDAdds Cluster Upgrade Feature information to describe Scope response.r8   r:   clusterUpgrades)r   r-   r(   r   IsKnownAndSpecifiedr8   AddClusterUpgradeInfoToScoper:   r
   MakeSerializableGetLinkedClusterUpgradeScopes)r   scopefeature
scope_nameserialized_scopes        r   GetScopeWithClusterUpgradeInfo.DescribeCommand.GetScopeWithClusterUpgradeInfoj   s    &DDUZZPJ		%%&<==		&&..u'JJ
))
'
'(E
F
F
))
/
/+<<UC,0,N,N
-()Lr   c                 Z    [         R                  " U5      nU R                  X#5      US'   U$ )NclusterUpgrade)r
   rq   GetClusterUpgradeInfoForScope)r   rs   ru   rt   rv   s        r   rp   ,DescribeCommand.AddClusterUpgradeInfoToScopex   s3    )::5A)-)K)K*%&r   c                    U R                   R                  UR                  5      nX;  d  X1   R                  (       d'  SR	                  U5      n[
        R                  " U5      eU R                   R                  U R                  R                  UR                  5      U   R                  =(       d    U R                  R                  5       nUU[        R                  X1   R                  5      S.$ )z@Gets Cluster Upgrade Feature information for the provided Scope.z8Cluster Upgrade feature is not configured for Scope: {}.)rs   statespec)	hubclientToPyDict
scopeSpecsr   r"   r   r!   ToPyDefaultDictmessagesScopeFeatureStatescopeStatesClusterUpgradeScopeStaterR   r`   )r   ru   rt   scope_specsmsgr~   s         r   r{   -DescribeCommand.GetClusterUpgradeInfoForScope~   s    ..))'*<*<=K%#22GfZ  
S!!&&MM++W-@-@	

	$n	4 ==113	 
 //#22
 r   c                    ^ ^^^^^	 [         R                  U5      m[        U/5      m	UUUU U	4S jmUUUU U	4S jmT R                  UT5      nT" U5      SS nT" U5      SS nXC/-   U-   $ )zAGets Cluster Upgrade Feature information for the entire sequence.c                   > U R                  SS5      nU(       a  UR                  OSnU(       d  U /$ US   nUT;   a  U /$ TR                  U5        [        R	                  U5      nUT	:X  a  T
OTR                  US9n TR                  X55      nT" U5      U /-   $ ! [        R                   a#  n[        R                  " U5        U /s SnA$ SnAff = f)z5Recursively gets information for the upstream Scopes.r   Nr   project)getupstreamScopesaddrR   rU   
GetFeaturer{   r   r!   r	   warning)cluster_upgradeupstream_specupstream_scopesupstream_scope_nameupstream_scope_projectupstream_featureupstream_cluster_upgradeeUpTheStreamcurrent_projectrt   r   visiteds           r   r   BDescribeCommand.GetLinkedClusterUpgradeScopes.<locals>.UpTheStream   s    %))&$7m8E444o   ,A.		'  kk%&.FF
  ,>'
//"8/
9 !#'#E#E$3 
 12o5FFF  !A  !s   ?B C0CCCc                 6  > U R                  SS5      nU(       a  UR                  OSnU(       d  U /$ US   nUT;   a  U /$ TR                  U5        [        R	                  U5      nUT:X  a  T	OT
R                  US9nT
R                  X55      nU /T" U5      -   $ )z7Recursively gets information for the downstream Scopes.r~   Nr   r   )r   downstreamScopesr   rR   rU   r   r{   )r   downstream_statedownstream_scopesdownstream_scope_namedownstream_scope_projectdownstream_featuredownstream_cluster_upgradeDownTheStreamr   rt   r   r   s          r   r   DDescribeCommand.GetLinkedClusterUpgradeScopes.<locals>.DownTheStream   s    (,,Wd;/?

+
+T    02	'	)  kk'(!0!H!H
"! .@'
//":/
;  $(#E#E
$5 /I!JJJr   Nr   )rR   rU   setr{   )
r   ru   rt   current_cluster_upgradeupstream_cluster_upgradesdownstream_cluster_upgradesr   r   r   r   s
   ` `   @@@@r   rr   -DescribeCommand.GetLinkedClusterUpgradeScopes   s     &==jIO:,GG G:K K4 #@@G +,C DSb I"/0G"H"L%(AA'( )r   r>   N)rJ   rK   rL   rM   rN   rO   rU   r`   rZ   rw   rp   r{   rr   rP   r>   r   r   rR   rR   K   sT    A      5 5.B)r   rR   c                       \ rS rSrSrS rSrg)EnableCommand   z4Base class for enabling the Cluster Upgrade Feature.c                      U R                   R                  U R                  5       5      $ ! [        R                   a<    U R                  U R                  R                  5       5        U R                  5       s $ f = f)zBGets the project's Cluster Upgrade Feature, enabling if necessary.)r   r   FeatureResourceNameapitools_exceptionsHttpNotFoundErrorEnabler   Featurer2   s    r   GetWithForceEnable EnableCommand.GetWithForceEnable   sb    ^^&&t'?'?'ABB00  kk$--'')*__s   (+ AA;:A;r>   N)rJ   rK   rL   rM   rN   r   rP   r>   r   r   r   r      s
    <
r   r   c                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )UpdateCommand   z4Base class for updating the Cluster Upgrade Feature.c                   > U R                   R                  U R                  R                  UR                  5      nX2   R
                  =(       d    U R                  R                  5       nU R                  U5        U R                  U5        U R                  U5        XCU   l        U R                  R                  U R                   R                  X#U   05      S9n[        [        U ];  S/U5      $ )z,Updates Cluster Upgrade Feature information.)r   r   )r   r   r   ScopeFeatureSpecr   r   ClusterUpgradeScopeSpecHandleUpstreamScopesHandleDefaultSoakTimeHandleUpgradeSoakingOverridesr   ToScopeSpecssuperr   Update)r   rt   ru   scope_specs_mapr\   patch	__class__s         r   r   UpdateCommand.Update   s    nn44&&(:(:<O 	#22 	0--/  	2334&&';<1EJ.MM!!>>..457 " 8E ,l^UCCr   c                 4   U R                   R                  S5      (       a#  U R                   R                  (       a  / Ul        gU R                   R                  S5      (       a5  U R                   R                  b  U R                   R                  /Ul        ggg)z\Updates the Cluster Upgrade Feature's upstreamScopes field based on provided arguments.
    r7   r5   N)r   ro   r7   r   r5   )r   r\   s     r   r   "UpdateCommand.HandleUpstreamScopes  sv     			%%&<==		&&,.)
))
'
'(8
9
9
))
"
"
.-1YY-E-E,F) / :r   c                 :   U R                   R                  S5      (       a  U R                   R                  c  g[        R                  " U R                   R                  5      nUR
                  =(       d    U R                  R                  5       nX#l        X1l        g)zCUpdates the Cluster Upgrade Feature's postConditions.soaking field.r9   N)	r   ro   r9   r   FormatDurationForJsonrX   r   ClusterUpgradePostConditionsrY   )r   r\   r]   post_conditionss       r   r   #UpdateCommand.HandleDefaultSoakTime  s{    II))*CDD		))111		))+O 	++ 	5224  .*9'r   c                    U R                   R                  S5      (       a#  U R                   R                  (       a  / Ul        gU R                   R                  S5      (       Ga%  U R                   R                  S5      (       Ga  U R                   R                  b  U R                   R
                  b  [        R                  " U R                   R                  5      nUR                  =(       d    / nU R                  R                  5       nU R                  R                  US9Ul        U R                   R
                  S   nU R                   R
                  S   nU R                  R                  XVS9Ul        X4/-   nXql        ggggg)	z?Updates the ClusterUpgrade Feature's gkeUpgradeOverrides field.r<   r;   r6   N)rY   r(   version)r(   r   )r   ro   r<   r[   r;   r6   r   r   r    ClusterUpgradeGKEUpgradeOverrider   rX   ClusterUpgradeGKEUpgradeupgrade)r   r\   rY   existing_gke_upgrade_overridesnew_gke_upgrade_overrideupgrade_nameupgrade_versionnew_gke_upgrade_overridess           r   r   +UpdateCommand.HandleUpgradeSoakingOverrides  sZ   		%%&HII		2213.
))
'
'(F
G
G
))
'
'(:
;
;
))
0
0
<
))
$
$
0++
))
0
02g 
2
2
8b % --
8
8
: 040Z0Z 1[ 1- YY//7l		229=o)-)O)O *P *6& )+E
E  1J.! 1 = < Hr   r>   )rJ   rK   rL   rM   rN   r   r   r   r   rP   __classcell__)r   s   @r   r   r      s#    <D,G:K Kr   r   )rN   
__future__r   r   r   rf   apitools.base.pyr   r   3googlecloudsdk.command_lib.container.fleet.featuresr   feature_base#googlecloudsdk.command_lib.projectsr   r#   googlecloudsdk.corer	   googlecloudsdk.core.resourcer
   googlecloudsdk.core.utilr   r%   r   objectr   FeatureCommandrR   EnableCommandMixinr   UpdateCommandMixinr   r>   r   r   <module>r      s    > &  ' 	 > T D * # ; * 
* %BF %BPL)l113H L)^L335J  IKL335J IKr   