
    e>                     .   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 ddlmZ ddlmZ d Zd Zej2                   ej4                  ej6                  j8                         G d dej:                  ej:                                      Zej2                   ej4                  ej6                  j>                  ej6                  j@                         G d dej:                  ej:                                      Z!y)z+The command to update Service Mesh Feature.    )absolute_import)division)unicode_literals)
exceptions)util)actions)base)file_parsers)	resources)utilsc                 	   g }d}g }|j                  d      rd}t        j                  |      }n&|j                  d}t	        j
                  |dd      }|D ]5  }|s| j                  |      }| j                  j                         }	 | j                  |      }|j                  r|j                  }|j                  s| j                  j                         |_        t!        |d      r_|j"                  S|j"                  dk(  rD| j                  j%                  | j                  j$                  j'                  d      	      |_        t!        |d
      r|j(                  | j                  j                  j+                  d      }|j(                  dk(  r%| j                  j                  j+                  d      }|j(                  dk(  r%| j                  j                  j+                  d      }||j                  _        |j,                  | j                  j                  j/                  d      }	|j,                  dk(  r&| j                  j                  j/                  d      }	n4|j,                  dk(  r%| j                  j                  j/                  d      }	|	|j                  _        t!        |d      r|j2                  | j                  j                  j5                  d      }
|j2                  dk(  r%| j                  j                  j5                  d      }
|j2                  dk(  r%| j                  j                  j5                  d      }
|
|j                  _        | j9                  |dg| j                  j                  |             8 | j:                  j=                         }|j                  rt?        j@                  |j                  t        jB                        }t        jD                  || j:                        }| j:                  jG                  |      |_$        |jK                  d       |r| jM                  ||       yy# t        j                  $ r | j                  j                         }Y w xY w)a   Runs the update command implementation that is common across release tracks.

  For membership level spec update, we will use v2alpha API to directly update
  the membership feature resource.

  Args:
    cmd: the release track specific command
    args: the args passed to the command
  F
membershipNTpromptsearchoriginfleetFLEETtype
managementMANAGEMENT_MANUAL	automaticMANAGEMENT_AUTOMATICnot_installedMANAGEMENT_NOT_INSTALLEDMANUAL	AUTOMATICunspecified$CONTROL_PLANE_MANAGEMENT_UNSPECIFIED
config_apiCONFIG_API_UNSPECIFIEDistioCONFIG_API_ISTIOgatewayCONFIG_API_GATEWAYspec)r'   	file_path	item_typemeshfleet_default_member_config)'IsKnownAndSpecifiedr   ParseMembershipsr-   features_baseParseMembershipsPluralMembershipResourceNamemessages_v2FeatureSpecGetMembershipFeatureapitools_exceptionsHttpNotFoundErrorMembershipFeaturer'   servicemeshServiceMeshSpechasattrr   OriginTypeValueValuesEnumr   ManagementValueValuesEnumcontrol_planeControlPlaneValueValuesEnumcontrolPlaner!   ConfigApiValueValuesEnum	configApiUpdateV2messagesFeaturer
   YamlConfigFileFleetDefaultMemberConfigObjectParseFleetDefaultMemberConfigV2"CommonFleetDefaultMemberConfigSpecfleetDefaultMemberConfigappendUpdate)cmdargsmembershipsresourceupdate_maskr   patch_v2existing_membership_featuremanagement_v2control_plane_v2r!   floaded_configmember_configs                 *lib/surface/container/fleet/mesh/update.py_RunUpdateV2r[   !   s     +(+ 
l+H((.K''/H66T$K  j--j9j**,HH$'$<$<Z$H! #'',11h __<<>htX4;;#:		//00'';;GD 1 
 t\"t'B
//
)
)
C
C!#  
K	'OO++EE&( 	 
O	+OO++EE*, 	 )6h%%
//
)
)
E
E  
		{	*OO++GG 	 .OO++GG68 	 +;h't\"t'B
//
)
)
B
B& 
 
