
    '                         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r
SrS	rS
rSrSrSrS rS rS rS rS rS rS rS rg)zSupports getting additional information on gke version(s).

We may want to retrieve specific information on a gke version. This file will
aid us in doing so. Such as if we need to know if a cluster version is end of
life etc.
    )absolute_import)division)unicode_literals)	locations)	constantsz
To upgrade a node pool to a newer version, run:
$ gcloud container {USERS_PLATFORM} node-pools update {NODE_POOL_NAME} --cluster={CLUSTER_NAME} --location={LOCATION} --node-version={NODE_POOL_VERSION}
zJ
The current version of your node pool(s) is unsupported, please upgrade.
zE
* - This version of your cluster(s) is unsupported, please upgrade.
zG
* - This version of your node pool(s) is unsupported, please upgrade.
z
To upgrade a cluster to a newer version, run:
$ gcloud container {USERS_PLATFORM} clusters update {CLUSTER_NAME} --location={LOCATION} --cluster-version={CLUSTER_VERSION}
zH
The current version of your cluster(s) is unsupported, please upgrade.
zy
To see the list of supported versions, run:
$ gcloud container {USERS_PLATFORM} get-server-config --location={LOCATION}
c                     [         R                  " 5       nU [        R                  :X  a  UR	                  U5      R
                  $ U [        R                  :X  a  UR                  U5      R
                  $ g)a\  Loads the valid version in respect to the platform via server config.

Args:
  platform: A string, the platform the component is on {AWS,Azure}.
  location_ref:  A resource object, the pathing portion the url, used to get
    the proper server config.

Returns:
  Returns the list of valid version that were obtained in the getServerConfig
  call.
N)api_utilLocationsClientr   AZUREGetAzureServerConfigvalidVersionsAWSGetAwsServerConfig)platformlocation_refclients      Blib/googlecloudsdk/command_lib/container/gkemulticloud/versions.py_load_valid_versionsr   >   s[     ##%& &&|4BBB9== $$\2@@@    c                 `    U  H(  nUR                   U:X  d  M  UR                  (       a    g  g   g)aB  Tells if a version is end of life.

Args:
  valid_versions: A array, contains validVersions are retrieved from
    GetServerConfig (platform dependent).
  version: A string, the GKE version the component is running.

Returns:
  A boolean value to state if the version on the specified platform is marked
  as end of life.
TF)version	endOfLife)valid_versionsr   xs      r   _is_end_of_lifer   S   s,     ayyG	
	 
 
r   c                    Sn[        X R                  5       5      n[        XAR                  R                  5      (       a  SnU[
        R                  :X  a  U R                  nO U[
        R                  :X  a  U R                  nU R                  n[        nU[        R                  UR                  5       UUSS9-  nU[        R                  UR                  5       US9-  nU$ )a  Generates a message that users if their cluster version can be upgraded.

Args:
  cluster_ref: A resource object, the cluster resource information.
  cluster_info: A GoogleCloudGkemulticloudV1AzureCluster or
    GoogleCloudGkemulticloudV1AwsCluster resource, the full list of
    information on the cluster that is to be tested.
  platform: A string, the platform the component is on {AWS,Azure}.

Returns:
  A message in how to upgrade a cluster if its end of life.
NCLUSTER_VERSION)USERS_PLATFORMCLUSTER_NAMELOCATIONr   r   r    )r   Parentr   controlPlaner   r   r   awsClustersIdr   azureClustersIdlocationsId%_END_OF_LIFE_MESSAGE_DESCRIBE_CLUSTER_UPGRADE_COMMAND_CLUSTERformatlower_SUPPORTED_COMMAND)cluster_refcluster_infor   upgrade_messager   cluster_namelocations          r   upgrade_hint_clusterr1   g   s     /'2D2D2FG.^%>%>%F%FGGL9==  ..l	Y__	$ 00l&&H;O/66~~'!)	 7  O )00~~'( 1  O 
r   c           	         Sn[        X R                  5       R                  5       5      n[        XAR                  5      (       d  U$ SnSnU[        R
                  :X  a  U R                  nU R                  nO,U[        R                  :X  a  U R                  nU R                  nU R                  n[        nU[        R                  UR                  5       UUUSS9-  nU[         R                  UR                  5       US9-  nU$ )a  Generates a message that users if their node pool version can be upgraded.

Args:
  node_pool_ref: A resource object, the node pool resource information.
  node_pool_info: A GoogleCloudGkemulticloudV1AzureNodePool or
    GoogleCloudGkemulticloudV1AwsNodePool resource, the full list of
    information on the node pool that is to be tested.
  platform: A string, the platform the component is on {AWS,Azure}.

Returns:
  A message in how to upgrade a node pool if its end of life.
NNODE_POOL_VERSIONr   NODE_POOL_NAMEr    r   r3   r!   )r   r"   r   r   r   r   r$   awsNodePoolsIdr   r%   azureNodePoolsIdr&   '_END_OF_LIFE_MESSAGE_DESCRIBE_NODE_POOL_UPGRADE_COMMAND_NODE_POOLr)   r*   r+   )node_pool_refnode_pool_infor   r.   r   r/   node_pool_namer0   s           r   upgrade_hint_node_poolr=      s    /'$$&--/. 
)?)?	@	@,. ..L"11N9??" 00L"33N&&(;//66^^%#+ 7  / '..^^% /  / 
r   c                     [         nU[        R                  U R                  5       SSSS9-  nU[        R                  U R                  5       SS9-  nU$ )zGenerates a message that warns users if their cluster version can be upgraded.

Args:
  platform: A string, the platform the component is on {AWS,Azure}.

Returns:
  A message in how to upgrade a cluster if its end of life.
r    r   r   )r   r    r   r   r!   )_UPGRADE_CLUSTER_HINTr(   r)   r*   r+   )r   r.   s     r   upgrade_hint_cluster_listr@      sl     */-44^^%'!	 5  / '..^^%
 /  / 
r   c           	      F   SnU [         R                  :X  a  UR                  nO U [         R                  :X  a  UR                  n[
        nU[        R                  U R                  5       SUR                  USS9-  nU[        R                  U R                  5       SS9-  nU$ )a(  Generates a message that warns users if their node pool version can be upgraded.

Args:
  platform: A string, the platform the component is on {AWS,Azure}.
  cluster_ref: A resource object, the cluster resource information.

Returns:
  A message in how to upgrade a node pool if its end of life.
Nr5   r3   r4   r    r!   )r   r   r$   r   r%   _UPGRADE_NODE_POOL_HINTr9   r)   r*   r&   r+   )r   r,   r/   r.   s       r   upgrade_hint_node_pool_listrC      s     ,,,L9??"..L+//66^^%%&&+ 7  / '..^^%
 /  / 
r   c                     / nSn[        X5      nU HY  n[        XVR                  R                  5      (       a!  UR                  =R                  S-  sl        SnUR	                  U5        M[     [        U5      U4$ )a4  Generates a table of user's cluster versions and then adds a "*" to the version that can be upgraded.

Args:
  cluster_ref: A resource object, the cluster resource information.
  platform: A string, the platform the component is on {AWS,Azure}.
  items: A generator, an iterator (generator), of cluster versions that need
    to be looked at, to see if they are in end of life.

Returns:
  A table with cluster information (with annotations on whether the cluster
  can be upgraded), an end of life flag used to tell whether we need to add
  any additional hints.
F *T)r   r   r#   r   appenditer)r,   r   itemscluster_info_tableend_of_life_flagr   r   s          r   generate_cluster_versions_tablerK      sz     '>.a~~~'='=>>nn$a 	  
 r   c                     / nSn[        XR                  5       5      nU HE  n[        XVR                  5      (       a  U=R                  S-  sl        SnUR	                  U5        MG     [        U5      U4$ )aL  Generates a table of user's node pool(s) based on cluster and then adds a "*" to the version that can be upgraded.

Args:
  cluster_ref: A resource object, the parent cluster resource information.
  platform: A string, the platform the component is on {AWS,Azure}.
  items: A generator, an iterator (generator), of cluster versions that need
    to be looked at, to see if they are in end of life.

Returns:
  A table with node pool information (with annotations on whether the node
  pool can be upgraded), an end of life flag used to tell whether we need to
  add any additional hints.
FrE   T)r   r"   r   r   rF   rG   )r,   r   rH   node_pool_info_tablerJ   r   r   s          r   !generate_node_pool_versions_tablerN     sv     '2D2D2FG.a~yy11ii4i"	   
 r   N)__doc__
__future__r   r   r   .googlecloudsdk.api_lib.container.gkemulticloudr   r	   2googlecloudsdk.command_lib.container.gkemulticloudr   r9   r8   r?   rB   r(   r'   r+   r   r   r1   r=   r@   rC   rK   rN    r   r   <module>rT      s~    '  ' P H 
+ '   
) % *( F'T,@8r   