
    ;5                     X   S 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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rSrSr\\S.r\\\-   S.rS rS rS rS rS rS r \RB                  \RD                  " \RF                  RH                  \RF                  RJ                  5       " S S\RL                  5      5       5       r'\RB                  \RD                  " \RF                  RP                  5       " S S\RL                  5      5       5       r)g)Clones a Cloud SQL instance.    )absolute_import)division)unicode_literals)
exceptions)api_util)
operations)validate)arg_parsers)base)flags)	instances)log)
propertiesai  
    *{command}* creates a clone of a Cloud SQL instance. The clone is an
    independent copy of the source instance with the same data and settings.
    Source and destination instances must be in the same project. An instance
    can be cloned from its current state, or from an earlier point in time.

    For MySQL: The binary log coordinates or timestamp (point in time), if
    specified, act as the point in time the source instance is cloned from. If
    not specified, the current state of the instance is cloned.

    For PostgreSQL: The point in time, if specified, defines a past state of the
    instance to clone. If not specified, the current state of the instance is
    cloned.

    For SQL Server: The point in time, if specified, defines a past state of the
    instance to clone. If not specified, the current state of the instance is
    cloned.

    a       To clone an instance from its current state (most recent binary log
  coordinates):

    $ {command} my-source-instance my-cloned-instance

  To clone a MySQL instance from an earlier point in time (past binary log
  coordinates):

    $ {command} my-source-instance my-cloned-instance --bin-log-file-name mysql-bin.000020 --bin-log-position 170

  To clone a MySQL source instance at a specific point in time:

    $ {command} my-source-instance my-cloned-instance --point-in-time '2012-11-15T16:19:00.094Z'

  To clone a PostgreSQL source instance at a specific point in time:

    $ {command} my-source-instance my-cloned-instance --point-in-time '2012-11-15T16:19:00.094Z'

  To clone a SQL Server source instance at a specific point in time:

    $ {command} my-source-instance my-cloned-instance --point-in-time '2012-11-15T16:19:00.094Z'

  To clone a deleted instance, include the name and deletion time of the source instance:

  $ {command} my-source-instance my-cloned-instance --source-instance-deletion-time '2012-11-15T16:19:00.094Z'
    z
  To specify the allocated IP range for the private IP target Instance
  (reserved for future use):

  $ {command} my-source-instance my-cloned-instance --allocated-ip-range-name cloned-instance-ip-range
    )DESCRIPTIONEXAMPLESc                    [         R                  " U R                  5        [         R                  " U R                  5        UR                  R                  U R                  S[        R                  R                  R                  R                  0SS9nUR                  R                  U R                  S[        R                  R                  R                  R                  0SS9n[        X#5        X#4$ )zAGet validated refs to source and destination instances from args.projectzsql.instances)params
collection)r
   ValidateInstanceNamesourcedestinationresource_parserParser   VALUEScorer   	GetOrFail_CheckSourceAndDestination)argsclientsource_instance_refdestination_instance_refs       "lib/surface/sql/instances/clone.py_GetInstanceRefsFromArgsr%   f   s     ,
 0 01..44
kk**//77AAB  5 " $3399
**//77AAB  : "
 0K		66    c                     U R                   UR                   :w  a8  [        R                  " SR                  U R                   UR                   S95      eg)zBVerify that the source and destination instance ids are different.zWThe source and the clone instance must belong to the same project: "{src}" != "{dest}".)srcdestN)r   r   ArgumentErrorformat)r"   r#   s     r$   r   r   x   sX       $<$D$DD

"
"	  &#++)11 !' !34 4 Er&   c                 &    U R                  SSSS9  g)z,Declare alpha flags for this command parser.z--allocated-ip-range-nameFa0        The name of the IP range allocated for the destination instance with
      private network connectivity. For example:
      'google-managed-services-default'. If set, the destination instance
      IP is created in the allocated range represented by this name.
      Reserved for future use.
      requiredhelpN)add_argumentparsers    r$   AddAlphaArgsr3      s     !
  	r&   c                    U R                   R                  nUR                  (       a;  UR                  (       a*  UR	                  UR                  UR                  S9Ul        O1UR                  (       a   UR                  R                  S5      Ul        UR                  (       a+  UR                  (       a  UR                  /UR                  SS& UR                  (       a  UR                  Ul        UR                  (       a  UR                  Ul        UR                  (       a   UR                  R                  S5      Ul        U["        R$                  R&                  :X  a$  UR(                  (       a  UR(                  Ul        ggg)z"Update request with clone options.)binLogFileNamebinLogPositionz%Y-%m-%dT%H:%M:%S.%fZN)instancesCloneRequestcloneContextbin_log_file_namebin_log_positionBinLogCoordinatesbinLogCoordinatespoint_in_timestrftimepointInTimerestore_database_namedatabaseNamespreferred_zonepreferredZonepreferred_secondary_zonepreferredSecondaryZonesource_instance_deletion_timesourceInstanceDeletionTimer   ReleaseTrackALPHAallocated_ip_range_nameallocatedIpRange)requestr    sql_messagesrelease_trackclone_contexts        r$   _UpdateRequestFromArgsrP      s-   //<<-	 5 5&2&D&D--,, 'E '.M#  $ 2 2 ; ;!!M 
D66&*&@&@%AM"	"&"5"5M	""+/+H+HM(	''**334KL , d''---##'+'C'Cm$ $ .r&   c                    [         R                  " [         R                  5      nUR                  nUR                  n[        X5      u  pVUR                  UR                  UR                  UR                  UR                  SUR                  S9S9S9n[        XpXA5         UR                  R                  UR                  UR                  UR                  S95      nUR                  (       a  [         R"                  " SS5        UR                  R)                  U5      n	UR*                  R-                  SU	R.                  UR                  S	9n
U R0                  (       aZ  U R3                  S
5      (       d  SU l        UR6                  R                  UR9                  U
R                  U
R:                  S95      $ [6        R<                  R?                  X:S5        [@        RB                  " U5        UR                  R                  UR                  UR                  UR                  S95      nSUl"        U$ ! [$        R&                   a     GNHf = f)a{  Clones a Cloud SQL instance.

Args:
  args: argparse.Namespace, The arguments used to invoke this command.
  release_track: base.ReleaseTrack, the release track that this was run under.

Returns:
  A dict object representing the operations resource describing the
  clone operation if the clone was successful.
Raises:
  ArgumentError: The arguments are invalid for some reason.
zsql#cloneContext)kinddestinationInstanceName)r8   )r   instancer7   )r   rT   clonezthe source instancezsql.operations)	operationr   r+   default)r   rV   zCloning Cloud SQL instanceN)#r   	SqlClientAPI_VERSION_DEFAULT
sql_clientrM   r%   SqlInstancesCloneRequestr   rT   InstancesCloneRequestCloneContextrP   r   GetSqlInstancesGetRequestdiskEncryptionConfigurationcommand_utilShowCmekWarningapitools_exceptions	HttpErrorCloner   Createnameasync_IsSpecifiedr+   r	   SqlOperationsGetRequestrV   OperationsV1Beta4WaitForOperationr   CreatedResourcerR   )r    rN   r!   rZ   rM   r"   r#   rL   source_instance_resourceresultoperation_refrsources               r$   RunBaseCloneCommandrr      s>    h::;&  *$$, t, 0 11!))"++(>>#00%&>&G&G 1 I ? J 2 K' D		)3377++'//(11 	, 	3 4  ;;""7,AB
 %%g.&((//&.. 0 0-
 
[[H%%dk  $$,,!))]5L5L 	- 	NO O //
0LN./  $$))*22+44 * 67' ',	.3 
	&	& 		s   !A%H7 7IIc                    [         R                  R                  U 5        U R                  R	                  [
        R                  " 5       5        U R                  S[
        R                  SS9  U R                  SSS9  U R                  SSS	9nUR                  SSS
S9nUR                  SSSS9  UR                  S[        SSS9  UR                  SSS	9nUR                  S[        R                  R                  SSS9  UR                  SSSS9  U R                  SSSS9  U R                  SSSS9  U R                  S[        R                  R                  SSS9  g)z0Add args common to all release tracks to parser.r   z$Cloud SQL instance ID of the source.)	completerr/   r   z#Cloud SQL instance ID of the clone.)r/   TF)mutexr.   z2Binary log coordinates for point-in-time recovery.)ru   r.   r/   z--bin-log-file-nameaI        The name of the binary log file. Enable point-in-time recovery on the
      source instance to create a binary log file. If specified with
      <--bin-log-position> to form a valid binary log coordinate, it defines an
      earlier point in time to clone a source instance from.
      For example, mysql-bin.000001.
      r-   z--bin-log-positiona;        Represents the state of an instance at any given point in time inside a
      binary log file. If specified along with <--bin-log-file-name> to form a
      valid binary log coordinate, it defines an earlier point in time to clone
      a source instance from.
      For example, 123 (a numeric value).
      )typer.   r/   z--point-in-timea        Represents the state of an instance at any given point in time inside
      a transaction log file. For MySQL, the binary log file is used for
      transaction logs. For PostgreSQL, the write-ahead log file is used for
      transaction logs. For SQL Server, the log backup file is used for
      such purpose. To create a transaction log, enable point-in-time recovery
      on the source instance. Instance should have transaction logs accumulated
      up to the point in time they want to restore up to. Uses RFC 3339 format
      in UTC timezone. If specified, defines a past state of the instance to
      clone. For example, '2012-11-15T16:19:00.094Z'.
      z--restore-database-namez    The name of the database to be restored for a point-in-time restore. If
    set, the destination instance will only restore the specified database.
    z--preferred-zonez    The preferred zone for the cloned instance. If you specify a value for
    this flag, then the destination instance uses the value as the primary
    zone.
    z--preferred-secondary-zonez    The preferred secondary zone for the cloned regional instance. If you
    specify a value for this flag, then the destination instance uses the
    value as the secondary zone. The secondary zone can't be the same as the
    primary zone.
    z--source-instance-deletion-timezq      The time the source instance was deleted. This is required if cloning
      from a deleted instance.
      N)r   
ASYNC_FLAGAddToParserdisplay_info	AddFormatr   GetInstanceListFormatr0   InstanceCompleter	add_groupintr   Datetimer   )r2   pitr_options_groupbin_log_grouppoint_in_time_groups       r$   AddBaseArgsr      s   //f% ; ; =>''1  3 	m*OP''dU'C$..? / A- 
  	 
	  
 +44E 5 #""%%

	 #  "" # 	 	  	 	"  	 	'%%
	  r&   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)re   iK  r   c                 l    [        U5        UR                  R                  [        R                  5        g)z=Declare flag and positional arguments for the command parser.N)r   ry   AddCacheUpdaterr   r|   )clsr2   s     r$   Args
Clone.ArgsR  s&     
''(?(?@r&   c                 4    [        XR                  5       5      $ Nrr   rH   selfr    s     r$   Run	Clone.RunX      t%6%6%899r&    N)__name__
__module____qualname____firstlineno____doc__DETAILED_HELPdetailed_helpclassmethodr   r   __static_attributes__r   r&   r$   re   re   K  s%     %-A A
:r&   re   c                   2    \ rS rSrSr\rS r\S 5       r	Sr
g)
CloneAlphai\  r   c                 4    [        XR                  5       5      $ r   r   r   s     r$   r   CloneAlpha.Runc  r   r&   c                     [        U 5        [        U 5        U R                  R                  [        R
                  5        g)z@Args is called by calliope to gather arguments for this command.N)r   r3   ry   r   r   r|   r1   s    r$   r   CloneAlpha.Argsf  s.     
''(?(?@r&   r   N)r   r   r   r   r   DETAILED_APLHA_HELPr   r   staticmethodr   r   r   r&   r$   r   r   \  s'     %%-: A Ar&   r   N)*r   
__future__r   r   r   apitools.base.pyr   rc   googlecloudsdk.api_lib.sqlr   r	   r
   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.sqlr   r   ra   googlecloudsdk.corer   r   r   EXAMPLES_GAEXAMPLES_ALPHAr   r   r%   r   r3   rP   rr   r   DefaultUniverseOnlyReleaseTracksrH   GABETACreateCommandre   rI   r   r   r&   r$   <module>r      s/   # &  ' > / 1 1 / / ( 0 D # **8  n, 7$4D@@FTn D%%(($*;*;*@*@A:D : B : D%%++,A## A - Ar&   