
    1R                        S r SSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SSKJr  SS
KJr  SSKJr  SSKJr  SSKr " S S\R8                  5      r " S S\5      r " S S\\R>                  5      r  " S S\\RB                  5      r! " S S\5      r" " S S\"\RF                  5      r# " S S\"\RH                  5      r%    S"S jr&     S#S jr'S r(S r)S$S  jr*S! r+g)%zIBase classes for [enable|disable|describe] commands for Feature resource.    )
exceptions)util)
enable_api)apis)base)api_util)	resources)info)log)
properties)retryNc                   b   ^  \ rS rSrSrSr\S 5       rS
U 4S jjrS
S jr	S
S jr
S
S jrS	rU =r$ )FeatureCommand$   zFFeatureCommand is a mixin adding common utils to the Feature commands. c                 B    [         R                  " U R                  5      $ )z2The Feature info entry for this command's Feature.)r
   Getfeature_name)selfs    ?lib/googlecloudsdk/command_lib/container/fleet/features/base.pyfeatureFeatureCommand.feature(   s     88D%%&&    c                 @   > [         [        U ]  U R                  U5      $ )zZBuilds the full resource name, using the core project property if no project is specified.)superr   FeatureResourceNamer   )r   project	__class__s     r   r   "FeatureCommand.FeatureResourceName-   s$    ++/+<+<gFGr   c                     U=(       d2    [         R                  R                  R                  R	                  5       n[
        R                  " SR                  U R                  R                  U5      5      $ )zFConstructs a new Error for reporting when this Feature is not enabled.z*{} Feature for project [{}] is not enabled
r   VALUEScorer   	GetOrFailr   Errorformatr   display_namer   r   s     r   FeatureNotEnabledError%FeatureCommand.FeatureNotEnabledError4   sW    C**//77AACGHOO!!7, - -r   c                     U=(       d2    [         R                  R                  R                  R	                  5       n[
        R                  " SR                  U R                  R                  U5      5      $ )zSConstructs a new Error for reporting when accessing this Feature is not authorized.z4Not authorized to access {} Feature for project [{}]r!   r(   s     r   NotAuthorizedError!FeatureCommand.NotAuthorizedError:   sW    C**//77AACG>EELL%%w	01 1r   c                      U R                   R                  U R                  U5      5      $ ! [        R                   a    U R                  U5      e[        R                   a    U R                  U5      ef = f)zBFetch this command's Feature from the API, handling common errors.)	hubclient
GetFeaturer   apitools_exceptionsHttpNotFoundErrorr)   HttpUnauthorizedErrorr,   r(   s     r   r0   FeatureCommand.GetFeatureA   sl    -^^&&t'?'?'HII00 1''0044 -##G,,-s
   ), A
