
                             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  G d d      Z G d	 d
ej                        Z
y)z3Functions to add flags in cluster upgrade commands.    )absolute_import)division)unicode_literals)arg_parsers)parser_argumentsc                      e Zd ZdZdej
                  fdZed        Zd Z	d Z
ddZdej
                  fd	Zdej
                  fd
Zdej
                  fdZdej
                  fdZddZdej
                  fdZdej
                  fdZy)ClusterUpgradeFlagsz1Add flags to the cluster upgrade command surface.parserc                     || _         y N_parser)selfr
   s     Flib/googlecloudsdk/command_lib/container/fleet/clusterupgrade/flags.py__init__zClusterUpgradeFlags.__init__   s	    DL    c                     | j                   S r   r   r   s    r   r
   zClusterUpgradeFlags.parser   s    <<r   c                 B    | j                   j                  dddd       y)z,Adds the --show-linked-cluster-upgrade flag.z--show-linked-cluster-upgrade
store_trueNa^          Shows the cluster upgrade feature information for the current fleet as
        well as information for all other fleets linked in the same rollout
        sequence (provided that the caller has permission to view the upstream
        and downstream fleets). This displays cluster upgrade information for
        fleets in the current fleet's rollout sequence in order of furthest
        upstream to downstream.

        To view the cluster upgrade feature information for the rollout
        sequence containing the current fleet, run:

          $ {command} --show-linked-cluster-upgrade
        actiondefaulthelp)r
   add_argumentr   s    r   AddShowLinkedClusterUpgradez/ClusterUpgradeFlags.AddShowLinkedClusterUpgrade#   s'    KK'	  r   c                 d    | j                   j                  dt        j                         d       y)z(Adds the --default-upgrade-soaking flag.z--default-upgrade-soakinga          Configures the default soaking duration for each upgrade propagating
        through the current fleet to become "COMPLETE". Soaking begins after
        all clusters in the fleet are on the target version, or after 30 days
        if all cluster upgrades are not complete. Once an upgrade state becomes
        "COMPLETE", it will automatically be propagated to the downstream
        fleet. Max is 30 days.

        To configure Rollout Sequencing for a fleet, this attribute must be
        set. To do this while specifying a default soaking duration of 7 days,
        run:

          $ {command} --default-upgrade-soaking=7d
        typer   N)r
   r   r   Durationr   s    r   AddDefaultUpgradeSoakingFlagz0ClusterUpgradeFlags.AddDefaultUpgradeSoakingFlag8   s-    KK#!!#  r   c                     |r=| j                   j                         }| j                  |       | j                  |       y | j                  | j                          y r   )r
   add_mutually_exclusive_group%_AddRemoveUpgradeSoakingOverridesFlag_AddUpgradeSoakingOverrideFlagsr   with_destructivegroups      r   AddUpgradeSoakingOverrideFlagsz2ClusterUpgradeFlags.AddUpgradeSoakingOverrideFlagsM   sE    kk668e
