
                         n    d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ  G d	 d
e      Zy))Base class for gkemulticloud API clients.    )absolute_import)division)unicode_literalsN)
list_pager)util)flagsc                   j    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd ZddZd Z	 	 	 ddZd Zy)
ClientBaser   Nc                     t        j                         | _        t        j                         | _        || _        || _        y )N)r   GetClientInstance_clientGetMessagesModule	_messages_service_list_result_field)selfservicelist_result_fields      <lib/googlecloudsdk/api_lib/container/gkemulticloud/client.py__init__zClientBase.__init__   s1    ))+DL++-DNDM/D    c                     dt        j                  |      i}t        |j                               r | j                  j
                  di |S d S )Nproject )r	   GetFleetProjectanyvaluesr   GoogleCloudGkemulticloudV1Fleetr   argskwargss      r   _FleetzClientBase._Fleet%   sQ    5((.F
 v}} 	766@@ r   c                     dt        j                  |      i}t        |j                               r | j                  j
                  di |S d S )NmaxPodsPerNoder   )r	   GetMaxPodsPerNoder   r   r   +GoogleCloudGkemulticloudV1MaxPodsConstraintr    s      r   _MaxPodsConstraintzClientBase._MaxPodsConstraint/   sP     7 7 =>F v}} 	CBBLVL r   c           
          t        j                  |      }|sy |j                  j                  }|j                  |j	                         D cg c]  \  }} |||       c}}      S c c}}w NkeyvalueadditionalProperties)r	   GetNodeLabelsLabelsValueAdditionalPropertyitems)r   r!   parent_typelabels
label_typekvs          r   _LabelszClientBase._Labels7   sn      &F((;;J""39<<>
3A41aJ1A&>
 #  
   A*
c           
          t        j                  |      }|sy |j                  j                  }|j                  |j	                         D cg c]  \  }} |||       c}}      S c c}}w r*   )r	   GetTags	TagsValuer2   r3   )r   r!   r4   tagstag_typer7   r8   s          r   _TagszClientBase._TagsB   se    ==D$$77H  CG::<P<41ah1A6<P !  Pr:   c           
          t        j                  |      }|sy|j                  j                  }|j                  |j	                         D cg c]  \  }} |||       c}}      S c c}}w )zParses the annotations from the args.

    Args:
      args: Arguments to be parsed.
      parent_type: Type of the parent object.

    Returns:
      Returns the parsed annotations.
    Nr+   r.   )r	   GetAnnotationsAnnotationsValuer2   r3   )r   r!   r4   annotationsannotation_typer7   r8   s          r   _AnnotationszClientBase._AnnotationsK   st     &&t,K!22EEO''8C8I8I8K
8K1O+8K
 (  
r:   c           
          t        j                  |      }|sy|j                  j                  }|j                  |j	                         D cg c]  \  }} |||       c}}      S c c}}w )zParses the tag bindings from the args.

    Args:
      args: Arguments to be parsed.
      parent_type: Type of the parent object.

    Returns:
      Returns the parsed tag bindings.
    Nr+   r.   )r	   GetTagBindingsr=   r2   r3   )r   r!   r4   tag_bindingstag_binding_typer7   r8   s          r   _TagBindingszClientBase._TagBindings_   sv     ''-L",,??  9E9K9K9M
9MA!,9M
 !  
r:   c                 j    t        j                  |      }|sy | j                  j                  |      S )N)evaluationMode)r	   GetBinauthzEvaluationModer   -GoogleCloudGkemulticloudV1BinaryAuthorization)r   r!   evaluation_modes      r   _BinaryAuthorizationzClientBase._BinaryAuthorizations   s8    55d;O>>GG& H  r   c                 j    t        j                  |      }|sy | j                  j                  |      S )N)vulnerabilityMode)r	    GetWorkloadVulnerabilityScanningr   /GoogleCloudGkemulticloudV1SecurityPostureConfig)r   r!   vulnerability_modes      r   _SecurityPosturezClientBase._SecurityPosture{   s9    ??E>>II, J  r   c                 X   ||j                         i} | j                  j                  d      di |}| j                  dd}|r||d<   |r||d<   t	        j
                  | j                  |fi |}	 t        |      }t        j                  |g|      }|dfS # t        $ r |dfcY S w xY w)	av  Lists gkemulticloud API resources.

    Args:
      parent_ref: Reference to the parent field to list resources.
      page_size: Page size for listing resources.
      limit: Limit for listing resources.
      parent_field: Name of the parent field.

    Returns:
      iterator: List of resources returned from the server.
      bool: True if empty. False, otherwise.
    ListpageSize)fieldbatch_size_attributelimit
batch_sizeFTr   )
RelativeNamer   GetRequestTyper   r   YieldFromListnext	itertoolschainStopIteration)	r   
parent_ref	page_sizer]   parent_fieldr"   reqr3   
first_items	            r   rY   zClientBase.List   s     J3356F
.$--
&
&v
.
8
8C(( *F fWo&f\$$T]]CB6BE;joozlE2eE\ D[s   3%B B)(B)c                      | j                   j                  d      |j                               }| j                   j                  |      S )z"Gets a gkemulticloud API resource.Getname)r   r`   r_   rl   )r   resource_refri   s      r   rl   zClientBase.Get   s;    
-$--
&
&u
-<3L3L3N
OC==S!!r   c                      | j                   j                  d      |j                               }|rd|_        |rd|_        |rd|_        | j                   j                  |      S )z%Deletes a gkemulticloud API resource.Deleterm   T)r   r`   r_   validateOnlyallowMissingignoreErrorsrq   )r   ro   validate_onlyallow_missingignore_errorsri   s         r   rq   zClientBase.Delete   sc     1$--
&
&x
0&&(C ccc==$$r   c                      | j                   j                  d      |j                         d      }| j                   j                  |      }t	        || j
                  d      }|rdS dS )z&Checks if the cluster has a node pool.rY      )parentrZ   NTF)r   r`   r_   rY   getattrr   )r   cluster_refri   res
node_poolss        r   HasNodePoolszClientBase.HasNodePools   sb    
.$--
&
&v
.'')AC --

S
!Cd55t<J4(5(r   )NN)NNrz   )NNN)__name__
__module____qualname____doc__r   r#   r(   r9   r@   rF   rK   rQ   rW   rY   rl   rq   r   r   r   r   r   r      sQ    10	((>" %&)r   r   )r   
__future__r   r   r   rc   apitools.base.pyr   .googlecloudsdk.api_lib.container.gkemulticloudr   2googlecloudsdk.command_lib.container.gkemulticloudr	   objectr   r   r   r   <module>r      s-    0 &  '  ' ? De) e)r   