
    &                        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 dZdj%                  e      ddZdj%                  e      ddZ G d de      Z e
j.                  e
j0                  j2                         G d dee
j4                               Z e
j.                  e
j0                  j8                         G d dee
j4                               Zy)z:Command to create migration jobs for a database migration.    )absolute_import)division)unicode_literals)api_util)migration_jobs)resource_args)base)flags)logzMhttps://cloud.google.com/database-migration/docs/mysql/configure-connectivityaE  
        Create a Database Migration Service migration job.
        Recommended steps before creating the migration job:
        - Create a source connection profile. See prerequisites [here](https://cloud.google.com/database-migration/docs/mysql/configure-source-database).
        - Create a destination connection profile. For migrating to Cloud SQL for MySQL or Cloud SQL for PostgreSQL, use the cloudsql connection profile for DMS to create the CloudSQL replica for you.
        - Configure the connectivity method. See prerequisites [here]({MYSQL_CONNECTIVITY_DOC}).
        )MYSQL_CONNECTIVITY_DOCa          To create a continuous migration job with IP allowlist connectivity:

            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2

        To create a continuous migration job with VPC peering connectivity:

            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2
            --peer-vpc=projects/my-project/global/networks/my-network

        To create a one-time migration job with reverse-SSH tunnel connectivity:

            $ {command} my-migration-job --region=us-central1 --type=ONE_TIME
            --source=cp1 --destination=cp2 --vm=vm1 --vm-ip=1.1.1.1
            --vm-port=1111 --vpc=projects/my-project/global/networks/my-network
        )DESCRIPTIONEXAMPLESa  
        Create a Database Migration Service migration job.
        Recommended steps before creating the migration job:
        - Create a source connection profile. See prerequisites [here](https://cloud.google.com/database-migration/docs/mysql/configure-source-database).
        - Create a destination connection profile. For migrating to Cloud SQL for MySQL or Cloud SQL for PostgreSQL, use the cloudsql connection profile for DMS to create the CloudSQL replica for you.
        - Configure the connectivity method. See prerequisites [here]({MYSQL_CONNECTIVITY_DOC}).
        - [Heterogeneous migrations only] Create a conversion workspace.
        a          To create a continuous migration job with IP allowlist connectivity:

            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2

        To create a continuous migration job with VPC peering connectivity:

            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2
            --peer-vpc=projects/my-project/global/networks/my-network

        To create a one-time migration job with reverse-SSH tunnel connectivity:

            $ {command} my-migration-job --region=us-central1 --type=ONE_TIME
            --source=cp1 --destination=cp2 --vm=vm1 --vm-ip=1.1.1.1
            --vm-port=1111 --vpc=projects/my-project/global/networks/my-network

        To create a heterogeneous continuous migration job:

            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2 --conversion-workspace=cw

        To create a continuous SQL Server to SQL Server homogeneous migration
        job with differential backup enabled:
            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2
            --sqlserver-diff-backup
            --sqlserver-databases=db1,db2,db3

        To create a continuous SQL Server to SQL Server homogeneous migration
        job with encrypted databases:
            $ {command} my-migration-job --region=us-central1 --type=CONTINUOUS
            --source=cp1 --destination=cp2
            --sqlserver-databases=db1,db2,db3
            --sqlserver-encrypted-databases=PATH/TO/ENCRYPTION/SETTINGS
        c                   &    e Zd ZdZed        Zd Zy)_Create2Create a Database Migration Service migration job.c                 :   t        j                  |        t        j                  |        t        j                  | d       t        j                  |        t        j
                  | t         j                  j                  d       t        j                  |        y)Args is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use to add arguments that go on
        the command line after this command. Positional arguments are allowed.
    TrequiredN)
mj_flagsAddNoAsyncFlagAddDisplayNameFlagAddTypeFlagAddDumpGroupFlagAddConnectivityGroupFlagApiTypeCREATEr
   AddLabelsCreateFlagsparsers    7lib/surface/database_migration/migration_jobs/create.pyArgsz_Create.Argso   so     F#'$/f%%%  ''$ 
