
                             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  G d	 d
ej                        Zy)z)Command for setting a backup target pool.    )absolute_import)division)unicode_literals)base_classes)base)
exceptions)flagsc                   .    e Zd ZdZdZdZed        Zd Zy)	SetBackupa  Set a backup pool for a target pool.

  *{command}* is used to set a backup target pool for a primary
  target pool, which defines the fallback behavior of the primary
  pool. If the ratio of the healthy instances in the primary pool
  is at or below the specified ``--failover-ratio value'', then traffic
  arriving at the load-balanced IP address will be directed to the
  backup pool.

  ## EXAMPLES
  To cause `TARGET-POOL` (in region `us-central1`) to fail over
  to `BACKUP-POOL` when more than half of the `TARGET-POOL`
  instances are unhealthy, run:

    $ {command} TARGET-POOL --backup-pool=BACKUP-POOL --failover-ratio=0.5 --region=us-central1

  To remove `BACKUP-POOL` as a backup to `TARGET-POOL`, run:

    $ {command} TARGET-POOL --backup-pool='' --region=us-central1
  Nc                 f   t        j                         | _        t        j                  d      | _        | j                  j                  |d       |j                  d      }|j                  ddd	
       |j                  dt         j                  d       |j                  dt        d       y )Nz" for which to set the backup pool.)help_suffixzset a backup pool for)operation_typeT)requiredz--no-backup-pool
store_truez/Unsets the backup pool. This disables failover.)actionhelpz--backup-poolz2Name of the target pool that will serve as backup.)	completerr   z--failover-ratioz^The new failover ratio value for the target pool. This must be a float in the range of [0, 1].)typer   )
r	   BackupPoolArgumentBACKUP_POOL_ARGTargetPoolArgumentTARGET_POOL_ARGAddArgumentadd_mutually_exclusive_groupadd_argumentTargetPoolsCompleterfloat)clsparserbackup_pool_groups      .lib/surface/compute/target_pools/set_backup.pyArgszSetBackup.Args7   s    224C228:C##6 $ 8 ;;T;J""<> # @ "",,A # C
 =  ?    c                    t        j                  | j                               }|j                  }| j                  j                  ||j                  t        j                  |            }|j                  rb|j                  |_        | j                  j                  ||j                        }|j                  j                  |j                               }n|j                  j                         }|j                  r!|j                   t#        j$                  d      |j                   3|j                   dk  s|j                   dkD  rt#        j$                  d      |j                  j'                  |j)                         ||j                   |j                  |j*                        }|j-                  |j.                  j0                  d|fg      S )	z<Issues a request necessary for setting a backup target pool.)scope_lister)targetz?[--failover-ratio] must be provided when setting a backup pool.r      z?[--failover-ratio] must be a number between 0 and 1, inclusive.)
targetPooltargetReferencefailoverRatioregionprojectr   )r   ComputeApiHolderReleaseTrackclientr   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerbackup_poolr+   backup_pool_regionr   messagesTargetReferenceSelfLinkfailover_ratiocompute_exceptionsArgumentError"ComputeTargetPoolsSetBackupRequestNamer,   MakeRequestsapitools_clienttargetPools)selfargsholderr/   target_pool_refbackup_pool_reftarget_referencerequests           r!   RunzSetBackup.RunN   s   **4+<+<+>?F]]F**<<"88@ = BO
  / 6 6d,,>>t?E?O?OQo88 ))+ 9 -  88:D//7,,
KM M &a4#6#6#:,,
KM M oo@@"'')())%%'' A )G !7!7!C!C!,g!7  8 9 9r#   )	__name__
__module____qualname____doc__r   r   classmethodr"   rH    r#   r!   r   r      s*    , //? ?,$9r#   r   N)rL   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r:   r	   r2   /googlecloudsdk.command_lib.compute.target_poolsSilentCommandr   rN   r#   r!   <module>rU      s6    0 &  ' 7 ( O E AV9"" V9r#   