A6 N)__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r)   r,   r0   __static_attributes____classcell__)r   s   @r   r   r   $   s7    N,' 'G-1- -r   r   c                   (    \ rS rSrSrSS jrS rSrg)EnableCommandMixinK   z.A mixin for functionality to enable a Feature.c                    [         R                  R                  R                  R	                  5       nU R
                  R                  (       a*  [        R                  " X0R
                  R                  5        [        R                  " U5      n [        R                  " SSS9nUR                  U R                  R                  X@R                   U4U R"                  SS9nS
R+                  U R
                  R,                  5      n	U R?                  U R                  R@                  XiS9$ ! [        R$                   a:    [&        R(                  " SR+                  U R
                  R,                  5      5      e[.        R0                   a{  n[2        R4                  " U5      nUR6                  S:w  d  U(       a  e [8        R:                  R=                  SR+                  U R
                  R,                  U5      5         S	nAg	S	nAff = f)a$  Enables feature API and creates the feature.

Args:
  feature: Fleet Feature to create.
  error_if_feature_exists: Whether to error if feature already exists.
    Example usage if caller populates feature fields that may differ on
    existing Feature.
Returns:
  Feature creation operation.
   g      ?)max_retrialsexponential_sleep_multiplieri  )argsshould_retry_ifsleep_msz-Retry limit exceeded waiting for {} to enableALREADY_EXISTSz.{} Feature for project [{}] is already enabledNz$Waiting for Feature {} to be created)opmessage)!r   r"   r#   r   r$   r   apir   EnableServiceIfDisabledr   LocationResourceNamer   RetryerRetryOnExceptionr/   CreateFeaturer   _FeatureAPINotEnabledMaxRetrialsExceptionr   r%   r&   r'   r1   HttpConflictErrorcore_api_exceptionsHttpErrorPayloadstatus_descriptionr   statusPrintWaitForHubOpfeature_waiter)
r   r   error_if_feature_existsr   parentretryerrJ   eerrormsgs
             r   EnableEnableCommandMixin.EnableN   s    $$,,668G||((,,2B2BC&&w/F 14Pg##
..
&
&))7344	 $ b" 1
7
7!!#CT^^::rOO %% *
9
@
@ll'')* * 00 !2215e

"
"&6
6$	jjGNN
,,
#
#W. /s   AD) )A H	A1G??Hc                 ^   AAU R                   R                  (       d  gU[        R                  :w  a  g[        R
                  " U5      nUR                  S:X  a4  U R                   R                  UR                  ;   a  SUR                  ;   d  g[        R                  R                  S5        g)NFFAILED_PRECONDITIONzis not enabledz/Waiting for service API enablement to finish...T)r   rL   r1   HttpBadRequestErrorrU   rV   rW   rK   r   rX   rY   )r   exc_type	exc_value	tracebackstater`   s         r   rR   (EnableCommandMixin._FeatureAPINotEnabledv   s    5<<&:::00;E$$(==LL--JJFGr   r5   N)F)r7   r8   r9   r:   r;   rb   rR   r=   r5   r   r   r@   r@   K   s    6&PPr   r@   c                       \ rS rSrSrS rSrg)EnableCommand   z2Base class for the command that enables a Feature.c                 T    U R                  U R                  R                  5       5      $ r6   )rb   messagesFeaturer   _s     r   RunEnableCommand.Run   s    ;;t}},,.//r   r5   N)r7   r8   r9   r:   r;   rt   r=   r5   r   r   rm   rm      s
    :0r   rm   c                   $    \ rS rSrSrS rS rSrg)DescribeCommand   zBBase class for the command that describes the status of a Feature.c                 "    U R                  5       $ r6   )r0   rr   s     r   rt   DescribeCommand.Run   s    ??r   c                 X   U Vs0 s H  n[         R                  " U5      U_M     nn0 nUR                  (       ak  UR                  R                   Vs0 s HJ  n[         R                  " UR                  5      U;   d  M)  [         R                  " UR                  5      U_ML     nnUR                  5        VVs/ s H  u  psXu;  d  M  UPM     nnnU(       a:  [        R                  " SR                  U R                  R                  U5      5      e0 n	UR                  (       ak  UR                  R                   Vs0 s HJ  n[         R                  " UR                  5      U;   d  M)  [         R                  " UR                  5      U_ML     n	nU R                  R                  R                  [        UR!                  5       5      S9Ul        U R                  R                  R#                  U Vs/ s H  nX9;   d  M
  X   PM     snS9Ul        gs  snf s  snf s  snnf s  snf s  snf )a  Leave only specs and states of Memberships in the Feature.

Respects the order of the Membership specs in the original Feature.

Args:
  feature: Feature in the v1 API.
  memberships: List of resource names according to go/resource-names.
    Ideally, the existence of these Memberships will have been verified.
Returns:
  None
Raises:
  exceptions.Error: if any of Memberships does not have a spec in Feature.
zcThe following requested memberships are not configured on the {} feature, under membershipSpecs: {}additionalPropertiesN)r   MembershipPartialNamemembershipSpecsr}   keyitemsr   r%   r&   r   r'   membershipStatesrp   rq   MembershipSpecsValuelistvaluesMembershipStatesValue)
r   r   membershipsm memberships_by_location_and_name%membership_specs_by_location_and_nameentrylocation_namemissing_memberships&membership_states_by_location_and_names
             r   filter_feature_for_memberships.DescribeCommand.filter_feature_for_memberships   s   " 3>(2=Q""1%q(+ % ( -/) ..CC/Ce''		2-. 7$
$
$UYY
/
6C , / !A F F H HME 	
 H  
 1F4<<,,.AB 
 .0* //DD0De''		223 7$
$
$UYY
/
6D - 0 #mm33HH!188:
 I G
  $}}44JJ ;
:: 625:
  K  GK(
/0
s5   !H(H?%H9HH=(H")%H"2	H'?H'r5   N)r7   r8   r9   r:   r;   rt   r   r=   r5   r   r   rw   rw      s    J;r   rw   c                       \ rS rSrSrS rSrg)UpdateCommandMixin   z.A mixin for functionality to update a Feature.c                 <    U R                   R                  U R                  5       X5      nSR                  U R                  R                  5      nU R                  U R                   R                  X4SS9$ ! [        R                   a    U R                  5       ef = f)z>Update provides common API, display, and error handling logic.z$Waiting for Feature {} to be updatedFrK   warnings)r/   UpdateFeaturer   r1   r2   r)   r&   r   r'   rZ   r[   )r   maskpatchrJ   ra   s        r   UpdateUpdateCommandMixin.Update   s    *>>''(@(@(BDPb 1
7
7!!#C%%r    00 *''))*s   *A6 6%Br5   N)r7   r8   r9   r:   r;   r   r=   r5   r   r   r   r      s
    6r   r   c                   H    \ rS rSrSr\R                  " SS S/SS9rS rS	r	g
)UpdateCommand   zBase class for the command that updates a Feature.

