
    W0                         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
 dd	lmZ dd
lmZ ddlZ G d de      Zy)z7Base class for Anthos GKE On-Prem API client resources.    )absolute_import)division)unicode_literalsN)apis)arg_parsers)parser_extensions)gkeonprem_v1_client)gkeonprem_v1_messagesc                      e Zd ZdZd&dZdej                  fdZd&dej                  fdZ
d Zd	 Zdej                  fd
Zdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZdej                  fdZd Zdej                  fdZdej                  fdZdej                  fdZ dej                  fdZ!dej                  fdZ"dej                  fd Z#dej                  fd!Z$dej                  ddfd"Z%dej                  fd#Z&dej                  fd$Z'dej                  fd%Z(y)'
ClientBasez.Base class for Anthos GKE On-Prem API clients.Nc                 <    | j                         | _        || _        y N)_get_client_instance_client_service)selfservices     8lib/googlecloudsdk/api_lib/container/gkeonprem/client.py__init__zClientBase.__init__#   s    ,,.DLDM    returnc                 .    t        j                  dd      S )zReturns the client instance.

    Function created for IDE type hint only, inline type annotation is not
    supported due to gcloud using a low Python3 version.
    	gkeonpremv1)r   GetClientInstance)r   s    r   r   zClientBase._get_client_instance'   s     !!+t44r   argsc                 B    ||j                         v rt        ||      S |S )a  Returns the flag value if it's set, otherwise returns None.

    Args:
      args: An argparser Namespace class instance.
      flag: A string type flag name.
      default: The default value to return if not found in the argparser
        namespace.

    Returns:
      The flag value if it is set by the user. If the flag is not added to the
      interface, or it is added by not specified by the user, returns the
      default value.
    )GetSpecifiedArgsDictgetattr)r   r   flagdefaults       r   GetFlagzClientBase.GetFlag/   s'     t((**T4  nr   c                 Z    |j                         D ]  }t        |t              r y|s y y)a  Returns True if any of the kwargs is set to not None value.

    The added condition handles the case when user specified boolean False
    for the given args, and it should return True, which does not work with
    normal Python identity comparison.

    Args:
      kwargs: dict, a mapping from proto field to its respective constructor
        function.

    Returns:
      True if there exists a field that contains a user specified argument.
    TF)values
isinstancebool)r   kwargsvalues      r   IsSetzClientBase.IsSetB   s,     	E4	 	 !
 r   c                      | j                   j                  d      |j                               }| j                   j                  |      S )zGets a gkeonprem API resource.Get)name)r   GetRequestTypeRelativeNamer+   )r   resource_refreqs      r   DescribezClientBase.DescribeW   s;    
