
                         0   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dlmZ dddZ ej&                  ej(                  j*                        ej,                   G d dej.                                      Zy)z?Command to create connection profiles for a database migration.    )absolute_import)division)unicode_literals)resource_args)base)
exceptions)flags)create_helper)sqlserver_flags)
console_ioFCreate a Database Migration Service connection profile for SQL Server.a          To create a source connection profile my-source-profile for SQL Server:

            $ {command} my-source-profile --region=us-central1
            --gcs-bucket=bucket-name --gcs-prefix=prefix/path

        To create a destination connection profile my-dest-profile for SQL
        Server:

            $ {command} my-dest-profile --region=us-central1
            --cloudsql-instance=cloudsql-id
        )DESCRIPTIONEXAMPLESc                   H    e Zd ZdZeZed        Zd Zd Z	d Z
d Zd Zd Zy	)

_SQLServerr   c                    t        j                  | d       t        j                  |        t        j                  |        t        j
                  |        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   (AddSqlServerConnectionProfileResourceArgcp_flagsAddNoAsyncFlagAddDisplayNameFlagAddRoleFlag%AddSslServerOnlyOrRequiredConfigGroupAddSslFlagsr   AddCloudSqlInstanceFlagsAddCpDetailsFlagAddDatabaseFlagr	   AddLabelsCreateFlags)parsers    Flib/surface/database_migration/connection_profiles/create/sqlserver.pyArgsz_SQLServer.Args8   s     ::6;OF#' 226: ,,V4$$V,V$	v&    c                 b   | j                  |       |j                  j                  j                         }|j	                         j                         }|j                  rt        j                  d      |_	        t        j                         }|j                  | j                         |||d      S )a,  Create a Database Migration Service connection profile.

    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.
    zPlease Enter Password: 	SQLSERVER)_ValidateArgsCONCEPTSconnection_profileParseParentRelativeNameprompt_for_passwordr   PromptPasswordpasswordr
   CreateHelpercreateReleaseTrack)selfargsconnection_profile_ref
parent_refhelpers        r   Runz_SQLServer.RunL   s     	t!]]==CCE'..0==?J //0IJdm'')F== r!   c                 H    | j                  |       | j                  |       y)z(Validates the arguments for the command.N)_ValidateHeterogeneousOrDagArgs$_ValidateHomeogeneousDestinationArgsr0   r1   s     r   r$   z_SQLServer._ValidateArgsg   s    ((.--d3r!   c                 l    |j                  d      r| j                  |       y | j                  |       y )Ndbm_port)IsKnownAndSpecified_ValidateDagArgs_ValidateHeterogeneousArgsr9   s     r   r7   z*_SQLServer._ValidateHeterogeneousOrDagArgsl   s,    
+
D!
%%d+r!   c                 L   |j                  d      r|j                  t        j                  dd      |j                  t        j                  dd      |j                  d      rt        j                  dd	      |j                  d
      rt        j                  dd      yy)zEValidates the arguments for heterogeneous source connection profiles.hostN
--usernamez'Username must be specified with --host.z
--passwordz'Password must be specified with --host.cloudsql_instance--cloudsql-instancez/Cloud SQL instance can not be used with --host.cloudsql_project_id--cloudsql-project-idz1Cloud SQL project ID can not be used with --host.)r<   usernamer   BadArgumentExceptionr,   r9   s     r   r>   z%_SQLServer._ValidateHeterogeneousArgsr   s    '		--5
 	
 
	--5
 	
 
	!	!"5	6--!=
 	
 
	!	!"7	8--#?
 	
 
9! (r!   c                    |j                  d      st        j                  dd      |j                  t        j                  dd      |j                  d      s6|j                  d      r%|j                  dk(  rt        j                  d	d
      |j                  d      rt        j                  dd      |j                  d      rt        j                  dd      y)zKValidates the arguments for DAG HMM source/destination connection profiles.rolez--rolez'Role must be specified with --dbm-port.NrA   z+Username must be specified with --dbm-port.rB   DESTINATIONrC   zLCloud SQL instance must be specified with --dbm-port and --role=DESTINATION.rD   rE   z5Cloud SQL project ID can not be used with --dbm-port.databasez
--databasez)Database can not be used with --dbm-port.)r<   r   rG   rF   rI   r9   s     r   r=   z_SQLServer._ValidateDagArgs   s    ##F+++

3  }}++

7 
 $$%89$$V,II&++
! 
  56++
!
A  
+++

5  ,r!   c                     |j                  d      sl|j                  d      rZ|j                  dk(  rJ|j                  t        j                  dd      |j                  d      rt        j                  dd	      yyyy)
zIValidates the arguments for homeogeneous destination connection profiles.r@   rI   rJ   NrC   z=Cloud SQL instance must be specified with --role=DESTINATION.
gcs_bucketz--gcs-bucketz3GCS bucket can not be used with --role=DESTINATION.)r<   rI   rB   r   rG   r9   s     r   r8   z/_SQLServer._ValidateHomeogeneousDestinationArgs   s     $$V,$$V,II&				'--!K
 	
 
	!	!,	/--A
 	
 
0 ' - -r!   N)__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr    r5   r$   r7   r>   r=   r8    r!   r   r   r   1   s>     O-' '&64
,
0B
r!   r   N)rQ   
__future__r   r   r   )googlecloudsdk.api_lib.database_migrationr   googlecloudsdk.callioper   r   -googlecloudsdk.command_lib.database_migrationr	   Agooglecloudsdk.command_lib.database_migration.connection_profilesr
   r   r   googlecloudsdk.core.consoler   rR   ReleaseTracksr/   GADefaultUniverseOnlyCommandr   rU   r!   r   <module>r`      s    F &  ' C ( . ? [ _ ] 2 	Q	& D%%(()H
 H
  *H
r!   