
                             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 ej"                   G d dej$                               Zy)z5Command to show fleets in an organization or project.    )absolute_import)division)unicode_literals)projects_api)client)base)util)log)
propertiesc                   ,    e Zd ZdZed        Zd Zd Zy)ListaK  List fleets visible to the user in an organization.

  This command can fail for the following reasons:
  * The org or project specified does not exist.
  * The user does not have access to the project specified.

  ## EXAMPLES

  The following command lists fleets in organization `12345`:

    $ {command} --organization=12345
  c                     t        j                  dddt         j                        }|j                  |        | j                  j                  t        j                         y )Nz--organizationORGANIZATION_IDzID (number) for the organization to list fleets from. If neither --organization nor --project are provided, defaults to the organization of the active project.)metavarhelpcategory)r   ArgumentCOMMONLY_USED_FLAGSAddToParserdisplay_info	AddFormatr	   LIST_FORMAT)parserorgflags     #lib/surface/container/fleet/list.pyArgsz	List.Args-   sR     mm! ))+G 
!!$"2"23    c                    t        j                          t        j                  | j	                               }|j
                  }|2t        j                  j                  j
                  j                         }|j                  }||j
                  | j                  |      }||n|}|dnd}t        j                  j                  dj                  ||             |j!                  ||      S )NorganizationprojectzListing fleets from {0} {1}:)r   EnableUserProjectQuotar   FleetClientReleaseTrackr    r   VALUEScoreGetr   GetOrgr
   statusPrintformat
ListFleets)selfargsfleetclientr    orgparent
parenttypes          r   RunzList.Run;   s    !$$T%6%6%89KllG!!&&..224g


C
{t||+KK cOSF#&?	JJJ3:::vNO!!'3//r   c                     t        j                  |      }|j                  D ]C  }|j                  j                  }|j                  j
                  }|dk(  r	 |dk(  r	 |dk(  sA|c S  y )N)
project_idr    folderr   )crmGetAncestryancestor
resourceIdtypeid)r,   r    ancestryresourceresource_typeresource_ids         r   r'   zList.GetOrgJ   sf    '2H%%))..m''**k	)	#	(	"	.	( &r   N)__name__
__module____qualname____doc__staticmethodr   r2   r'    r   r   r   r      s%     4 40r   r   N)rC   
__future__r   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   r6   &googlecloudsdk.api_lib.container.fleetr   googlecloudsdk.callioper   *googlecloudsdk.command_lib.container.fleetr	   googlecloudsdk.corer
   r   DefaultUniverseOnlyListCommandr   rE   r   r   <module>rN      sL     < &  ' K 9 ( ; # * 64 6 6r   