-$--
&
&u
-<3L3L3N
OC==S!!r   c                 z    t        |j                  dd      r$|j                  j                  j                         S y)z@Parses user cluster resource argument and returns its reference.clusterN)r   CONCEPTSr3   Parser   r   s     r   _user_cluster_refzClientBase._user_cluster_ref\   s.    t}}i.]]""((**r   c                 z    t        |j                  dd      r$|j                  j                  j                         S y)AParses admin cluster resource argument and returns its reference.admin_clusterN)r   r4   r:   r5   r6   s     r   _admin_cluster_refzClientBase._admin_cluster_refb   s.    t}}ot4]]((..00r   c                 z    t        |j                  dd      r$|j                  j                  j                         S y)z<Parses location resource argument and returns its reference.locationN)r   r4   r=   r5   r6   s     r   _location_refzClientBase._location_refh   s.    t}}j$/]]##))++r   c                 J    | j                  |      }|r|j                         S y)z/Parses location from args and returns its name.N)r>   r.   )r   r   location_refs      r   _location_namezClientBase._location_namen   s'    %%d+L&&((r   c                 J    | j                  |      }|r|j                         S y)z3Parses user cluster from args and returns its name.N)r7   r.   r   r   user_cluster_refs      r   _user_cluster_namezClientBase._user_cluster_nameu   s(    --d3**,,r   c                 f    | j                  |      }|r|j                         j                         S y)z:Parses user cluster from args and returns its parent name.N)r7   Parentr.   rC   s      r   _user_cluster_parentzClientBase._user_cluster_parent|   s1    --d3$$&3355r   c                 J    | j                  |      }|r|j                         S y)z1Parses user cluster from args and returns its ID.N)r7   NamerC   s      r   _user_cluster_idzClientBase._user_cluster_id   s(    --d3""$$r   c                 J    | j                  |      }|r|j                         S yz4Parses admin cluster from args and returns its name.N)r;   r.   r   r   admin_cluster_refs      r   _admin_cluster_namezClientBase._admin_cluster_name   s(    //5++--r   c                 f    | j                  |      }|r|j                         j                         S y)z;Parses admin cluster from args and returns its parent name.N)r;   rG   r.   rN   s      r   _admin_cluster_parentz ClientBase._admin_cluster_parent   s1    //5%%'4466r   c                 J    | j                  |      }|r|j                         S y)z2Parses admin cluster from args and returns its ID.N)r;   rJ   rN   s      r   _admin_cluster_idzClientBase._admin_cluster_id   s(    //5##%%r   c                 z    t        |j                  dd      r$|j                  j                  j                         S y)r9   admin_cluster_membershipN)r   r4   rV   r5   r6   s     r   _admin_cluster_membership_refz(ClientBase._admin_cluster_membership_ref   s/    t}}8$?]]3399;;r   c                 J    | j                  |      }|r|j                         S yrM   )rW   r.   rN   s      r   _admin_cluster_membership_namez)ClientBase._admin_cluster_membership_name   s(    ::4@++--r   c                 z    t        |j                  dd      r$|j                  j                  j                         S yz=Parses node pool resource argument and returns its reference.	node_poolNr   r4   r\   r5   r6   s     r   _node_pool_refzClientBase._node_pool_ref   s.    t}}k40]]$$**,,r   c                 J    | j                  |      }|r|j                         S yz0Parses node pool from args and returns its name.N)r^   r.   r   r   node_pool_refs      r   _node_pool_namezClientBase._node_pool_name   s'    ''-M''))r   c                 J    | j                  |      }|r|j                         S yz.Parses node pool from args and returns its ID.N)r^   rJ   ra   s      r   _node_pool_idzClientBase._node_pool_id   s)    ''-M!! r   c                 f    | j                  |      }|r|j                         j                         S yz7Parses node pool from args and returns its parent name.N)r^   rG   r.   ra   s      r   _node_pool_parentzClientBase._node_pool_parent   s0    ''-M!!#0022r   c                 "   t         j                  j                  }|j                  |j                  |j
                  d}dj                  |      }dj                  d t        |j                               D              }t        j                  d      }|j                  |      }|s$t        j                  dj                  |            |j                         \  }}	}
|
|vr%t        j                  dj                  ||            ||	||
   dS )	a  Validates and parses a node taint object.

    Args:
      node_taint: tuple, of format (TAINT_KEY, value), where value is a string
        of format TAINT_VALUE:EFFECT.

    Returns:
      If taint is valid, returns a dict mapping message NodeTaint to its value;
      otherwise, raise ArgumentTypeError.
      For example,
      {
          'key': TAINT_KEY
          'value': TAINT_VALUE
          'effect': EFFECT
      }
    )