Because Features updates are often bespoke actions, there is no default
`Run` override like some of the other classes.
z--originc                 "    U R                  5       $ r6   )lowerorigins    r   <lambda>UpdateCommand.<lambda>   s
    &,,.r   fleeta+  Update the configuration of the target membership(s) to the [fleet-default membership configuration](https://docs.cloud.google.com/kubernetes-engine/fleet-management/docs/manage-features). Errors if the fleet-default membership configuration is not set; see the `--fleet-default-member-config` flag.)typechoiceshelpc                    U R                   R                  R                  U Vs/ s H  nU R                   R                  R                  R                  UU R                   R	                  U R                   R                  U R                   R
                  R                  R                  S9S9S9PM     snS9nU R                  S/U R                   R                  US95      $ s  snf )N)r   r   )r   valuer|   membership_specs)r   )	rp   rq   r   AdditionalPropertyMembershipFeatureSpecOriginTypeValueValuesEnumFLEETr   )r   r   r   r   s       r   !sync_memberships_to_fleet_default/UpdateCommand.sync_memberships_to_fleet_default   s    }},,AA !

 ! MM!!66IImm99==//!]]11EEKK 0  :  J  !

 B  ;;*+T]]-B-B( .C .  

s   BC!r5   N)
r7   r8   r9   r:   r;   calliope_baseArgumentORIGIN_FLAGr   r=   r5   r   r   r   r      s.    
 &&(i;+r   r   c                       \ rS rSrSr\R                  " SSSS9r\R                  " SSSS9rS	r	\
S
 5       rS rS rS rSrg)DisableCommandi  zLBase class for the command that disables an entire or parts of a Feature.
  z--force
store_truezForce disablement. Bypasses any prompts for confirmation. When disabling the entire feature, proceeds even if the feature is in use. Might result in unexpected behavior.)actionr   z--fleet-default-member-configzDisable the [fleet-default membership configuration](https://docs.cloud.google.com/kubernetes-engine/fleet-management/docs/manage-features). Does not change existing membership configurations. Does nothing if the feature is disabled.Fc                     U R                   R                  U5        U R                  (       a  U R                  R                  U5        g g r6   )
FORCE_FLAGAddToParsersupport_fleet_default FLEET_DEFAULT_MEMBER_CONFIG_FLAG)clsparsers     r   ArgsDisableCommand.Args)  s6    NNv&
  	**66v> !r   c                     U R                   (       a"  UR                  (       a  U R                  5         g U R                  UR                  5        g r6   )r   fleet_default_member_configclear_fleet_defaultDisableforce)r   rF   s     r   rt   DisableCommand.Run/  s/    !!d&F&F
 
ll4::r   c                     U R                   R                  U R                  5       US9nSR                  U R                  R                  5      nU R                  U R                   R                  X#SS9  g ! [        R                   a     g f = f)N)r   z$Waiting for Feature {} to be deletedFr   )
r/   DeleteFeaturer   r1   r2   r&   r   r'   rZ   resourceless_waiter)r   r   rJ   rK   s       r   r   DisableCommand.Disable5  s    >>''(@(@(B%'Pb 5;;!!#G**B%  Q	 00 s   (A5 5BBc                    S/nU R                   R                  SS9n U R                  X5      $ ! [        R                   aH  n[
        R                  " U5      [
        R                  " U R                  5       5      :w  a  Ue S nAg S nAff = f)Nr   placeholder)name)rp   rq   r   r   r%   six	text_typer)   )r   r   r   r_   s       r   r   "DisableCommand.clear_fleet_default?  s{    )*D MM!!}!5E[[%% 	q	S]]4+F+F+HI	I 
