
    T                        d Z ddlmZ ddlmZ ddlmZ ddlZddl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j0                   ej2                  ej4                  j6                         G d dej8                                      Z ej2                  ej4                  j<                         G d de             Z ej2                  ej4                  j@                         G d de             Z!y)z4Migrates a Cloud SQL instance to an AlloyDB cluster.    )absolute_import)division)unicode_literalsN)messages)api_util)cluster_operations)base)cluster_helper)flags)resource_args)log)
properties)	resourcesc                       e Zd ZdZdddZedej                  ddfd       Zd	e	j                  d
ej                  dej                  dej                  fdZdej                  dej                  fdZy)MigrateCloudSqlGAzTMigrate Cloud SQL instance to an AlloyDB cluster using an existing Cloud SQL backup.z{description}a+            To migrate a Cloud SQL instance to an AlloyDB cluster from a backup, run:

              $ {command} my-alloydb-cluster --region=us-central1 --cloud-sql-project-id=my-cloud-sql-project-id --cloud-sql-instance-id=my-cloud-sql-cluster-id --cloud-sql-backup-id=my-cloud-sql-backup-id
        )DESCRIPTIONEXAMPLESparserreturnNc                 N   t        j                  | j                               }t        j                  j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |dd       t        j                  ||| j                         d       t        j                  || j                                t        j                   ||       t        j"                  |       t        j$                  ||       t        j&                  ||       t        j(                  |       t        j*                  |       t        j,                  ||       y)zhSpecifies additional command flags.

    Args:
      parser: Parser object for command line inputs.
    clusterzjThe 'AlloyDB Service Agent' service account must hold permission 'Cloud KMS CryptoKey Encrypter/Decrypter')permission_infoF)updateN)r   GetMessagesModuleReleaseTrackr	   
ASYNC_FLAGAddToParserr   	AddRegion
AddCluster
AddNetworkAddPasswordAddAllocatedIPRangeNamekms_resource_argsAddKmsKeyResourceArgAddAutomatedBackupFlagsAddContinuousBackupConfigFlagsAddDatabaseVersionAddEnablePrivateServiceConnectAddMaintenanceWindowAddSubscriptionTypeAddTagsAddMigrateCloudSqlFlagsAddDenyMaintenancePeriod)clsr   alloydb_messagess      1lib/surface/alloydb/clusters/migrate_cloud_sql.pyArgszMigrateCloudSqlGA.Args5   s7     11#2B2B2DEOO'	OOF	V	V	f	!!&)**9	 
!! #"2"2"4U 
((1A1A1CD	V%56	((0	v'78	f&67	MM&	!!&)	""6+;<    r/   location_refargsc                 0    t        j                  |||      S aU  Constructs the Migrate Cloud Sql request.

    Args:
      alloydb_messages: The AlloyDB messages module.
      location_ref: The location reference for the request.
      args: An object that contains the values for the arguments specified in
        the .Args() method.

    Returns:
      The Migrate Cloud Sql request based on args.
    )r
   )ConstructMigrateCloudSqlRequestFromArgsGAselfr/   r3   r4   s       r0   'ConstructMigrateCloudSqlRequestFromArgsz9MigrateCloudSqlGA.ConstructMigrateCloudSqlRequestFromArgsW   s    " CC, r2   c                    t        j                  | j                               }|j                  }|j                  }|j
                  j                  dt        j                  j                  j                  j                  |j                        }| j                  |||      }|j                  j                  |      }t         j"                  j%                  |j&                  d      }t(        j*                  j-                  dj/                  |j1                                      |j2                  s%t5        j6                  |d| j                                |S )zConstructs request from args, and sends it to the server.

    Args:
      args: An object that contains the values for the arguments specified in
        the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    zalloydb.projects.locations)
projectsIdlocationsIdz%alloydb.projects.locations.operations)
collectionzOperation ID: {}zMigrating Cloud SQL)r   AlloyDBClientr   alloydb_clientr/   resource_parserCreater   VALUEScoreproject	GetOrFailregionr:   projects_locations_clustersRestoreFromCloudSQLr   REGISTRYParseRelativeNamenamer   statusPrintformatNameasync_r   Await)	r9   r4   clientr@   r/   r3   reqopop_refs	            r0   RunzMigrateCloudSqlGA.Runl   s    ##D$5$5$78F**N..))00$$$))11;;KK 1 L 
6
6,C 
	3	3	G	G	LB11
C 2 F JJ'..v{{}=>;;
'):):)< Ir2   )__name__
__module____qualname____doc__detailed_helpclassmethodargparsePARSERr1   types
ModuleTyper   Resource	Namespacer   Messager:   rW    r2   r0   r   r   '   s     ] %- = =D = =B(( && 	
 * h((  X-=-=  r2   r   c                        e Zd ZdZedej                  ddf fd       Zdej                  de
j                  dej                  dej                  fd	Z xZS )
MigrateCloudSqlBetaMigrate Cloud SQL instance to an AlloyDB cluster.

  This command migrates a Cloud SQL instance to an AlloyDB cluster using an
  existing Cloud SQL backup.
  r   r   Nc                 ,    t         t        |   |       y N)superrg   r1   r.   r   	__class__s     r0   r1   zMigrateCloudSqlBeta.Args   s    	
s(0r2   r/   r3   r4   c                 0    t        j                  |||      S r6   )r
   +ConstructMigrateCloudSqlRequestFromArgsBetar8   s       r0   r:   z;MigrateCloudSqlBeta.ConstructMigrateCloudSqlRequestFromArgs   s    " EE, r2   rX   rY   rZ   r[   r]   r^   r_   r1   r`   ra   r   rb   rc   r   rd   r:   __classcell__rm   s   @r0   rg   rg      sq     1 1D 1 1(( && 	
 r2   rg   c                        e Zd ZdZedej                  ddf fd       Zdej                  de
j                  dej                  dej                  fd	Z xZS )
MigrateCloudSqlAlpharh   r   r   Nc                 ,    t         t        |   |       y rj   )rk   rt   r1   rl   s     r0   r1   zMigrateCloudSqlAlpha.Args   s    	
)&1r2   r/   r3   r4   c                 0    t        j                  |||      S r6   )r
   ,ConstructMigrateCloudSqlRequestFromArgsAlphar8   s       r0   r:   z<MigrateCloudSqlAlpha.ConstructMigrateCloudSqlRequestFromArgs   s    " FF, r2   rp   rr   s   @r0   rt   rt      sq     2 2D 2 2(( && 	
 r2   rt   )"r[   
__future__r   r   r   r^   r`   apitools.base.protorpcliter   googlecloudsdk.api_lib.alloydbr   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.alloydbr
   r   googlecloudsdk.command_lib.kmsr   r#   googlecloudsdk.corer   r   r   DefaultUniverseOnlyReleaseTracksr   GARestoreCommandr   BETArg   ALPHArt   re   r2   r0   <module>r      s    ; &  '   / 3 = ( = 4 M # * ) D%%(()c++ c * cL D%%**++  ,B D%%++,,  -r2   