G	#OO++DD" 	
 
I	%OO++DD$ 	
 (2h$LLVHcoo??X?NO  V 
ll!	%% //2266M 99s||M 	77]7K  45JJ{A k 00 H$'OO$E$E$G!Hs   
Q-Q?>Q?c                 .	   g }d}g }|j                  d      rd}t        j                  |      }dg}n)|j                  d}t	        j
                  |dd      }dg}| j                         }i }|D ]N  }|s| j                  |      }| j                  j                         }| j                  j                  |j                        j                         D ]6  \  }	}
t        j                  |	      t        j                  |      k(  s2|
s5|
}8 |j                   s| j                  j#                         |_        t%        |d      r_|j&                  S|j&                  dk(  rD| j                  j)                  | j                  j(                  j+                  d	      
      |_        t%        |d      r|j,                  | j                  j"                  j/                  d      }|j,                  dk(  r%| j                  j"                  j/                  d      }|j,                  dk(  r%| j0                  j2                  j/                  d      }||j                   _        |j4                  | j                  j"                  j7                  d      }|j4                  dk(  r&| j                  j"                  j7                  d      }n4|j4                  dk(  r%| j                  j"                  j7                  d      }||j                   _        t%        |d      r|j:                  | j                  j"                  j=                  d      }|j:                  dk(  r%| j                  j"                  j=                  d      }|j:                  dk(  r%| j                  j"                  j=                  d      }||j                   _        |||<   Q | j                  jA                  | j                  jC                  |            }|j                  rtE        jF                  |j                  t        jH                        }t        jJ                  || j                        }| j                  jM                  |      |_'        |jQ                  d       | jS                  ||       y)zRuns the update command implementation that is common across release tracks.

  Args:
    cmd: the release track specific command
    args: the args passed to the command
  Fr   membershipSpecsNTr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )r]   r(   r+   r-   )*r.   r   r/   r-   r0   r1   
GetFeaturer2   rE   MembershipFeatureSpec	hubclientToPyDictr]   itemsr   MembershipShortnamer,   ServiceMeshMembershipSpecr;   r   r<   r=   r   r>   r3   r:   r?   r@   rA   r!   rB   rC   rF   ToMembershipSpecsr
   rG   rH   ParseFleetDefaultMemberConfigrJ   rK   rL   rM   )rN   rO   rP   rQ   rR   rW   membership_specsr   patchnamer'   r   r?   r!   rX   rY   s                   rZ   
_RunUpdaterj      s    +(+ 
l+H((.K$%K''/H66T$K %%K	nn!j--j9jLL..0Emm,,Q->->?EEG
d

"
"4
(D,D,DZ,P
P H ::<<99;ejtX4;;#:		||**$$88A + 
 t\"t'B
,,
0
0
J
J! 
 
K	'LL22LL& 	
 
O	+OO++EE*, 	 )ejj%
,,
0
0
L
L 
 
		{	*LL22NN 	
 .LL22NN6 	
 !.ejjt\"t'B
,,
0
0
I
I& 
 
G	#LL22KK" 	
 
I	%LL22KK$ 	
 (ejj#(Z ]  ` 
llmm556FG  ! 
%% //2266M 77s||M 	77]7K  45**[!    c                   .    e Zd ZdZdZdZed        Zd Zy)UpdateAlphaaK  Update the configuration of the Service Mesh Feature.

  Update the Service Mesh Feature Spec of a membership.

  ## EXAMPLES

  To update the control plane management of comma separated memberships like
  `MEMBERSHIP1,MEMBERSHIP2`, run:

    $ {command} --memberships=MEMBERSHIP1,MEMBERSHIP2
      --control-plane=CONTROL_PLANE
  r9   c           	      D   | j                  d      }|j                  dt        d       |j                  d      }|j                         }t	        j
                  |dd       |j                  d	t        d
t        j                  d	d             |j                  d      }|j                  ddgd       |j                         }|j                  dddgd       |j                  dg dd       |j                  dg ddt        j                  dd             y )NTrequired--fleet-default-member-configThe path to a service-mesh.yaml configuration file.

        To enable the Service Mesh Feature with a fleet-level default
        membership configuration, run:

          $ {command} --fleet-default-member-config=/path/to/service-mesh.yamlr   helpzComponent optionsIMembership names to update, separated by commas if multiple are supplied.pluralmembership_helpz--membershipzMembership name to update.zKThe {flag_name} flag is now deprecated. Please use `--memberships` instead.warn)r   rt   action--originr   &Changing the origin of the membership.choicesrt   --config-apir#   r%   &The API to use for mesh configuration.--management)r   manualr   !The management mode to update to.--control-planer   r   r   &Control plane management to update to.The {flag_name} flag is now deprecated. Please use `--management` instead. See https://cloud.google.com/service-mesh/docs/managed/provision-managed-anthos-service-meshr   rt   r{   add_mutually_exclusive_groupadd_argumentstr	add_groupr   AddMembershipResourceArgr   DeprecationAction)parser