Js   / B>BBr5   N)r7   r8   r9   r:   r;   r   r   r   r   r   classmethodr   rt   r   r   r=   r5   r   r   r   r     sn     %%2	
* &3%;%;% 6&"  ? ?
Qr   r   c                    U R                  S5      (       d,  U R                  S5      (       d  U R                  U5      (       aN  [        R                  " U U5      (       d  U(       d  [        R                  " X5      $ [        R                  " XSS9$ U(       d  U(       d  [        X5      e[        R                  " SS9u  pVU(       a%  [        R                  " SR                  U5      5      eU(       aE  [        U5      S:X  a6  [        R                  R                  SR                  US   5      5        US   $ U(       a  [        R                  " U5      nUb  U$ [        X5      e)	a
  Returns a membership on which to run the command, given the arguments.

Allows for a `--membership` flag or a `MEMBERSHIP_NAME` positional flag.

Args:
  args: object containing arguments passed as flags with the command
  prompt: whether to prompt in console for a membership when none are provided
    in args
  autoselect: if no membership is provided and only one exists,
    automatically use that one
  search: whether to search for the membership and error if it does not exist
    (not recommended)
  flag_override: to use a custom membership flag name

Returns:
  membership: A membership resource name string

Raises:
  exceptions.Error: no memberships were found or memberships are invalid
  calliope_exceptions.RequiredArgumentException: membership was not provided

membershipMEMBERSHIP_NAMETfilter_cluster_missingLocations {} are currently unreachable. Please specify memberships using `--location` or the full resource name (projects/*/locations/*/memberships/*)   Selecting membership [{}].r   )IsKnownAndSpecifiedr	   MembershipLocationSpecifiedMembershipResourceNameSearchMembershipResourceMembershipRequiredErrorr   ListMembershipsFullr   r%   r&   lenr   rX   rY   PromptForMembership)rF   prompt
autoselectsearchflag_overrideall_membershipsunreachabler   s           r   ParseMembershipr   O  s7   8 
l++t/G/G0 0 44]CC,,T-:< <CI--dBB//
d< < 


!$
66!)!=!=!"#/



2396+3FH H C(A-JJ1889KLM1..?J44r   c                    / n[        U S5      (       ar  U R                  (       aa  [        R                  " SS9u  pxU(       a%  [        R
                  " SR                  U5      5      eU(       d  [        R
                  " S5      eU$ U R                  S5      (       a  [        R                  " U 5      (       a  U[        R                  " U 5      -  nU(       aI  U HC  n	[        R                  " U	5      (       a  M   [        R
                  " SR                  U	5      5      e   U(       dB  [        [        R                  " U5      5      S:  a  [        [        R                  " U5      5      eOU[        R                  " U SS9-  nU(       a  U$ U(       d  U(       d  [!        U 5      e[        R                  " SS9u  pxU(       a%  [        R
                  " S	R                  U5      5      eU(       aF  [        U5      S:X  a7  ["        R$                  R'                  S
R                  US   5      5        US   /$ U(       a/  [        R(                  " SUS9n	U	(       a  UR+                  U	5        U$ [!        U 5      e)a6  Parses a list of membership resources from args.

Allows for a `--memberships` flag and a `--all-memberships` flag.

Args:
  args: object containing arguments passed as flags with the command
  prompt: whether to prompt in console for a membership when none are provided
    in args
  prompt_cancel: whether to include a 'cancel' option in the prompt
  autoselect: if no memberships are provided and only one exists,
    automatically use that one
  allow_cross_project: whether to allow memberships from different projects
  search: whether to check that the membership exists in the fleet

Returns:
  memberships: A list of membership resource name strings

Raises:
  exceptions.Error if no memberships were found or memberships are invalid
  calliope_exceptions.RequiredArgumentException if membership was not provided
r   Tr   zaLocations {} are currently unreachable. Please try again or specify memberships for this command.z&No Memberships available in the fleet.r   z*Membership {} does not exist in the fleet.r   r   r   r   z--memberships)flagcancel)hasattrr   r   r   r   r%   r&   r   r	   r   PluralMembershipsResourceNamesGetMembershipr   GetMembershipProjectsCrossProjectErrorSearchMembershipResourcesPluralr   r   rX   rY   r   append)
rF   r   prompt_cancelr   allow_cross_projectr   r   r   r   r   s
             r   ParseMembershipsPluralr     s%   6 + T$%%$*>*>#+#?#?#$% O228&2EG G EFF 
m,,,,T22Y==dCCk	%J''
33""<CCJOQ Q &
 !S

)
)+
6&8:;&<	 ? ? LMM Y>>
t- -k  


!$
''!)!=!=!"#/



2396+3FH H C(A-JJ1889KLMA..J $%%r   c                     [         R                  " SS5      n U R                  R                  U R                  R                  [        R                  R                  5       S95      nUR                   Vs/ s H?  n[        UR                  5      (       a  M  [        R                  " UR                  5      PMA     sn$ s  snf )zwLists Membership IDs in the fleet for the current project.

Returns:
  A list of Membership resource IDs in the fleet.
gkehubv1beta)r]   )	core_apisGetClientInstanceprojects_locations_membershipsListMESSAGES_MODULE-GkehubProjectsLocationsMembershipsListRequesthub_base
HubCommandrN   r	   _ClusterMissingendpointr   MembershipShortnamer   )clientresponser   s      r   ListMembershipsr    s     &&x:&2277JJ$$99; K =>( !!
!!QZZ( 'dqvv&!
  
s   4B=$B=c                 L    [         R                  " SR                  U 5      5      $ )NzoMemberships for this command must belong to the same project and cannot mix project number and project ID ({}).)r   r%   r&   )projectss    r   r   r     s$    			 --3VH-=
? ?r   c                 z    U(       a  UnOU R                  S5      (       a  SnOSn[        R                  " US5      $ )a  Parses a list of membership resources from args.

Assumes a `--memberships` flag or a `MEMBERSHIP_NAME` flag unless overridden.

Args:
  args: argparse.Namespace arguments provided for the command
  flag_override: set to override the name of the membership flag

Returns:
  memberships: A list of membership resource name strings

Raises:
  exceptions.Error: if no memberships were found or memberships are invalid
  calliope_exceptions.RequiredArgumentException: if membership was not
    provided
r   r   z5At least one membership is required for this command.)r   calliope_exceptionsRequiredArgumentException)rF   r   r   s      r   r   r     sC    " D 122DD		6	6
C
E Er   c                 f    S H+  n[        X5      (       d  M  [        [        X5      SS5      s  $    g )N)
gkeClustermultiCloudClusteronPremClusterclusterMissingF)r   getattr)r   ts     r   r  r    s*    ?aq}}WQ]$4e<< @r   )FFFr   )FTFFF)r   ),r;   apitools.base.pyr   r1   &googlecloudsdk.api_lib.container.fleetr   googlecloudsdk.api_lib.servicesr   googlecloudsdk.api_lib.utilr   r   rU   googlecloudsdk.callioper   r   r  *googlecloudsdk.command_lib.container.fleetr   r  r	   3googlecloudsdk.command_lib.container.fleet.featuresr
   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r   r  r   r@   CreateCommandrm   rw   r   r   DeleteCommandr   r   r   r  r   r   r  r5   r   r   <module>r      s   P ? 7 6 9 I 9 E ? G @ D * # * * 
$-X(( $-N7 7t0&(C(C 0Dnm&C&C DN "$&(C(C $NA')D)D AJ !$ "$	75v #()-&+/4"'T&r$?E6=r   