NoSchedulePreferNoSchedule	NoExecute=z, c              3   F   K   | ]  }t        j                  |        y wr   )six	text_type).0keys     r   	<genexpr>z/ClientBase._parse_node_taint.<locals>.<genexpr>   s      )&Isc&Is   !z2([a-zA-Z0-9-_]*)=([a-zA-Z0-9-_]*):([a-zA-Z0-9-_]*)z?Node taint [{}] not in correct format, expect KEY=VALUE:EFFECT.z1Invalid taint effect in [{}] , expect one of [{}])rs   r(   effect)messages	NodeTaintEffectValueValuesEnumNO_SCHEDULEPREFER_NO_SCHEDULE
NO_EXECUTEjoinsortedkeysrecompile	fullmatchr   ArgumentTypeErrorformatgroups)r   
node_tainttaint_effect_enumtaint_effect_mappinginput_node_taintvalid_node_taint_effectstaint_patterntaint_match	taint_keytaint_valuetaint_effects              r   _parse_node_taintzClientBase._parse_node_taint   s    " !**@@'33-@@&11 xx
+#yy )&,-A-F-F-H&I)   JJ=M  ))*:;K))
K6"#  ,7+=+=+?(I{L//))
=
D
D 8  &|4 r   c                 z    t        |j                  dd      r$|j                  j                  j                         S y)FParses standalone cluster resource argument and returns its reference.standalone_clusterN)r   r4   r   r5   r6   s     r   _standalone_cluster_refz"ClientBase._standalone_cluster_ref   s/    t}}2D9]]--3355r   c                 J    | j                  |      }|r|j                         S yz9Parses standalone cluster from args and returns its name.N)r   r.   r   r   standalone_cluster_refs      r   _standalone_cluster_namez#ClientBase._standalone_cluster_name   s(    !99$?#0022r   c                 f    | j                  |      }|r|j                         j                         S y)z@Parses standalone cluster from args and returns its parent name.N)r   rG   r.   r   s      r   _standalone_cluster_parentz%ClientBase._standalone_cluster_parent  s1    !99$?#**,99;;r   c                 J    | j                  |      }|r|j                         S y)zAParses standalone cluster from the given args and returns its ID.N)r   rJ   r   s      r   _standalone_cluster_idz!ClientBase._standalone_cluster_id  s(    !99$?#((**r   c                 z    t        |j                  dd      r$|j                  j                  j                         S y)r   
membershipN)r   r4   r   r5   r6   s     r   "_standalone_cluster_membership_refz-ClientBase._standalone_cluster_membership_ref  s0     t}}lD1]]%%++--r   c                 J    | j                  |      }|r|j                         S yr   )r   r.   r   s      r   #_standalone_cluster_membership_namez.ClientBase._standalone_cluster_membership_name  s*     "DDTJ#0022r   c                 z    t        |j                  dd      r$|j                  j                  j                         S yr[   r]   r6   s     r   _standalone_node_pool_refz$ClientBase._standalone_node_pool_ref&  s0    t}}k40]]$$**,, 1r   c                 J    | j                  |      }|r|j                         S yr`   )r   r.   ra   s      r   _standalone_node_pool_namez%ClientBase._standalone_node_pool_name+  s)     2248M''))r   c                 J    | j                  |      }|r|j                         S yre   )r   rJ   ra   s      r   _standalone_node_pool_idz#ClientBase._standalone_node_pool_id4  s)    2248M!! r   c                 f    | j                  |      }|r|j                         j                         S yrh   )r   rG   r.   ra   s      r   _standalone_node_pool_parentz'ClientBase._standalone_node_pool_parent:  s0    2248M!!#0022r   c                     | j                  |d      }|yt        j                  j                  |      }t        j                  |      S )z<Parses binary authorization from args and returns its value.binauthz_evaluation_modeN)evaluationMode)r"   rv   BinaryAuthorizationEvaluationModeValueValuesEnum)r   r   evaluation_modemodes       r   _binary_authorizationz ClientBase._binary_authorizationA  sH    ll4)CDO''EED ''t<<r   r   ))__name__
__module____qualname____doc__r   clientGkeonpremV1r   r   	Namespacer"   r)   r1   r7   r;   r>   rA   rE   rH   rK   rP   rR   rT   rW   rY   r^   rc   rf   ri   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r       sH   65F$6$6 5+55 &*"
$5$?$? %6%@%@  1 ; ; !2!<!< %6%@%@ '8'B'B #4#>#> &7&A&A (9(C(C $5$?$? 0A0K0K 1B1L1L !2!<!< "3"="= " 1 ; ; "$5$?$? 2h*;*E*E +<+F+F ->-H-H ):)D)D #--#---,=,G,G -
#--"+<+F+F "/@/J/J =(9(C(C =r   r   )r   
__future__r   r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   2googlecloudsdk.generated_clients.apis.gkeonprem.v1r	   r   r
   rv   rp   objectr   r   r   r   <module>r      s6    > &  ' 	 , / 5 \ ` 
i= i=r   