
                            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
 Z G d de      Z G d de      Z e	j$                  e	j&                  j(                         G d dee	j*                               Z e	j$                  e	j&                  j.                         G d dee	j*                               Zy)z2Implementation of connection profile list command.    )absolute_import)division)unicode_literals)connection_profiles)resource_args)base)concept_parsers)
propertiesc                 ^    t        j                  |       j                  |j                        S )z/Gets the resource URI for a connection profile.)r   ConnectionProfilesClientGetUriname)release_trackconnection_profile_infos     :lib/surface/database_migration/connection_profiles/list.py_GetUrir      s+     
	5	5m	D	K	K""
$ $    c                       e Zd ZdZd Zy)_ConnectionProfileInfoz<Container for connection profile data using in list display.c                 L   |j                   | _        |j                  | _        |j                  | _        |j                  | _        || _        |j                  | _        || _	        |j                  r5|j                  sd| _        dj                  | j
                  d      | _        y y )NCLOUDSQLz{}_{}REPLICA)displayNamedisplay_namer   stateproviderprovider_displayhost
createTimecreate_timeenginecloudsqlformat)selfmessager   r!   s       r   __init__z_ConnectionProfileInfo.__init__&   s    ++DDIDJ#,,DDI))DDK *%nnT-B-BINd r   N)__name__
__module____qualname____doc__r&    r   r   r   r   #   s    DOr   r   c                   &    e Zd ZdZed        Zd Zy)_ListzFBase class for listing Database Migration Service connection profiles.c                      t         j                  j                  dt        j                         d      j                  |       |j                  j                  d       |j                  j                   fd       y)z Register flags for this command.z--regionz:The location you want to list the connection profiles for.)
group_helpa[  
          table(
            name.basename():label=CONNECTION_PROFILE_ID,
            display_name,
            name.scope('locations').segment(0):label=REGION,
            state,
            provider_display:label=PROVIDER,
            engine,
            host:label=HOSTNAME/IP,
            create_time.date():label=CREATED
          )
        c                 8    t        j                         |       S N)r   ReleaseTrack)pclss    r   <lambda>z_List.Args.<locals>.<lambda>P   s    WS5E5E5G-Kr   N)	r	   ConceptParserForResourcer   GetRegionResourceSpecAddToParserdisplay_info	AddFormat
AddUriFunc)r4   parsers   ` r   Argsz
_List.Args:   sl     !!--++-O .  k&
!! #  ""#KLr   c           
         t        j                  | j                               }t        j                  j
                  j                  j                  d      }|j                  ||      }|j                  |j                  j                  d      r9|D cg c]-  }t        || j                  |      |j                  |            / c}S |S c c}w )zRuns the command.

    Args:
      args: All the arguments that were provided to this command invocation.

    Returns:
      An iterator over objects containing connection profile data.
    T)requiredz"table)r   r   r2   r
   VALUEScoreprojectGetListr#   
startswithr   _GetHostGetEngineName)r$   args	cp_client
project_idprofilesprofiles         r   Runz	_List.RunR   s     $<<I""''//33T3BJ~~j$/H{{dkk44X> " "g !$--*@!*!8!8!AC! 
 Os   2CN)r'   r(   r)   r*   classmethodr>   rN   r+   r   r   r-   r-   7   s    NM M.r   r-   c                       e Zd ZdZd Zy)	ListAlphaa  List Database Migration Service connection profiles.

  List connection profiles.

  ## API REFERENCE
    This command uses the datamigration/v1alpha2 API. The full documentation
    for this API can be found at: https://cloud.google.com/database-migration/

  ## EXAMPLES
    To list all connection profiles in a project and region ``us-central1'',
    run:

        $ {command} --region=us-central1

    To filter connection profiles with the given state:

        $ {command} --filter="state=READY"
  c                     |j                   r|j                   j                  S |j                  rB|j                  j                  r|j                  j                  S |j                  j                  S y r1   )mysqlr   r"   publicIp	privateIpr$   rM   s     r   rG   zListAlpha._GetHost~   s`    }}]]			!!** '' /##--/ r   Nr'   r(   r)   r*   rG   r+   r   r   rQ   rQ   i   s    &r   rQ   c                       e Zd ZdZd Zy)ListGAa  List Database Migration Service connection profiles.

  List connection profiles.

  ## API REFERENCE
    This command uses the datamigration/v1 API. The full documentation
    for this API can be found at: https://cloud.google.com/database-migration/

  ## EXAMPLES
    To list all connection profiles in a project and region 'us-central1', run:

        $ {command} --region=us-central1

    To filter connection profiles with the given state:

        $ {command} --filter="state=READY"
  c                    |j                   r|j                   j                  S |j                  r|j                  j                  S |j                  rB|j                  j                  r|j                  j                  S |j                  j
                  S |j                  r*|j                  j                  j                  j
                  S |j                  r|j                  j                  S y r1   )
rS   r   
postgresqlr"   rT   rU   alloydbsettingsprimaryInstanceSettingsoraclerV   s     r   rG   zListGA._GetHost   s    }}]]			$$$			!!** '' /##--/ 
__%%==GGG	^^   r   NrW   r+   r   r   rY   rY      s    $r   rY   N)r*   
__future__r   r   r   )googlecloudsdk.api_lib.database_migrationr   r   googlecloudsdk.callioper   (googlecloudsdk.command_lib.util.conceptsr	   googlecloudsdk.corer
   r   objectr   r-   ReleaseTracksr2   ALPHAListCommandrQ   GArY   r+   r   r   <module>rj      s    9 &  ' I C ( D *$OV O(/F /d D%%++,t''  -> D%%(()"UD$$ " *"r   