
    7                         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
mZ ddlmZ ddlmZ d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)z3Helpers for the container cluster related commands.    )absolute_import)division)unicode_literalsN)util)base)admin_users)fleet)resource_args)robin)flags)	resourcesc                 B   t        j                  |      }t        |       }|j                  |j	                         |j
                  |j                         j                               }t        |||        |t        j                  j                  k(  rt        ||        |S )zGet cluster create request message.

  Args:
    args: comand line arguments.
    release_track: release track of the command.

  Returns:
    message obj, cluster create request message.
  )cluster	clusterIdparent)r   GetMessagesModuleGetClusterReference3EdgecontainerProjectsLocationsClustersCreateRequestCluster
clustersIdParentRelativeNamePopulateClusterMessager   ReleaseTrackALPHAPopulateClusterAlphaMessage)argsrelease_trackmessagescluster_refreqs        :lib/googlecloudsdk/api_lib/edge_cloud/container/cluster.pyGetClusterCreateRequestr#   !   s     ##M2(#D)+DD &&!..0 	E 	#
 h-d''---T*	*    c                    t        j                  |      }t        |       }|j                         }| j                  |_        | j                  j                         dk7  rt        d| j                  z         |j                  j                  | j                  j                               |_        |j                         }|j                         |_        ||_        |S )zGet cluster upgrade request message.

  Args:
    args: comand line arguments.
    release_track: release track of the command.

  Returns:
    message obj, cluster upgrade request message.
  IMMEDIATELYzUnsupported --schedule value: )r   r   r   UpgradeClusterRequestversiontargetVersionscheduleupper
ValueErrorScheduleValueValuesEnum4EdgecontainerProjectsLocationsClustersUpgradeRequestr   nameupgradeClusterRequest)r   r   r   r    upgrade_cluster_reqr!   s         r"   GetClusterUpgradeRequestr2   8   s     ##M2(#D)+ 668&*ll#	]]m+
5E
FF$$<<
--


 
 	EEG#%%'#(1#	*r$   c                    |j                         | j                  _        |j                  g| j                  j                  _        |j
                  g| j                  j                  _        t        j                  |d      r$t        |j                        | j                  _        t        j                  |d      r|j                  j                         | j                  _        g | j                  j                  _        |j                  j!                         D ]f  \  }}|j                  j                  j#                         }||_        ||_        | j                  j                  j                  j)                  |       h t        j                  |d      s-t        j                  |d      st        j                  |d      r|j+                         | j                  _        |j/                         | j                  j,                  _        |j3                         | j                  j,                  j0                  _        t        j                  |d      r9|j6                  | j                  j,                  j0                  j4                  _        |j;                         | j                  j,                  j0                  j4                  _        t        j                  |d      rC|j<                  | j                  j,                  j0                  j4                  j0                  _        t        j                  |d      rC|j@                  | j                  j,                  j0                  j4                  j0                  _!        t        j                  |d      rD|jE                         | j                  _#        |jH                  | j                  jF                  _%        t        j                  |d      rD|jM                         | j                  _'        |jP                  | j                  jN                  _%        tS        jT                  |||        tW        jX                  t[        |      ||        t        j                  |d      r|j\                  | j                  _/        t        j                  |d	      r|j`                  | j                  _1        t        j                  |d
      rB|j                  je                  |jf                  ji                               | j                  _5        t        j                  |d      s-t        j                  |d      st        j                  |d      r|jm                         | j                  _7        |jq                         | j                  jn                  _9        t        j                  |d      r/|jt                  | j                  jn                  jr                  _;        t        j                  |d      r8t        |jx                        | j                  jn                  jr                  _=        t        j                  |d      r/|j|                  | j                  jn                  jr                  _?        t        j                  |d      rV|jp                  j                  |j                  ji                               | j                  jn                  jr                  _B        t        j                  |d      rp| j                  j                  s|j                         | j                  _C        t        j                  |j                        dz   | j                  j                  _H        t        j                  |d      r/|j                  | j                  jn                  jr                  _J        t        | ||       t        | ||       y)zFill the cluster message from command arguments.

  Args:
    req: create cluster request message.
    messages: message module of edgecontainer cluster.
    args: command line arguments.
  default_max_pods_per_nodelabelsmaintenance_window_recurrencemaintenance_window_startmaintenance_window_endcontrol_plane_kms_keyzone_storage_kms_keyexternal_lb_ipv4_address_poolsr(   release_channelcontrol_plane_node_locationcontrol_plane_node_countcontrol_plane_machine_filter&control_plane_shared_deployment_policyoffline_reboot_ttls!control_plane_node_storage_schemaN)MClusterNetworkingr   