007
**51
**4;;7r   r(   c                 .    |j                  dddd       y)zvAdds the --remove-upgrade-soaking-overrides flag.

    Args:
      group: The group that should contain the flag.
    z"--remove-upgrade-soaking-overridesr   Na          Removes soaking time overrides for all upgrades propagating through the
        current fleet. Consequently, all upgrades will follow the soak time
        configured by `--default-upgrade-soaking` until new overrides are
        configured with `--add_upgrade_soaking_override` and
        `--upgrade_selector`.

        To remove all configured soaking time overrides, run:

          $ {command} --remove-upgrade-soaking-overrides
        r   r   r   r(   s     r   r$   z9ClusterUpgradeFlags._AddRemoveUpgradeSoakingOverridesFlagU   s%     
,
	  r   c                 l    |j                  d      }| j                  |       | j                  |       y)zAdds upgrade soaking override flags.

    Args:
      group: The group that should contain the upgrade soaking override flags.
    a4          Upgrade soaking override.

        Defines a specific soaking time override for a particular upgrade
        propagating through the current fleet that supercedes the default
        soaking duration configured by `--default-upgrade-soaking`.

        To set an upgrade soaking override of 12 hours for the upgrade with
        name, `k8s_control_plane`, and version, `1.23.1-gke.1000`, run:

          $ {command}               --add-upgrade-soaking-override=12h               --upgrade-selector=name="k8s_control_plane",version="1.23.1-gke.1000"
        )r   N)	add_group!_AddAddUpgradeSoakingOverrideFlag_AddUpgradeSelectorFlagr,   s     r   r%   z3ClusterUpgradeFlags._AddUpgradeSoakingOverrideFlagsn   s7     OO "O E 	**51  'r   c                 R    |j                  dt        j                         dd       y)zrAdds the --add-upgrade-soaking-override flag.

    Args:
      group: The group that should contain the flag.
    z--add-upgrade-soaking-overrideTa7          Overrides the soaking time for a particular upgrade name and version
        propagating through the current fleet. Set soaking to 0 days to bypass
        soaking and fast-forward the upgrade to the downstream fleet.

        See `$ gcloud topic datetimes` for information on duration formats.
        r   requiredr   N)r   r   r    r,   s     r   r/   z5ClusterUpgradeFlags._AddAddUpgradeSoakingOverrideFlag   s.     
(!!#	  r   c                 >    |j                  dt               dd       y)zfAdds the --ugprade-selector flag.

    Args:
      group: The group that should contain the flag.
    z--upgrade-selectorTz        Name and version of the upgrade to be overridden where version is a
        full GKE version. Currently, name can be either `k8s_control_plane` or
        `k8s_node`.
        r2   N)r   UpgradeSelectorr,   s     r   r0   z+ClusterUpgradeFlags._AddUpgradeSelectorFlag   s(     
	  	r   c                     |r=| j                   j                         }| j                  |       | j                  |       y| j                  | j                          y)zAdds upstream fleet flags.N)r
   r#   _AddUpstreamFleetFlag_AddResetUpstreamFleetFlagr&   s      r   AddUpstreamFleetFlagsz)ClusterUpgradeFlags.AddUpstreamFleetFlags   sE    kk668e
  '
%%e,
  -r   c                 4    |j                  dt        d       y)zdAdds the --upstream-fleet flag.

    Args:
      group: The group that should contain the flag.
    z--upstream-fleeta          The upstream fleet. GKE will finish upgrades on the upstream fleet
        before applying the same upgrades to the current fleet.

        To configure the upstream fleet, run:

        $ {command}             --upstream-fleet={upstream_fleet}
        r   N)r   strr,   s     r   r7   z)ClusterUpgradeFlags._AddUpstreamFleetFlag   s"     
  r   c                 .    |j                  dddd       y)zjAdds the --reset-upstream-fleet flag.

    Args:
      group: The group that should contain the flag.
    z--reset-upstream-fleetr   Na          Clears the relationship between the current fleet and its upstream
        fleet in the rollout sequence.

        To remove the link between the current fleet and its upstream fleet,
        run:

          $ {command} --reset-upstream-fleet
        r   r+   r,   s     r   r8   z.ClusterUpgradeFlags._AddResetUpstreamFleetFlag   s%     
 	  r   N)F)__name__
__module____qualname____doc__r   ArgumentInterceptorr   propertyr
   r   r!   r)   r$   r%   r/   r0   r9   r7   r8    r   r   r	   r	      s    9-AA   **8#772(#77(2#77*#77(.)9)M)M *#77r   r	   c                   "     e Zd ZdZ fdZ xZS )r5   zGExtends the ArgDict type to properly parse --upgrade-selector argument.c                 L    t         t        |   t        t        dddgd       y )N)nameversionrF   rG      )specrequired_keys
max_length)superr5   r   r;   )r   	__class__s    r   r   zUpgradeSelector.__init__   s*    	/4)c*y) * r   )r=   r>   r?   r@   r   __classcell__)rM   s   @r   r5   r5      s    O r   r5   N)r@   
__future__r   r   r   googlecloudsdk.callioper   r   r	   ArgDictr5   rC   r   r   <module>rR      s8    : &  ' / 4J JZk)) r   