
    u                     ~   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 dd	lmZ dd
lmZ dZ e	j*                  e	j,                  j.                  e	j,                  j0                  e	j,                  j2                         G d dej4                               Z G d dej8                        Zy)zBCommand to update Cluster Ugprade Feature information for a Fleet.    )absolute_import)division)unicode_literals)
exceptions)base)flags)	arg_utils)iso_duration)timesclusterupgradec                   `     e Zd ZdZddiZeZed        Zd Z	 fdZ
ed        Zd Zd	 Z xZS )
UpdatezEUpdate the clusterupgrade feature for a fleet within a given project.EXAMPLESz            To update the clusterupgrade feature for the current fleet, run:

            $ {command} --default-upgrade-soaking=DEFAULT_UPGRADE_SOAKING
        c                     t        j                  |       }|j                          |j                  d       |j	                  d       y )NT)with_destructive)clusterupgrade_flagsClusterUpgradeFlagsAddDefaultUpgradeSoakingFlagAddUpgradeSoakingOverrideFlagsAddUpstreamFleetFlags)parserr   s     4lib/surface/container/fleet/clusterupgrade/update.pyArgszUpdate.Args0   s@     44V<E	&&(	(($(?	6    c                     t        j                  |dd      }t        |      }|j                  |      }| j	                  ||       y )Nz	--projectT)use_defaults)r	   GetFromNamespace_EnableCommandGetWithForceEnabler   )selfargsproject
enable_cmdfeatures        r   Runz
Update.Run7   s>    (({NG%J++G4GKKr   c                    |j                   j                  xs | j                  j                         }t        j                  ||       | j                  ||       | j                  ||       | j                  j                  | j                  j                  |            }|j                   j                  dnd}t        t        |   |g|      S )z8Updates Cluster Upgrade Feature information for a fleet.)r   )speczspec.clusterupgrader'   )r'   r   messagesClusterUpgradeFleetSpecr   _HandleUpstreamFleets_HandleDefaultSoakTime_HandleUpgradeSoakingOverridesFeatureCommonFeatureSpecsuper)r    r$   r!   cluster_upgrade_specpatchpath	__class__s         r   r   zUpdate.Update=   s     	##Nt}}'L'L'N    ';<&:;''.BCMM!!]],,/ - 
 " E <<&&2 	 	
 %tfe44r   c                     | j                  d      r| j                  rg |_        y| j                  d      r | j                  | j                  g|_        yyy)z;Updates the Cluster Upgrade Feature's upstreamFleets field.reset_upstream_fleetupstream_fleetN)IsKnownAndSpecifiedr5   upstreamFleetsr6   )r!   r0   s     r   r*   zUpdate._HandleUpstreamFleetsQ   s\     	  !78%%,.)  !12+-1-@-@,A) , 	3r   c                    |j                  d      r|j                  yt        j                  t	        j
                  |j                              }|j                  xs | j                  j                         }||_	        ||_        y)zCUpdates the Cluster Upgrade Feature's postConditions.soaking field.default_upgrade_soakingNseconds)
r7   r:   r   FormatDurationForJsonr
   DurationpostConditionsr(   ClusterUpgradePostConditionssoaking)r    r!   r0   default_soakingpost_conditionss        r   r+   zUpdate._HandleDefaultSoakTime_   s~     $$%>?''/11d&B&BCO 	++ 	8==557  .O*9'r   c                 `   |j                  d      r|j                  rg |_        y|j                  d      r|j                  d      r|j                  |j                  t        j                  t        j                  |j                              }|j                  xs g }| j                  j                         }| j                  j                  |      |_        |j                  d   }|j                  d   }| j                  j                  ||	      |_        ||gz   }||_        yyyyy)
z?Updates the ClusterUpgrade Feature's gkeUpgradeOverrides field. remove_upgrade_soaking_overridesadd_upgrade_soaking_overrideupgrade_selectorNr;   )rA   nameversion)rH   rI   )r7   rE   gkeUpgradeOverridesrF   rG   r   r=   r
   r>   r(    ClusterUpgradeGKEUpgradeOverrider@   r?   ClusterUpgradeGKEUpgradeupgrade)	r    r!   r0   rA   existing_gke_upgrade_overridesnew_gke_upgrade_overrideupgrade_nameupgrade_versionnew_gke_upgrade_overridess	            r   r,   z%Update._HandleUpgradeSoakingOverridesq   sG    	  !CD1113.  !?@$$%78--9!!-++


(I(I
Jg 
2
2
8b % --
8
8
:  --
4
4W
4
E - **62l--i8o)-)O)O_ *P *& #A
"D # 2K./ . : 9 	Ar   )__name__
__module____qualname____doc__detailed_helpCLUSTER_UPGRADE_FEATUREfeature_namestaticmethodr   r%   r   r*   r+   r,   __classcell__)r3   s   @r   r   r   "   s\     N   - ),7 75( B B:$"Kr   r   c                   "    e Zd ZdZd Zd Zd Zy)r   z4Base class for enabling the Cluster Upgrade Feature.c                 (    t         | _        || _        y )N)rX   rY   r!   )r    r!   s     r   __init__z_EnableCommand.__init__   s    /DDIr   c                 J    | j                   j                  j                         S )z:Required to initialize HubClient. See calliope base class.)r!   calliope_commandReleaseTrack)r    s    r   ra   z_EnableCommand.ReleaseTrack   s    99%%2244r   c                     	 | j                   j                  | j                  |            S # t        j                  $ r< | j                  | j                  j                                | j                         cY S w xY w)zBGets the project's Cluster Upgrade Feature, enabling if necessary.)r"   )	hubclient
GetFeatureFeatureResourceNameapitools_exceptionsHttpNotFoundErrorEnabler(   r-   )r    r"   s     r   r   z!_EnableCommand.GetWithForceEnable   sn    
^^&&

"
"7
"
3  00  kk$--'')*__s   *- AA<;A<N)rS   rT   rU   rV   r^   ra   r    r   r   r   r      s    <5r   r   N)rV   
__future__r   r   r   apitools.base.pyr   rf   googlecloudsdk.callioper   9googlecloudsdk.command_lib.container.fleet.clusterupgrader   r   3googlecloudsdk.command_lib.container.fleet.featuresfeature_base$googlecloudsdk.command_lib.util.apisr	   googlecloudsdk.core.utilr
   r   rX   ReleaseTracksra   ALPHABETAGAUpdateCommandr   EnableCommandMixinr   ri   r   r   <module>rx      s     I &  ' > ( c T : 1 * +  T..33T5F5F5I5InK\'' nKnKb\44 r   