args_groupmembership_groupmembership_names_groupmembership_config_groupmembership_controlplane_groups         rZ   ArgszUpdateAlpha.Args2  se   44d4CJ'R  	 "++ .JJL&&%	 '')((
	 (  /88$8G((	5 )  	 <<> " "..)$5 / 
 "..80 / 
 "..65((o
	 / rk   c                 t    t        |d      xr |j                  dk(  }|st        | |       y t        | |       y Nr   r   r;   r   r[   rj   selfrO   use_fleet_default_configs      rZ   RunzUpdateAlpha.Run  =     	h 	#KK7"  $4trk   N	__name__
__module____qualname____doc__feature_namemf_namestaticmethodr   r    rk   rZ   rm   rm     s-     ,'J JX
rk   rm   c                   .    e Zd ZdZdZdZed        Zd Zy)UpdateGAaK  Update the configuration of the Service Mesh Feature.

  Update the Service Mesh Feature Spec of a Membership.

  ## EXAMPLES

  To update the control plane management of comma separated Memberships like
  `membership1,membership2`, run:

    $ {command} --memberships=membership1,membership2
      --control-plane=CONTROL_PLANE
  r9   c           	         | j                  d      }|j                  dt        d       |j                         }|j                         }t	        j
                  |dd       |j                  d      }|j                  dd	gd
       |j                         }|j                  dddgd       |j                  dddgd       |j                  dg ddt        j                  dd             y )NTro   rq   rr   rs   ru   rv   r|   r   r}   r~   r   r#   r%   r   r   r   r   r   r   r   r   r   ry   r   r   )r   r   r   r   membership_configs_groupr   s         rZ   r   zUpdateGA.Args  s/   44d4CJ'R  	 "++--JJL&&%	  09949H))	5 *  	!==? " "..)$5 / 
 "..h'0 / 
 "..65((o
	 / rk   c                 t    t        |d      xr |j                  dk(  }|st        | |       y t        | |       y r   r   r   s      rZ   r   zUpdateGA.Run  r   rk   Nr   r   rk   rZ   r   r     s+     ,'; ;z
rk   r   N)"r   
__future__r   r   r   apitools.base.pyr   r6   &googlecloudsdk.api_lib.container.fleetr   googlecloudsdk.callioper   r	   (googlecloudsdk.command_lib.anthos.commonr
   *googlecloudsdk.command_lib.container.fleetr   3googlecloudsdk.command_lib.container.fleet.featuresr0   =googlecloudsdk.command_lib.container.fleet.membershipfeaturesmf_base/googlecloudsdk.command_lib.container.fleet.meshr   r[   rj   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHAUpdateCommandrm   BETAGAr   r   rk   rZ   <module>r      s    2 &  ' > 7 + ( A @ U Y Awx~D D%%++,h---w/D/D h - hV D%%**D,=,=,@,@AY}**G,A,A Y B Yrk   