
    G                     8   d Z ddlZddlmZmZ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d      Z e	j*                  e	j,                  j.                        e	j0                   G d dej2                  e	j4                                      Zy)zACommand to create conversion workspaces for a database migration.    N)OptionalTypeTypeVar)resource_args)base)
exceptions)command_mixin)flags)labels_util)datamigration_v1_messagesGlobalSettingsValuec                       e Zd ZdZdddZedej                  ddfd       Zd	ej                  de
ej                     fd
Zd	ej                  ddfdZd	ej                  dee   defdZy)Createz9Create a Database Migration Service conversion workspace.zI
        Create a Database Migration Service conversion workspace.
      aM          To create a conversion workspace:

            $ {command} my-conversion-workspace --region=us-central1
            --display-name=cw1
            --source-database-engine=ORACLE
            --source-database-version=11
            --destination-database-engine=POSTGRESQL
            --destination-database-version=15
      )DESCRIPTIONEXAMPLESparserreturnNc                 ,   t        j                  | d       t        j                  |        t        j                  |        t        j
                  |        t        j                  |        t        j                  |        t        j                  |        y)zArgs 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.
    z	to createN)	r   !AddConversionWorkspaceResourceArgcw_flagsAddNoAsyncFlagAddDisplayNameFlagAddDatabaseEngineFlagsAddDatabaseProviderFlagsAddDatabaseVersionFlagAddGlobalSettingsFlag)r   s    >lib/surface/database_migration/conversion_workspaces/create.pyArgszCreate.Args4   sh     33FKHF#'##F+%%f-##F+""6*    argsc                 p   | j                  |       |j                  j                  j                         }| j                  j
                  j                  |j                         j                         |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                   | j#                  || j                  j
                  j$                  j&                  j(                        
      }| j+                  ||d|j-                  d            S )a.  Create a Database Migration Service conversion workspace.

    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.
    )r    global_settings_value_cls)

parent_refconversion_workspace_iddisplay_namesource_database_providersource_database_enginesource_database_versiondestination_database_providerdestination_database_enginedestination_database_versionglobal_settingsCreatedno_async)conversion_workspace_refresult_operationoperation_namesync)_ValidateEngineProviderFlagsCONCEPTSconversion_workspaceParseclientcrudr   ParentRelativeNameconversionWorkspacesIdr%   r&   r'   r(   r)   r*   r+   _BuildGlobalSettingsmessagesConversionWorkspacer   HandleOperationResultIsKnownAndSpecified)selfr    r/   r0   s       r   Runz
Create.RunD   s    	%%d+#}}AAGGI{{''..+224AAC 8 O O&&!%!>!>#:: $ < <&*&H&H$($D$D%)%F%F11&*kk&6&6&?&?&S&S&g&g 2 
 /   %%!9) %%j1	 &  r   c                     |j                   |j                  j                  vret        j                  dd|j                   d|j                    ddj                  t        t        |j                  j                               d      |j                  |j                  j                  vret        j                  dd|j                   d	|j                   ddj                  t        t        |j                  j                               d      y
)z(Validates the engine and provider flags.z4--source_database_engine, --source_database_providerzSource database engine z2 is not supported by the source database provider z.
Supported providers are: z, .z>--destination_database_engine, --destination_database_providerzDestination database engine z7 is not supported by the destination database provider N)
r&   r'   supported_providersr   InvalidArgumentExceptionjoinmapstrr)   r*   )rA   r    s     r   r3   z#Create._ValidateEngineProviderFlagsj   s    	%%**>>	? //
@#D$?$?#@ A++, -iiC!<!<!P!PQRSSTV  	**//CC	D //
J()I)I(J K001 2iiC!A!A!U!UVWXXY[ 	Dr   r"   c                     |j                   i |_         |j                   j                  dd       t        j                  ||d      S )a'  Builds the global settings for the conversion workspace.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.
      global_settings_value_cls: The class to use for the global settings value.

    Returns:
      A global settings value object.
    *true)filterv2r,   )r    
labels_clslabels_dest)r,   updater   ParseCreateArgs)rA   r    r"   s      r   r<   zCreate._BuildGlobalSettings   sM     #dsv6&&,% r   )__name__
__module____qualname____doc__detailed_helpstaticmethodargparseArgumentParserr   	Namespacer   r=   	OperationrB   r3   r   r   r<    r   r   r   r      s     B
	
	-  +8** +t + +$h(( $Xh6H6H-I $Lx/A/A d 4 "&&9!: 	r   r   )rV   rY   typingr   r   r   )googlecloudsdk.api_lib.database_migrationr   googlecloudsdk.callioper   r   Cgooglecloudsdk.command_lib.database_migration.conversion_workspacesr	   r
   r   $googlecloudsdk.command_lib.util.argsr   6googlecloudsdk.generated_clients.apis.datamigration.v1r   r=   r   ReleaseTracksReleaseTrackGADefaultUniverseOnly ConversionWorkspacesCommandMixinCommandr   r]   r   r   <module>rj      s    H  * * C ( . ] a < h34  D%%(()y];;T\\ y  *yr   