
    Q                     2   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\R&                  5      r " S S\5      rS rS rS rS r          SS jr SS jrS rS rS rS rg)z5Command util functions for gcloud container commands.    )absolute_import)division)unicode_literals)api_adapter)
exceptions)log)
properties)
console_io)iso_duration)text)timesc                       \ rS rSrSrSrg)Error    z.Class for errors raised by container commands. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       Blib/googlecloudsdk/command_lib/container/container_command_util.pyr   r       s    6r   r   c                       \ rS rSrSrSrg)NodePoolError$   zEError when a node pool name doesn't match a node pool in the cluster.r   Nr   r   r   r   r   r   $   s    Mr   r   c                     U R                    H  nUR                  U:X  d  M  Us  $    [        SR                  U5      5      e)z@Helper function to get node pool from a cluster, given its name.z*No node pool found matching the name [{}].)	nodePoolsnamer   format)clusternode_pool_name	node_pools      r   _NodePoolFromClusterr%   (   sC    $$i~~' % 	299.I	K Kr   c                     U(       a  SR                  UR                  5      nOSnU(       d  U(       a  UR                  nU(       a  SR                  U5      nOSnSR                  XU5      $ )a  Returns the prompt message during a master upgrade.

Args:
  name: str, the name of the cluster being upgraded.
  server_conf: the server config object.
  cluster: the cluster object.
  new_version: str, the name of the new version, if given.

Raises:
  NodePoolError: if the node pool name can't be found in the cluster.

Returns:
  str, a message about which nodes in the cluster will be upgraded and
      to which version.
version [{}]its current versionthe default cluster versionz6Master of cluster [{}] will be upgraded from {} to {}.)r!   currentMasterVersiondefaultClusterVersion)r    server_confr"   new_versionversion_messagenew_version_messages         r   _MasterUpgradeMessager0   2   se      $++G,H,HIO+O	33K(//<7
B
I
I
02 3r   c                 *   U(       a  SR                  UR                  5      nOSnU(       d  U(       a  UR                  nU(       a  SR                  U5      nOSn[        R                  " [
        R                  " US95      nSR                  XXg5      $ )a^  Returns the prompt message during a rollback safe upgrade.

Args:
  name: str, the name of the cluster being upgraded.
  server_conf: the server config object.
  cluster: the cluster object.
  new_version: str, the name of the new version, if given.
  control_plane_soak_duration: int, the soak duration in seconds for the
    control plane upgrade.
r'   r(   r)   )secondszControl plane of cluster [{}] will be upgraded from {} to {} with a soak duration of {}. You can rollback the cluster to previous version within the soak duration.)r!   r*   r+   r   FormatDurationForJsonr   Duration)r    r,   r"   r-   control_plane_soak_durationr.   r/   soak_durations           r   _RollbackSafeUpgradeMessager7   S   s     $++G,H,HIO+O	33K(//<7--$?@-##)6
!4$r   c                   ^ ^ SmSnU(       a/  SR                  TU5      mU(       a  [        X5      R                  nOOU(       aH  SR                  TUR                  [        R
                  " UR                  S5      5      mUR                  nU(       a  SR                  U5      n	OSn	U(       d  U(       a  UR                  nU(       a  SR                  U5      n
OSn
U U4S	 jnU(       a]  SnU(       a'  U(       a   [        UU5      R                  R                  nU(       a  S
R                  TT X5      $ SR                  TT U5      $ / nU(       aH  SnU(       a'  U(       a   [        UU5      R                  R                  nUR                  U" SX5      5        U(       aH  SnU(       a'  U(       a   [        UU5      R                  R                  nUR                  U" SX5      5        U(       aI  SnU(       a'  U(       a   [        UU5      R                  R                  nUR                  U" SUU5      5        U(       d  SR                  TT X5      $ SR                  U5      $ )a  Returns the prompt message during a node upgrade.

Args:
  name: str, the name of the cluster being upgraded.
  cluster: the cluster object.
  node_pool_name: str, the name of the node pool if the upgrade is for a
    specific node pool.
  new_version: str, the name of the new version, if given.
  new_image_type: str, the name of the new image type, if given.
  new_machine_type: str, the name of the new machine type, if given.
  new_disk_type: str, the name of the new disk type, if given.
  new_disk_size: int, the size of the new disk, if given.

Raises:
  NodePoolError: if the node pool name can't be found in the cluster.

Returns:
  str, a message about which nodes in the cluster will be upgraded and
      to which version, image, or config, if applicable.
z	All nodesNz{} in node pool [{}]z
{} ({} {})noder'   r(   zthe master versionc                 `   > U(       a  SR                  U5      OSnSR                  TTXU5      $ )Nzfrom {} z+{} of cluster [{}] {} will change {} to {}.)r!   )fieldcurrentnewfrom_currentr    node_messages       r   _UpgradeMessage,_NodeUpgradeMessage.<locals>._UpgradeMessage   s3    079##G,RL8??dE6 6r   z3{} of cluster [{}] image will change from {} to {}.z+{} of cluster [{}] image will change to {}.machine_type	disk_type	disk_sizez2{} of cluster [{}] will be upgraded from {} to {}.r;   )r!   r%   versioncurrentNodeCountr   	PluralizecurrentNodeVersionr*   config	imageTypemachineTypeappenddiskType
diskSizeGbjoin)r    r"   r#   r-   new_image_typenew_machine_typenew_disk_typenew_disk_sizecurrent_versionr.   r/   rA   
image_typenode_upgrade_messagesrC   rD   rE   r@   s   `                @r   _NodeUpgradeMessagerX   y   s#   . ,/)00~NL,WEMMo&&g..w//8:L 00O$++O<O+O	..K(//<.6
 J>'(688>yy CJJ
j: ; <BB
n. / L>)'*8::@&   GI I>&w'577=vhh   Y>@ I>&w'577=vjj   Y>@ 
?FFdOB B	&	''r   Nc           
          U(       a"  U(       a  [        XX&U5      nO[        XX&5      nO[        U UUUUUU	U
5      nSR                  U5      $ )a  Get a message to print during gcloud container clusters upgrade.

Args:
  name: str, the name of the cluster being upgraded.
  server_conf: the server config object.
  cluster: the cluster object.
  master: bool, if the upgrade applies to the master version.
  control_plane_soak_duration: int, the soak duration for the control plane
    upgrade.
  node_pool_name: str, the name of the node pool if the upgrade is for a
    specific node pool.
  new_version: str, the name of the new version, if given.
  new_image_type: str, the name of the new node image type, if given.
  new_machine_type: str, the name of the new machine type, if given.
  new_disk_type: str, the name of the new boot disk type, if given.
  new_disk_size: int, the size of the new boot disk in GB, if given.

Raises:
  NodePoolError: if the node pool name can't be found in the cluster.

Returns:
  str, a message about which nodes in the cluster will be upgraded and
      to which version.
z{} This operation is long-running and will block other operations on the cluster (except other node pool upgrades) until it has run to completion.)r7   r0   rX   r!   )r    r,   r"   masterr5   r#   r-   rQ   rR   rS   rT   upgrade_messages               r   ClusterUpgradeMessager\      sf    F "3
W3No .
Wo *	OVO,r   c                 
   [        U SS5      n[        U SS5      n[        U SS5      nU(       a  SnGOU(       aj  [        R                  R                  R                  R                  5       (       a3  [        R                  R                  R                  R                  5       nO[        R                  R                  R                  R                  5       (       a3  [        R                  R                  R                  R                  5       nO2[        R                  R                  R                  R                  5       nU=(       d    U=(       d    U=(       d    UnU(       a  U(       d  [        R                  " / SQ5      eU$ )a  Get a location (zone or region) from argument or property.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.
  ignore_property: bool, if true, will get location only from argument.
  required: bool, if true, lack of zone will cause raise an exception.
  is_autopilot: bool, if true, region property will take precedence over zone.

Raises:
  MinimumArgumentException: if location if required and not provided.

Returns:
  str, a location selected by user.
locationNzoneregion)z
--locationz--zonez--region)	getattrr	   VALUEScomputer`   Getr_   calliope_exceptionsMinimumArgumentException)argsignore_propertyrequiredis_autopilotr^   r_   r`   location_propertys           r   GetZoneOrRegionrl     s   $ T:t,(	vt	$$44(&
))1188<<>>"))1188<<>  %%))++"))1166::<"))1188<<><<4<+<(h

6
6,  
/r   c                     U R                  S5      (       a  U R                  $ [        U SS5      (       a  gU R                  $ )z$Gets the value of node auto-upgrade.enable_autoupgradeenable_kubernetes_alphaFN)IsSpecifiedrn   ra   rg   s    r   GetAutoUpgraderr   B  s?    	*++"""T,e44		 	  r   c                     U R                  S5      (       a  U R                  $ [        U SS5      (       a  g[        U SS5      (       a  gU R                  =(       d    SR	                  5       S;   $ )	z#Gets the value of node auto-repair.enable_autorepairrelease_channelNTro   Fr;   )r;   coscos_containerdgciubuntuubuntu_containerd)rp   rt   ra   rV   lowerrq   s    r   GetAutoRepairr|   L  sn    	)**!!! T$d++T,e44 //
R	&	&	( - 
 r   c                     [        U SS5      nUc  gUR                  5       S:X  a   [        R                  R	                  S5        gg)zChecks if the release_channel argument is 'extended' and prints a message.

Args:
  args: An object (e.g., from argparse) containing command-line arguments.
ru   NextendedzNote: For GKE Standard edition, pay-per-use costs apply when your cluster is enrolled in the Extended release channel and your cluster's minor version enters the extended support period.)ra   r{   r   statusPrint)rg   ru   s     r   CheckReleaseChannelr   ]  sJ     D"3T:/

*JJ	G
 +r   c           
      d   [         R                  " SB0 SU R                  _SU R                  _SU R                  _SU R
                  _SU R                  _SU R                  _SU R                  _SU R                  _S	U R                  _S
U R                  _SU R                  _SU R                  _SU R                  _SU_SU R                  _SU R                   _SU R"                  _SU R$                  _SU R&                  _SU R(                  _SU R*                  _SU R,                  _SU R.                  _SU R0                  _SU R2                  _SU R4                  _SU R6                  _SU R8                  _S[;        U SS5      _S[;        U SS5      _S [;        U S S5      _S![;        U S!S5      _S"[;        U S"S5      _S#[;        U S#S5      _S$[;        U S$S5      _S%[;        U S%S5      _S&[;        U S&S5      _S'[;        U S'S5      _S(U R<                  _S)U R>                  _S*U R@                  _S+U RB                  _S,U RD                  _S-U RF                  _S.U RH                  _S/[;        U S/S5      _S0U RJ                  _S1U RL                  _S2U RN                  _S3U RP                  _S4[;        U S4S5      _S5[;        U S5S5      _S6[;        U S7S5      _S8[;        U S8S5      _6nU R                  (       aW  [         RR                  U R                  ;   a9  U R                  [         RR                     nU(       a  [T        RV                  " S9S:S;9  U R                  (       aW  [         RX                  U R                  ;   a9  U R                  [         RX                     nU(       a  [T        RV                  " S<S:S;9  U R                  (       aW  [         RZ                  U R                  ;   a9  U R                  [         RZ                     nU(       a  [T        RV                  " S=S:S;9  U R                  (       aW  [         R\                  U R                  ;   a9  U R                  [         R\                     nU(       a  [T        RV                  " S>S:S;9  U R                  (       aW  [         R^                  U R                  ;   a9  U R                  [         R^                     nU(       a  [T        RV                  " S?S:S;9  U R                  (       aW  [         R`                  U R                  ;   a9  U R                  [         R`                     nU(       a  [T        RV                  " S@S:S;9  U R                  (       aW  [         Rb                  U R                  ;   a9  U R                  [         Rb                     n	U	(       a  [T        RV                  " SAS:S;9  U$ )Ca6  Helper function to build ClusterUpdateOptions object from args.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.
  locations: list of strings. Zones in which cluster has nodes.

Returns:
  ClusterUpdateOptions, object with data used to update cluster.
monitoring_servicelogging_service
monitoringloggingenable_stackdriver_kubernetesdisable_addonsenable_autoscaling	min_nodes	max_nodestotal_min_nodestotal_max_nodeslocation_policyr$   	locations!enable_master_authorized_networksmaster_authorized_networksprivate_ipv6_google_access_typeworkload_pooldisable_workload_identitydatabase_encryption_keydisable_database_encryptionenable_vertical_pod_autoscalingenable_autoprovisioningenable_mesh_certificatesautoprovisioning_config_file autoprovisioning_service_accountautoprovisioning_scopesautoprovisioning_locations"autoprovisioning_max_surge_upgradeN(autoprovisioning_max_unavailable_upgrade%enable_autoprovisioning_surge_upgrade*enable_autoprovisioning_blue_green_upgrade(autoprovisioning_standard_rollout_policy(autoprovisioning_node_pool_soak_duration"enable_autoprovisioning_autorepair#enable_autoprovisioning_autoupgrade!autoprovisioning_min_cpu_platformautoprovisioning_image_typemin_cpumax_cpu
min_memory
max_memorymin_acceleratormax_acceleratorlogging_variantin_transit_encryption&autoprovisioning_resource_manager_tags!service_account_verification_keysservice_account_signing_keys!control_plane_disk_encryption_keyboot_disk_provisioned_iops boot_disk_provisioned_throughputenable_pod_snapshotspod_snapshots_enabledenable_slice_controllerzIf the GCE Persistent Disk CSI Driver is disabled, then any pods currently using PersistentVolumes owned by the driver will fail to terminate. Any new pods that try to use those PersistentVolumes will also fail to start.T)messagecancel_on_nozIf the GCP Filestore CSI Driver is disabled, then any pods currently using PersistentVolumes owned by the driver will fail to terminate. Any new pods that try to use those PersistentVolumes will also fail to start.zIf the Cloud Storage Fuse CSI Driver is disabled, then any pods currently using PersistentVolumes owned by the driver will fail to terminate. Any new pods that try to use those PersistentVolumes will also fail to start.zIf the StatefulHA Addon is disabled, then any applications currently protected will no longer be updated for high availability configuration.zIf the Parallelstore CSI Driver is disabled, then any pods currently using PersistentVolumes owned by the driver will fail to terminate. Any new pods that try to use those PersistentVolumes will also fail to start.zIf the High Scale Checkpointing is disabled, then any pods currently using Volumes owned by the driver will fail to terminate. Any new pods that try to use those Volumes will also fail to start.zIf the Lustre CSI Driver is disabled, then any pods currently using PersistentVolumes owned by the driver will fail to terminate. Any new pods that try to use those PersistentVolumes will also fail to start.r   )2r   UpdateClusterOptionsr   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   ra   r   r   r   r   r   r   r   r   r   r   r   GCEPDCSIDRIVERr
   PromptContinueGCPFILESTORECSIDRIVERGCSFUSECSIDRIVER
STATEFULHAPARALLELSTORECSIDRIVERHIGHSCALECHECKPOINTINGLUSTRECSIDRIVER)
rg   r   optspdcsi_disabledfilestorecsi_disabledgcsfusecsi_disabledstatefulha_disabledparallelstorecsi_disabledhighscalecheckpointing_disabledlustrecsi_disableds
             r   ParseUpdateOptionsBaser   q  sq    
	)	) S
00S
**S
 S
 ll	S

 %)$F$FS
 ((S
 00S
 S
 S
 **S
 **S
 **S
 S
 S
 )-(N(NS
  "&!@!@!S
" '+&J&J#S
$ &&%S
& !% > >'S
( #::)S
* #'"B"B+S
, '+&J&J-S
. #::/S
0  $<<1S
2 $(#D#D3S
4 (,'L'L5S
6 #::7S
8 "&!@!@9S
: *1
4d*;S
@ 07
:D0AS
F -4
7-GS
L 29
<d2MS
R 07
:D0SS
X 07
:D0YS
^ *1
4d*_S
d +2
5t+eS
j )0
3T)kS
p #*
-t#qS
v llwS
x llyS
z {S
| }S
~ **S
@ **AS
B **CS
D $D*A4HES
H 
5
5IS
N 
0
0OS
R $(#D#DSS
T )-(N(NUS
V ")
,d"WS
\ (/
2D(]S
b #4)@$GcS
d &d,EtLeS
$j   D$7$77(()C)CDN7  ''4+>+>> //))+7  ""d&9&99--$$&7   3 33--  	 ((D,?,?? $ 3 3**!, 7  ((D,?,??&*&9&9**',#&-  !!T%8%88,,##%7  
+r   )
NNFNNNNNNN)FTF)r   
__future__r   r   r    googlecloudsdk.api_lib.containerr   googlecloudsdk.callioper   re   googlecloudsdk.corer   r	   googlecloudsdk.core.consoler
   googlecloudsdk.core.utilr   r   r   r   r   r%   r0   r7   rX   r\   rl   rr   r|   r   r   r   r   r   <module>r      s    < &  ' 8 E * # * 2 1 ) *7J 7NE NK3B#L](B '+"&!&6:)-&*)-+/(,(,<@ >C'T!"
(qr   