
    J                     f   S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  \R                   " S S\R                  5      5       r
S	 rS
 rS(S jrS rS rS rS(S jrS rS rS rS rS(S jrS(S jrS)S jrS*S jrS rS rS(S jrS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S(S% jr'S& r(S(S' jr)g)+z:Flags and helpers for the migration jobs related commands.    )absolute_import)division)unicode_literalsN)arg_parsersc                        \ rS rSrSrSrSrSrg)ApiType   zoThis API type is used to differentiate between the classification types of Create requests and Update requests.createupdate N)__name__
__module____qualname____firstlineno____doc__CREATEUPDATE__static_attributes__r       Ilib/googlecloudsdk/command_lib/database_migration/migration_jobs/flags.pyr   r      s    w&&r   r   c                 *    SnU R                  SSUS9  g)z+Adds a --no-async flag to the given parser.zAWaits for the operation in progress to complete before returning.z
--no-async
store_trueactionhelpNadd_argumentparser	help_texts     r   AddNoAsyncFlagr!   !   s$     J  	l<iHr   c                 (    SnU R                  SUS9  g)z/Adds a --display-name flag to the given parser.z
    A user-friendly name for the migration job. The display name can include
    letters, numbers, spaces, and hyphens, and must start with a letter.
    z--display-namer   Nr   r   s     r   AddDisplayNameFlagr$   )   s    ) 	&Y7r   c                 2    SnSS/nU R                  SX#US9  g)z%Adds --type flag to the given parser.zType of the migration job.ONE_TIME
