
    d                     P   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  e
j"                  e
j$                  j&                  e
j$                  j(                  e
j$                  j*                         G d de
j,                               Zy)zICauses a high-availability Cloud SQL instance to failover to its replica.    )absolute_import)division)unicode_literals)api_util)
operations)validate)base)flags)
properties)
console_ioc                   &    e Zd ZdZed        Zd Zy)Failoverz:Causes a high-availability Cloud SQL instance to failover.c                     | j                  dt        j                  d       t        j                  j                  |        y)z@Args is called by calliope to gather arguments for this command.instancezCloud SQL instance ID.)	completerhelpN)add_argumentr
   InstanceCompleterr	   
ASYNC_FLAGAddToParser)parsers    %lib/surface/sql/instances/failover.pyArgszFailover.Args#   s:     ))%  ' 	OO'    c           
      B   t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }t        j                   ddd       |j"                  j%                  |j'                  |j                  |j                              }|j)                  |j                  |j                  |j+                  |j-                  d|j.                  j0                  	      
            }|j"                  j3                  |      }|j                  j5                  d|j6                  |j                        }	|j8                  r@|j:                  j%                  |j=                  |	j                  |	j>                              S t:        j@                  jC                  ||	d       y)a  Calls the failover api method.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A dict object representing the operations resource describing the failover
      operation if the failover was successful.
    projectzsql.instances)params
collectionzFailover will be initiated. Existing connections to the primary instance will break and no new connection can be established during the failover.T)messagedefaultcancel_on_no)r   r   zsql#failoverContext)kindsettingsVersion)failoverContext)r   r   instancesFailoverRequestzsql.operations)	operationr   )r   r&   zFailing over Cloud SQL instanceN)"r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserParser   VALUEScorer   	GetOrFailr   PromptContinue	instancesGetSqlInstancesGetRequestSqlInstancesFailoverRequestInstancesFailoverRequestFailoverContextsettingsr#   r   Createnameasync_r   SqlOperationsGetRequestr&   OperationsV1Beta4WaitForOperation)
selfargsclientr)   r*   instance_refr   requestresult_operationoperation_refs
             r   RunzFailover.Run,   s     < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L
   ##''++ ((<3H3H 	, 	JKH 66$$&&!-!F!F(88* ( 1 1 A A 9 C "G "D 7 EG "++44W=**11"''$$ 2 &M
 {{""&&

.
.#++%// / 12 2
   11M#DF r   N)__name__
__module____qualname____doc__staticmethodr   rF    r   r   r   r      s     C( (8r   r   N)rJ   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   r   googlecloudsdk.callioper	   googlecloudsdk.command_lib.sqlr
   googlecloudsdk.corer   googlecloudsdk.core.consoler   ReleaseTracksReleaseTrackGABETAALPHACommandr   rL   r   r   <module>rY      s    P &  ' / 1 / ( 0 * 2 D%%(($*;*;*@*@%%++-Dt|| D-Dr   