networkingcluster_ipv4_cidrclusterIpv4CidrBlocksservices_ipv4_cidrservicesIpv4CidrBlocksr   FlagIsExplicitlySetintr4   defaultMaxPodsPerNoder   LabelsValuer5   additionalPropertiesitemsAdditionalPropertykeyvalueappendMaintenancePolicymaintenancePolicyMaintenanceWindowwindowRecurringTimeWindowrecurringWindowr6   
recurrence
TimeWindowr7   	startTimer8   endTimeControlPlaneEncryptioncontrolPlaneEncryptionr9   kmsKeyZoneStorageEncryptionzoneStorageEncryptionr:   r   SetAdminUsersr	   SetFleetProjectPathr   r;   $externalLoadBalancerIpv4AddressPoolsr(   r)   ReleaseChannelValueValuesEnumr<   r+   releaseChannelControlPlanecontrolPlaneLocallocalr=   nodeLocationr>   	nodeCountr?   machineFilter%SharedDeploymentPolicyValueValuesEnumr@   sharedDeploymentPolicysurvivabilityConfigSurvivabilityConfigjsondumpsrA   offlineRebootTtlrC   controlPlaneNodeStorageSchemaSetContainerRuntimeConfigEnableGoogleGroupAuthentication)r!   r   r   rQ   rR   vs         r"   r   r   S   s    $557#++262H2H1I#++.373J3J2K#++/
t%@A(+D,J,J(KCKK%
tX.!))557CKK.0CKK+kk'')
U



&
&
9
9
;aaeag	kk--44Q7	 * &EF		"	"4)C	D		"	"4)A	B$,$>$>$@CKK!+3+E+E+GCKK!!($$& KK!!((8   'FG

,
, 
kk##**::E 	 KK!!((88?   'AB

'
' 
kk##**::AAK   '?@

%
% 
kk##**::AAI t%<=)1)H)H)JCKK&040J0JCKK&&-
t%;<(0(F(F(HCKK%/3/H/HCKK%%,HdC0/5tSA
t%EF++ KK4 tY/ $CKK
t%67!)!1!1!O!O""$"CKK &CD		"	"4)C	D		"	"4)G	H  (446CKK%-^^%5CKK"  'DE

*
* 
kk$$1   'AB14

'
'2ckk$$.   'EF

+
+ 
kk$$2   6 ..
>
>99??A 
kk$$;
 t%9:;;**(0(D(D(Fckk%

4**+c1 KK##4 t%HI.. KK""@ Cx0!#tX6r$   c                    t        j                  |d      r&|j                  g| j                  j                  _        t        j                  |d      r&|j                  g| j                  j                  _        t        j                  |d      r|j                  | j                  _	        t        j                  ||        t        j                  ||        t        | |       t        | |       t        j                  |d      rt        j                   | |       t#        j$                  t&        j(                  j*                        }t        j                  |d      rt-        | ||       yy)zFilled the Alpha cluster message from command arguments.

  Args:
    req: create cluster request message.
    args: command line arguments.
  cluster_ipv6_cidrservices_ipv6_cidrexternal_lb_ipv6_address_poolsenable_robin_cns,control_plane_node_system_partition_size_gibN)r   rJ   r{   r   rE   clusterIpv6CidrBlocksr|   servicesIpv6CidrBlocksr}   $externalLoadBalancerIpv6AddressPoolsr
   SetSystemAddonsConfig)SetExternalLoadBalancerAddressPoolsConfigEnableClusterIsolationConfigEnableRemoteBackupConfigr   EnableRobinCNSInRequestr   r   r   r   r   &SetControlPlaneNodeSystemPartitionSizer!   r   r   s      r"   r   r      s    t%89484J4J3KCKK0
t%9:595L5L4MCKK1
t%EF++ KK4 %%dC099$DsD)3%
t%78	!!#t,##D$5$5$;$;<(

: +3h?r$   c                     t        j                  | d      rCt        j                  | d      r-t        j                  | d      st        j                  | d      ryy)zIdentify if the command is creating LCP cluster.

  Args:
    args: command line arguments.

  Returns:
    Boolean, indication of LCP cluster.
  r=   r>   r;   external_lb_address_poolsTFr   rJ   r   s    r"   IsLCPClusterr      sP     &CD

#
#D*D
E

#
#D*J
K&&t-HI 	r$   c                 2    t        j                  | d      ryy)zIdentify if the command is requesting an offline credential for LCP cluster.

  Args:
    args: command line arguments.

  Returns:
    Boolean, indication of requesting offline credential.
  offline_credentialTFr   r   s    r"   IsOfflineCredentialr      s     t%9:	r$   c                     t         j                  j                  | j                  j                  j                         j                         d      S )zGet edgecontainer cluster resources.

  Args:
    args: command line arguments.

  Returns:
    edgecontainer cluster resources.
  z)edgecontainer.projects.locations.clusters)
collection)r   REGISTRYParseRelativeNameCONCEPTSr   Parser   r   s    r"   r   r      sD     
			-	-
mm!!#002< 
. 
 r$   c                     t        j                  |      }| j                  j                  |j                  j
                  j                  k(  r| j                  j                  	 yy)zValidate cluster create request message.

  Args:
    req: Create cluster request message.
    release_track: Release track of the command.

  Returns:
    Single string of error message.
  NzSInvalid Argument: REGULAR release channel does not support specification of version)r   r   r   rg   r   rf   REGULARr)   )r!   r   r   s      r"   ValidateClusterCreateRequestr     s[     ##M2(	kk  				7	7	?	?@
