
                             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  G d de      Zy)z+Base command class for Hub gcloud commands.    )absolute_import)division)unicode_literals)encoding)client)util)waiter)log)
propertiesc                       e Zd ZdZed        Zed        Zed        Zed        Ze	dd       Z
e	dd       Ze		 	 	 dd	       Ze	dd
       Ze		 	 	 dd       Ze	dd       Ze	dd       ZddZy)
HubCommandz:HubCommand is a mixin adding common utils to Hub commands.c                     t        | d      s(t        j                  | j                               | _        | j                  S ),The HubClient for the current release track._client)hasattrr   	HubClientReleaseTrackr   selfs    6lib/googlecloudsdk/command_lib/container/fleet/base.py	hubclientzHubCommand.hubclient!   s3     4#%%d&7&7&9:dl<<    c                     t        | d      s(t        j                  | j                               | _        | j                  S )r   
_client_v2)r   r   HubV2Clientr   r   r   s    r   hubclient_v2zHubCommand.hubclient_v2)   s3     4&**4+<+<+>?do??r   c                 .    | j                   j                  S )z,Convenience property for hubclient.messages.)r   messagesr   s    r   r   zHubCommand.messages1   s     >>"""r   c                 .    | j                   j                  S )z/Convenience property for hubclient_v2.messages.)r   r   r   s    r   messages_v2zHubCommand.messages_v26   s     %%%r   c                     t         j                  j                  j                  j	                         }| rt        j                  |      S |S )zSimple helper for getting the current project.

    Args:
      number: Boolean, whether to return the project number instead of the ID.

    Returns:
      The project ID or project number, as a string.
    )r   VALUEScoreproject	GetOrFailproject_utilGetProjectNumber)numberr$   s     r   ProjectzHubCommand.Project;   s=     $$,,668G**733Nr   c                 V    t        j                  t        j                  |      |       S )Nlocation)r   LocationResourceNamer   r)   )r,   
use_numbers     r   r-   zHubCommand.LocationResourceNameJ   s%    $$:&; ;r   Nc                 d    |xs t         j                  |      }t        j                  || |      S )z[Builds the full resource name, using the core project property if no project is specified..r+   )r   r)   r   FeatureResourceName)namer$   r,   r.   s       r   r0   zHubCommand.FeatureResourceNameO   s.     7++J7G##GTHEEr   c                 X    t        j                  t        j                  |      | |      S )z?Builds a full Membership name, using the core project property.r+   )r   MembershipResourceNamer   r)   r1   r,   r.   s      r   r3   z!HubCommand.MembershipResourceNameX   s+     &&:&xA Ar   c                 f    |xs t         j                  |      }t        j                  || ||      S )zdBuilds the full MembershipFeature name, using the core project property if no project is specified..r+   )r   r)   r   MembershipFeatureResourceName)membership_namefeature_namer$   r,   r.   s        r   r6   z(HubCommand.MembershipFeatureResourceName^   s8     7++J7G--	 r   c                 X    t        j                  t        j                  |      | |      S )z>Builds a full Workspace name, using the core project property.r+   )r   WorkspaceResourceNamer   r)   r4   s      r   r:   z HubCommand.WorkspaceResourceNameo   s+     %%:&xA Ar   c                 X    t        j                  t        j                  |      | |      S )z:Builds a full Scope name, using the core project property.r+   )r   ScopeResourceNamer   r)   r4   s      r   r<   zHubCommand.ScopeResourceNameu   s+     !!:&xA Ar   c                 
   | j                   j                  |      }t        j                  ||fd|i|}|rL|j	                  |      }t        j                  |j                        }	d|	v rt        j                  |	d          |S )zBHelper wrapping waiter.WaitFor() with additional warning handling.messagestatusDetail)
r   OperationRefr	   WaitForPollr   MessageToPyValuemetadatar
   warning)
r   polleropr>   warningskwargsop_refresultfinal_opmetadata_dicts
             r   WaitForHubOpzHubCommand.WaitForHubOp{   su    ^^((,F^^FFFGFvFFV$h//0A0ABm	=	(M.12Mr   )F)globalF)NrO   F)NT)__name__
__module____qualname____doc__propertyr   r   r   r    staticmethodr)   r-   r0   r3   r6   r:   r<   rN    r   r   r   r      s    B    # # & &   ; ; "&#+%*F F A A
     A A
 A A
	r   r   N)rS   
__future__r   r   r   apitools.base.pyr   &googlecloudsdk.api_lib.container.fleetr   r   googlecloudsdk.api_lib.utilr	   #googlecloudsdk.command_lib.projectsr&   googlecloudsdk.corer
   r   objectr   rV   r   r   <module>r^      s6    2 &  ' % 9 7 . D # *f fr   