CONTINUOUSz--type)r   choicesrequiredNr   )r   r)   r    r(   s       r   AddTypeFlagr*   2   s+    *)&'Y(  r   c                 N    U R                  SS9n[        U5        [        U5        g)z<Adds a --dump-path or --dump-flags flag to the given parser.TmutexN)	add_groupAddDumpPathFlagAddDumpFlagsFlag)r   
dump_groups     r   AddDumpGroupFlagr2   ;   s%    d+**:r   c                 (    SnU R                  SUS9  g)z,Adds a --dump-path flag to the given parser.zn    Path to the dump file in Google Cloud Storage, in the format:
    `gs://[BUCKET_NAME]/[OBJECT_NAME]`.
    z--dump-pathr#   Nr   r   s     r   r/   r/   B   s    ) 	m)4r   c                 R    SnU R                  SS[        R                  " 5       US9  g)z-Adds a --dump-flags flag to the given parser.zS    A list of dump flags. An object containing a list of "key": "value" pairs.
    z--dump-flagsz	KEY=VALUEmetavartyper   N)r   r   ArgDictr   s     r   r0   r0   K   s3    ) 	 	  r   c                    U[         R                  :X  a  U R                  SSS9nO$U[         R                  :X  a  U R                  SSS9nWR	                  SSSS9  UR	                  S	S
S9  UR                  S5      nUR	                  SSUS9  UR	                  SS[
        US9  UR	                  SSS9  UR	                  SSUS9  g)z1Adds connectivity flag group to the given parser.zThe connectivity method used by the migration job. If a connectivity method isn't specified, then it isn't added to the migration job.Tr,   zThe connectivity method used by the migration job. If a connectivity method isn't specified, then it isn't updated for the migration job.z--static-ipr   a   Use the default IP allowlist method. This method creates a public IP that will be used with the destination Cloud SQL database. The method works by configuring the source database server to accept connections from the outgoing IP of the Cloud SQL instance.r   z
--peer-vpczCName of the VPC network to peer with the Cloud SQL private network.r#   z:Parameters for the reverse-SSH tunnel connectivity method.z--vm-ipzBastion Virtual Machine IP.)r   r)   z	--vm-portz#Forwarding port for the SSH tunnel.)r   r7   r)   z--vmz1Name of VM that will host the SSH tunnel bastion.z--vpcz/Name of the VPC network where the VM is hosted.N)r   r   r.   r   r   int)r   api_typer)   connectivity_groupreverse_ssh_groups        r   AddConnectivityGroupFlagr>   X   s%   ))  *  7>>!))"  *  !!I	 " 	 !!
O "  )22B   3h !    0	 !    F !    < ! r   c                 (    SnU R                  SUS9  g)z)Adds a --filter flag to the given parser.zFilter the entities based on [AIP-160](https://google.aip.dev/160) standard. Example: to filter all tables whose name start with "Employee" and are present under schema "Company", use filter as "Company.Employee```*``` AND type=TABLE"z--filterr#   Nr   r   s     r   AddFilterFlagr@      s!    2  	jy1r   c                 (    SnU R                  SUS9  g)z,Adds a --commit-id flag to the given parser.zCommit id for the conversion workspace to use for creating the migration job. If not specified, the latest commit id will be used by default.z--commit-idr#   Nr   r   s     r   AddCommitIdFlagrB      s"    N  	m)4r   c                 0    Sn/ SQnU R                  SXS9  g)z6Adds a --dump-parallel-level flag to the given parser.zoParallelization level during initial dump of the migration job. If not specified, will be defaulted to OPTIMAL.)MINOPTIMALMAXz--dump-parallel-levelr   r(   Nr   r   r    r(   s      r   AddDumpParallelLevelFlagrI      s'    2  &'-IOr   c                 0    SnSS/nU R                  SXS9  g)z,Adds a --dump-type flag to the given parser.zSThe type of the data dump. Currently applicable for MySQL to MySQL migrations only.LOGICALPHYSICALz--dump-typerG   Nr   rH   s      r   AddDumpTypeFlagrM      s+      
#'m)Er   c                 N    U R                  SS9n[        X!5        [        X!5        g)zEAdds SQL Server homogeneous migration flag group to the given parser.Tr,   N)r.   !AddSqlServerLogShippingConfigFlagAddSqlServerDagConfigFlag)r   	is_update&sqlserver_homogeneous_migration_configs      r   *AddSqlServerHomogeneousMigrationConfigFlagrS      s,    +1+;+;$+;+G(#, BNr   c                 
   U R                  S5      nU(       a6  [        USS9  [        USS9  [        U5        [	        U5        [        U5        g[        USS9  [        USS9  [        U5        [	        U5        [        U5        g)zRAdds SQL Server homogeneous log shipping migration flag group to the given parser.zpThe SQL Server homogeneous migration config. This is used only for SQL Server to CloudSQL SQL Server migrations.N)default_valueF)r)   z*.*(\.|_)(<epoch>\d*)\.(trn|bak|trn\.final)T)r.   AddSqlServerBackupFilePatternAddSqlServerDatabasesFlag"AddSqlServerEncryptedDatabasesFlagAddSqlServerUseDiffBackupFlag AddSqlServerPromoteWhenReadyFlag)r   rQ   sqlserver_log_shipping_configs      r   rO   rO      s    "("2"2;# !%T % ''DE!"?@$%BC!%F % ''DE!"?@$%BCr   c                 ,    SnU R                  SUUSS9  g)z@Adds a --sqlserver-backup-file-pattern flag to the given parser.a  Pattern that describes the default backup naming strategy. The specified pattern should ensure lexicographical order of backups. The pattern should define the following capture group set
epoch - unix timestamp
Example: For backup files TestDB.1691448240.bak, TestDB.1691448254.trn, TestDB.1691448284.trn.final use pattern: .*\.(<epoch>\d*)\.(trn|bak|trn\.final) or .*\.(<timestamp>\d*)\.(trn|bak|trn\.final)
This flag is used only for SQL Server to Cloud SQL migrations.z--sqlserver-backup-file-patternT)r   defaulthiddenNr   )r   rU   r    s      r   rV   rV      s-    1  	'	  r   c                 R    SnU R                  SS[        R                  " SS9UUS9  g)z6Adds a --sqlserver-databases flag to the given parser.a      A list of databases to be migrated to the destination Cloud SQL instance.
    Provide databases as a comma separated list. This list should contain all
    encrypted and non-encrypted database names. This flag is used only for
    SQL Server to Cloud SQL migrations.
    z--sqlserver-databasesdatabaseName   
min_length)r6   r7   r   r)   Nr   r   ArgList)r   r)   r    s      r   rW   rW      s8    ) 	!,  r   c                 P    SnU R                  S[        R                  " 5       US9  g)z@Adds a --sqlserver-encrypted-databases flag to the given parser.a      A JSON/YAML file describing the encryption settings per database for all encrytped databases.
    Note:
    Path to the Certificate (.cer) and Private Key (.pvk) in Cloud Storage,
    should be in the form of `gs://bucketName/fileName`. The instance must
    have write permissions to the bucket and read access to the file.
    An example of a JSON request:
        [{
            "database": "db1",
            "encryptionOptions": {
                "certPath": "Path to certificate 1",
                "pvkPath": "Path to certificate private key 1",
                "pvkPassword": "Private key password 1"
            }
        },
        {
            "database": "db2",
            "encryptionOptions": {
                "certPath": "Path to certificate 2",
                "pvkPath": "Path to certificate private key 2",
                "pvkPassword": "Private key password 2"
            }
        }]

      This flag accepts "-" for stdin. This flag is used only for SQL Server to Cloud SQL migrations.
    z--sqlserver-encrypted-databases)r7   r   N)r   r   YAMLFileContentsr   s     r   rX   rX     s0    )4 	''')  r   c                 *    SnU R                  SSUS9  g)z8Adds a --sqlserver-diff-backup flag to the given parser.a$        Enable differential backups. If not specified, differential backups
      are disabled by default. Use --sqlserver-diff-backup to enable and
      --no-sqlserver-diff-backup to disable. This flag is used only for
      homogeneous SQL Server to Cloud SQL for SQL Server migrations.
    z--sqlserver-diff-backupr   r   Nr   r   s     r   rY   rY   *  s'    ) 	  r   c                     U R                  SSS9nUR                  SSU(       + SS9  UR                  SSU(       + SS9  g	)
zIAdds SQL Server homogeneous DAG migration flag group to the given parser.z|The SQL Server homogeneous DAG migration config. This is used only for SQL Server to CloudSQL SQL for SQL Server migrations.T)r^   z--sqlserver-dag-source-agz*The name of the source availability group.)r   r)   r^   z--sqlserver-dag-linked-serverzLThe name of the linked server that points to the source SQL Server instance.N)r.   r   )r   rQ   sqlserver_dag_configs      r   rP   rP   9  sm    ))G  *  ##!7}	 $  ##% } $ r   c                 *    SnU R                  SSUS9  g)z2Adds a --skip-validation flag to the given parser.zT    Restart the migration job without running prior configuration verification.
    z--skip-validationr   r   Nr   r   s     r   AddSkipValidationFlagrl   S  s'    ) 	  r   c                 p    U R                  SSS9nUR                  SSS9n[        U5        [        U5        g)AAdds migration job objects config flag group to the given parser.!The migration job objects config.Tr,   z/The migration job objects config for databases.N)r.   AddDatabasesFilterFlagAddAllDatabasesFlag)r   migration_configdatabase_configs      r   2AddMigrationJobObjectsConfigFlagForCreateAndUpdatert   _  sM    %%) &  %..7 / / )o&r   c                 :    U R                  SSS9n[        U5        grn   ro   Tr,   N)r.   "AddDatabasesFilterFlagForSqlServerr   rr   s     r   *AddMigrationJobObjectsConfigFlagForPromotery   m  s)    %%) &  %%56r   c                 P    U R                  SSS9n[        U5        [        U5        grv   )r.   rw   #AddObjectFilterFlagForHeterogeneousrx   s     r   *AddMigrationJobObjectsConfigFlagForRestartr|   v  s2    %%) &  %%56%&67r   c                 P    SnU R                  SS[        R                  " SS9US9  g)3Adds a --databases-filter flag to the given parser.z    A list of databases to be migrated to the destination instance.
    Provide databases as a comma separated list. This flag is used only for
    Postgres to AlloyDB migrations and Postgres to Cloud SQL Postgres migrations.
    --databases-filterr`   ra   rb   r5   Nrd   r   s     r   rp   rp     5    )
 	!,	  r   c                 *    SnU R                  SSUS9  g)z.Adds --all-databases flag to the given parser.z    Migrate all databases for the migration job. This flag is used only for
    Postgres to AlloyDB migrations and Postgres to Cloud SQL Postgres migrations.
    z--all-databasesr   r   Nr   r   s     r   rq   rq     s!    ) 	'9Mr   c                 P    SnU R                  SS[        R                  " SS9US9  g)r~   z    A list of databases to be migrated to the destination instance.
    Provide databases as a comma separated list. This flag is used only for
    SQL Server to Cloud SQL SQL Server migrations.
    r   r`   ra   rb   r5   Nrd   r   s     r   rw   rw     r   r   c                 n    SnU R                  S[        R                  " [        [        S.SS/S9SUSS	9  g
)z0Adds a --object-filter flag to the given parser.z    A list of schema and table names to be migrated to the destination instance.
    Usage: --object-filter schema=schema1,table=table1 --object-filter schema=schema2,table=table2
    This flag is used only for heterogeneous migrations.
    z--object-filter)schematabler   r   )specrequired_keysappendT)r7   r   r   r^   N)r   r   r8   strr   s     r   r{   r{     sO    )
 	 "7+   r   c                 *    SnU R                  SSUS9  g)z?Adds a --sqlserver-promote-when-ready flag to the given parser.z      Promote the database when it is ready. Use --sqlserver-promote-when-ready
      to enable and --no-sqlserver-promote-when-ready to disable. This flag is
      used only for homogeneous SQL Server to Cloud SQL for SQL Server
      migrations.
    z--sqlserver-promote-when-readyr   r   Nr   r   s     r   rZ   rZ     s'    ) 	&  r   c                 *    SnU R                  SSUS9  g)z9Adds a --restart-failed-objects flag to the given parser.z    Restart the failed objects in the migration job. This flag is used only for
    Postgres to AlloyDB migrations and Postgres to Cloud SQL Postgres migrations.
    z--restart-failed-objectsr   r   Nr   r   s     r   AddRestartFailedObjectsFlagr     s'    ) 	   r   c                 R    U R                  S5      n[        X!5        [        U5        g)z<Adds heterogeneous migration flag group to the given parser.zThe heterogeneous migration config. This is used only for Oracle to Cloud SQL for PostgreSQL and SQL Server to Cloud SQL for PostgreSQL migrations.N)r.   *AddHeterogeneousMigrationSourceConfigFlags/AddHeterogeneousMigrationDestinationConfigFlags)r   rQ   heterogeneous_migration_configs      r   #AddHeterogeneousMigrationConfigFlagr     s2    #)#3#3$$  -$ 2$r   c           	          U R                  S5      nUR                  SS[        S9  UR                  SS[        R                  " SSS	9S9  g
)zCAdds heterogeneous migration destination config flag to the parser.zIConfiguration for Postgres as a destination in a heterogeneous migration.z(--max-concurrent-destination-connectionsz        Maximum number of concurrent connections Database Migration Service will
        open to the destination for data migration.
        r   r7   z--transaction-timeoutz(Timeout for data migration transactions.30s300s)lower_boundupper_boundN)r.   r   r:   r   Duration)r   destination_configs     r   r   r     se    '' !!0  "  !!9EvF " r   c                 8   U R                  S5      nUR                  SS[        S9  UR                  SS[        S9  U(       dX  UR                  S5      nUR                  SS	S
S9  UR                  SSS9nUR                  SS[        S9  UR                  SSS9  gg)zDAdds heterogeneous migration source config flag group to the parser.zPConfiguration for Oracle or SQL Server as a source in a heterogeneous migration.z&--max-concurrent-full-dump-connectionsz~        Maximum number of connections Database Migration Service will open to
        the source for full dump phase.
        r   z --max-concurrent-cdc-connectionszx        Maximum number of connections Database Migration Service will open to
        the source for CDC phase.
        z%Configuration for skipping full dump.z--skip-full-dumpz6          Whether to skip full dump or not.
          r   )r   r   z%Configuration for CDC start position.Tr,   z--oracle-cdc-start-positionzX          Oracle schema change number (SCN) to start CDC data migration from.
          z--sqlserver-cdc-start-positionzY          Sqlserver log squence number (LSN) to start CDC data migration from.
          r#   N)r.   r   r:   )r   rQ   source_configskip_full_dump_groupcdc_start_position_groups        r   r   r     s    ""&- .    (    
(22/ %%  &   4==/  >   ))%  *  ))( * - 
r   )F)N)T)*r   
__future__r   r   r   enumgooglecloudsdk.callioper   uniqueEnumr   r!   r$   r*   r2   r/   r0   r>   r@   rB   rI   rM   rS   rO   rV   rW   rX   rY   rP   rl   rt   ry   r|   rp   rq   rw   r{   rZ   r   r   r   r   r   r   r   <module>r      s    A &  '  / dii  I85
7t25PFOD>(" F4	'78N,
".3r   