++
#
#
/	$ 
r$   c                    t        j                  |d      r|j                         | j                  _        |j
                  j                         dk(  r:|j                  j                  j                  | j                  j                  _	        y|j
                  j                         dk(  r:|j                  j                  j                  | j                  j                  _	        yt        d|j
                  z         y)zSet container runtime config in the cluster request message.

  Args:
    req: Create cluster request message.
    args: Command line arguments.
    messages: Message module of edgecontainer cluster.
  container_default_runtime_classGVISORRUNCz5Unsupported --container_default_runtime_class value: N)r   rJ   ContainerRuntimeConfigr   containerRuntimeConfigr   r+   &DefaultContainerRuntimeValueValuesEnumr   defaultContainerRuntimer   r,   r   s      r"   rw   rw   %  s     t%FG)1)H)H)JCKK&++113x?

)
)
P
P
W
W 
kk((@ 
	-	-	3	3	5	?

)
)
P
P
U
U 
kk((@ 
A001  Hr$   c                    t        j                  |d      rv|j                  j                         dk(  rd| j                  _        y|j                  j                         dk(  rd| j                  _        yt        d|j                  z         y)zSet secure cluster isolation config in the cluster request message.

  Args:
   req: Create cluster request message.
   args: Command line arguments.
  enable_cluster_isolationTRUETFALSEFz.Unsupported --enable_cluster_isolation value: N)r   rJ   r   r+   r   enableClusterIsolationr,   r!   r   s     r"   r   r   >  s     t%?@$$**,6+/ckk(		&	&	,	,	.'	9+0ckk(
:))*  Ar$   c                     t        j                  |d      rE|j                         | j                  _        |j
                  | j                  j                  _        yy)zSet Google Group authentication config in the cluster request message.

  Args:
   req: Create cluster request message.
   args: Command line arguments.
   messages: Message module of edgecontainer cluster.
  "enable_google_group_authenticationN)r   rJ   GoogleGroupAuthenticationConfigr   googleGroupAuthenticationr   enabler   s      r"   rx   rx   R  sP     t%IJ002 KK) 	// KK))0	 Kr$   c                 h    t        j                  |d      r|j                  | j                  _        yy)zSet remote backup config in the cluster request message.

  Args:
   req: Create cluster request message.
   args: Command line arguments.
  enable_remote_backupN)r   rJ   r   r   enableRemoteBackupr   s     r"   r   r   c  s,     t%;<%)%>%>CKK" =r$   c                    |j                   dk(  rD|j                  j                  j                  | j                  j
                  j                  _        y|j                   dk(  rD|j                  j                  j                  | j                  j
                  j                  _        yt        d|j                   z   dz         )zSet control plane node system partition size in the cluster request message.

  Args:
   req: Create cluster request message.
   args: Command line arguments.
   messages: Message module of edgecontainer cluster.
  d   i,  zBUnsupported --control_plane_node_system_partition_size_gib value: z; valid values are 100 and 300.N)
r   rj   2ControlPlaneNodeSystemPartitionSizeValueValuesEnumSYSTEM_PARTITION_GIB_SIZE100r   ri   rk   #controlPlaneNodeSystemPartitionSizeSYSTEM_PARTITION_GIB_SIZE300r,   r   s      r"   r   r   o  s     
66#=IIff KK""F 88C?IIff KK""F L

;
;	<
+	, r$   ) __doc__
__future__r   r   r   rs   +googlecloudsdk.api_lib.edge_cloud.containerr   googlecloudsdk.callioper   /googlecloudsdk.command_lib.edge_cloud.containerr   r	   r
   r   googlecloudsdk.command_lib.runr   googlecloudsdk.corer   r#   r2   r   r   r   r   r   r   rw   r   rx   r   r    r$   r"   <module>r      sr    : &  '  < ( G A I A 0 ).6i7X@:*.2(1"	?r$   