v&    c           	         |j                   j                  j                         }|j                         j	                         }|j                   j
                  j                         }|j                   j                  j                         }| j                         t        j                  j                  k(  rI|j                   j                  j                         }|j                   j                  j                         }nd}d}t        j                  | j                               }|j                  ||j                  |||||      }	t!        j"                  | j                               }
t!        j$                  | j                               }t!        j&                  | j                               }|j)                  d      rt*        j,                  j/                  dj1                  |j                  |	j2                               t!        j4                  |
|	|
j6                         t*        j,                  j/                  dj1                  |j                  |	j2                               y|j                  d|	j2                  |j8                  |j:                        }|
j<                  j?                  |jA                  |jB                              S )a'  Create a Database Migration Service migration job.

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

    Returns:
      A dict object representing the operations resource describing the create
      operation if the create was successful.
    Nno_asyncz6Waiting for migration job [{}] to be created with [{}]zCreated migration job {} [{}]z+datamigration.projects.locations.operations)operationsId
projectsIdlocationsId)name)"CONCEPTSmigration_jobParseParentRelativeNamesourcedestinationReleaseTrackr	   GAconversion_workspacecmek_keyr   MigrationJobsClientCreatemigrationJobsIdr   GetClientInstanceGetMessagesModuleGetResourceParserIsKnownAndSpecifiedr   statusPrintformatr)   	HandleLRO projects_locations_migrationJobsr'   r(   projects_locations_operationsGet2DatamigrationProjectsLocationsOperationsGetRequestr&   )selfargsmigration_job_ref
parent_ref
source_refdestination_refconversion_workspace_refcmek_key_ref	mj_clientresult_operationclientmessagesresource_parseroperation_refs                 r!   Runz_Create.Run   sT    3399;"))+88:J%%++-Jmm//557Od//222!%!C!C!I!I!K]]++113l!%l2243D3D3FGI ''))  ''(9(9(;<F))$*;*;*=>H001B1B1DEO
+	jj
B
I
I//1A1F1FHI !1@@B 
jj6==

+
+-=-B-BD E#**5%**$//%11	 + 3M //33CC++ 	D 	-. .r#   N)__name__
__module____qualname____doc__staticmethodr"   rR    r#   r!   r   r   l   s    :' ' :.r#   r   c                   $    e Zd ZdZeZed        Zy)CreateGAr   c                    t        j                  | dd       t        j                  |        t	        j
                  |        t	        j                  |        t	        j                  |        t	        j                  | d       t	        j                  |        t	        j                  |        t	        j                  |        y)r   	to createTr   F)	is_updateN)r   (AddHeterogeneousMigrationJobResourceArgsr   r"   r   AddFilterFlagAddCommitIdFlagAddDumpParallelLevelFlag*AddSqlServerHomogeneousMigrationConfigFlagAddDumpTypeFlag2AddMigrationJobObjectsConfigFlagForCreateAndUpdate#AddHeterogeneousMigrationConfigFlagr   s    r!   r"   zCreateGA.Args   s     ::d LL6"V$%%f-77%PV$??G008r#   N)rS   rT   rU   rV   DETAILED_HELP_GAdetailed_helprW   r"   rX   r#   r!   rZ   rZ      s    :"-9 9r#   rZ   c                   $    e Zd ZdZeZed        Zy)CreateAlphar   c                 ^    t        j                  | dd       t        j                  |        y)r   r\   Tr   N)r   AddMigrationJobResourceArgsr   r"   r   s    r!   r"   zCreateAlpha.Args   s'     --d LLr#   N)rS   rT   rU   rV   DETAILED_HELP_ALPHArg   rW   r"   rX   r#   r!   ri   ri      s    :%-
 
r#   ri   N)rV   
__future__r   r   r   )googlecloudsdk.api_lib.database_migrationr   r   r   googlecloudsdk.callioper	   -googlecloudsdk.command_lib.database_migrationr
   <googlecloudsdk.command_lib.database_migration.migration_jobsr   googlecloudsdk.corer   r   r>   rl   rf   objectr   ReleaseTracksr1   r2   CommandrZ   ALPHAri   rX   r#   r!   <module>rw      s    A &  ' > D C ( ? Z #h  F*@FA : F*@FA$. bN.f N.b D%%(()9w 9 *94 D%%++,'4<<  -r#   