
    &                         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 Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)z5Helpers for the container node pool related commands.    )util)base)
exceptions)flags)labels_util)	resourcesc                     t         j                  j                  | j                  j                  j                         j                         d      S )zGet edgecontainer node pool resources.

  Args:
    args: command line arguments.

  Returns:
    edgecontainer node pool resources.
  z3edgecontainer.projects.locations.clusters.nodePools)
collection)r   REGISTRYParseRelativeNameCONCEPTS	node_poolParseRelativeName)argss    ;lib/googlecloudsdk/api_lib/edge_cloud/container/nodepool.pyGetNodePoolReferencer      sD     
			-	-
mm##%224F 
. 
     c                     t        j                  |      }|j                  | j                  j                  j                         j                               }|S )zGet node pool get request message.

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

  Returns:
    message obj, node pool get request message.
  )name)r   GetMessagesModule9EdgecontainerProjectsLocationsClustersNodePoolsGetRequestr   r   r   r   )r   release_trackmessagesreqs       r   GetNodePoolGetRequestr   (   sP     ##M2(JJ==""((*779 	K 	# 
*r   c                 B   t        j                  |      }t        |       }|j                  |j	                         |j
                  |j                         j                               }t        |||        |t        j                  j                  k(  rt        ||        |S )zGet node pool create request message.

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

  Returns:
    message obj, node pool create request message.
  )nodePool
nodePoolIdparent)r   r   r   <EdgecontainerProjectsLocationsClustersNodePoolsCreateRequestNodePoolnodePoolsIdParentr   PopulateNodePoolCreateMessager   ReleaseTrackALPHA"PopulateNodePoolAlphaCreateMessage)r   r   r   node_pool_refr   s        r   GetNodePoolCreateRequestr*   9   s     ##M2(&t,-MM  "**!!#002 	N 	#
  Xt4d''---&sD1	*r   c                     t        j                  |      }|j                  | j                  j                  j                         j                         |j                               }g }t        ||| ||       dj                  |      |_
        |S )zGet node pool update request message.

  Args:
    args: comand line arguments.
    release_track: release track of the command.
    existing_node_pool: existing node pool.

  Returns:
    message obj, node pool update request message.
  )r   r   ,)r   r   ;EdgecontainerProjectsLocationsClustersNodePoolsPatchRequestr   r   r   r   r"   PopulateNodePoolUpdateMessagejoin
updateMask)r   r   existing_node_poolr   r   update_mask_piecess         r   GetNodePoolUpdateRequestr3   P   s     ##M2(LL==""((*779  " 	M 	# 	8T-/A 88./#.	*r   c                 j   t        |j                        | j                  _        |j                  | j                  _        t        j                  |d      r|j                  | j                  _	        t        j                  |d      rD|j                         | j                  _        |j                  | 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      r|j/                         | j                  _        |j.                  j                         | j                  j0                  _        g | j                  j0                  j                   _        |j2                  j%                         D ]p  \  }}|j.                  j                  j'                         }||_        ||_        | j                  j0                  j                   j"                  j-                  |       r t        j                  |d      r[| j                  j0                  s|j/                         | j                  _        |j4                  | j                  j0                  _        yy)zFill the node pool message from command arguments.

  Args:
    req: create node pool request message.
    messages: message module of edgecontainer node pool.
    args: command line arguments.
  machine_filterlocal_disk_kms_keylabelsnode_labelsnode_storage_schemaN)int
node_countr   	nodeCountnode_locationnodeLocationr   FlagIsExplicitlySetr5   machineFilterLocalDiskEncryptionlocalDiskEncryptionr6   kmsKeyr"   LabelsValuer7   additionalPropertiesitemsAdditionalPropertykeyvalueappend
NodeConfig
nodeConfigr8   r9   nodeStorageSchema)r   r   r   rH   rI   vs         r   r%   r%   h   sE    t/#,,"00#,,
t%56!%!4!4CLL
t%9:'/'C'C'ECLL$.2.E.ECLL$$+
tX."++779CLL/1CLL,kk'')
U



'
'
:
:
<aaeag	ll..55a8	 *
 t]3&113CLL%-%8%8%D%D%FCLL":<CLL""7&&,,.
U



)
)
<
<
>aaeag	ll$$99@@C	 /
 t%:;<<"" ( 3 3 5cll040H0HCLL- <r   c                    t        j                  |d      rpt        j                  t        j
                  j                        }| j                  j                  s|j                         | j                  _        t        | ||       yy)zFill the Alpha create node pool message from command arguments.

  Args:
    req: create node pool request message.
    args: command line arguments.
  node_system_partition_size_gibN)r   r?   r   r   r   r&   r'   r   rL   rK   SetNodeSystemPartitionSizer   r   r   s      r   r(   r(      se     t%EF%%d&7&7&=&=>H<<"" ( 3 3 5cllsD(3	 Gr   c                 $   t        j                  |d      r,t        j                  |d      rt        j                  dd      t        j                  |d      rL|j	                  d       |j                         | j                  _        d| j                  j                  _        yt        j                  |d      rV|j	                  d       |j                         | j                  _        |j                  | j                  j                  _        yy)zFilled the Alpha node pool message from command arguments.

  Args:
    req: create node pool request message.
    messages: message module of edgecontainer node pool.
    update_mask_pieces: update masks.
    args: command line arguments.
  use_google_managed_keyr6   .--use-google-managed-key, --local-disk-kms-key$cannot be specified at the same timerB    N)
r   r?   r   InvalidArgumentExceptionrJ   rA   r   rB   rC   r6   )r   r   r2   r   s       r   "PopulateNodePoolUpdateAlphaMessagerY      s     
$!!$(<=

-
-8.  t%=>34'/'C'C'ECLL$.0CLL$$+

t%9:34'/'C'C'ECLL$.2.E.ECLL$$+
	 ;r   c                    t        j                  |d      r,|j                  d       |j                  | j                  _        t        j                  |d      r5|j                  d       t        |j                        | j                  _        t        j                  |      }t        j                  |      }|j                  j                  }t        j                  |||j                        j!                  ||j"                        }|j$                  r,|j                  d       |j"                  | j                  _        t        j                  |d      r|j                  d       |j'                         | j                  _        |j&                  j                         | j                  j(                  _        g | j                  j(                  j"                  _        |j,                  j/                         D ]p  \  }	}
|j&                  j                  j1                         }|	|_        |
|_        | j                  j(                  j"                  j*                  j                  |       r t        j                  |d	      r,t        j                  |d
      rt7        j8                  dd      t        j                  |d	      rK|j                  d       |j;                         | j                  _        d| j                  j<                  _        t        j                  |d
      rV|j                  d       |j;                         | j                  _        |j@                  | j                  j<                  _        yy)a  Fill the node pool message from command arguments.

  Args:
    req: update node pool request message.
    messages: message module of edgecontainer node pool.
    args: command line arguments.
    update_mask_pieces: update mask pieces.
    existing_node_pool: existing node pool.
  r5   r@   r;   r<   )	additionssubtractionsclearr7   r8   znodeConfig.labelsrT   r6   rU   rV   rB   rW   N)!r   r?   rJ   r5   r   r@   r:   r;   r<   r   GetUpdateLabelsDictFromArgsGetRemoveLabelsListFromArgsr"   rD   Diffclear_labelsApplyr7   needs_updaterK   rL   rE   r8   rF   rG   rH   rI   r   rX   rA   rB   rC   r6   )r   r   r   r2   r1   
add_labelsremove_labels
value_typelabel_update_resultrH   rI   rN   s               r   r.   r.      s    t%56o.!%!4!4CLL
t\2k* 1CLL66t<*99$?-  ,,*#((d>O>O	E*(//0  %%h'-44CLL
t]312&113CLL%-%8%8%D%D%FCLL":<CLL""7&&,,.
U



)
)
<
<
>aaeag	ll$$99@@C	 /
 
$!!$(<=

-
-8.  t%=>34'/'C'C'ECLL$.0CLL$$+
t%9:34'/'C'C'ECLL$.2.E.ECLL$$+ ;r   c                 \   |j                   dk(  r:|j                  j                  j                  | j                  j
                  _        y|j                   dk(  r:|j                  j                  j                  | j                  j
                  _        yt        d|j                   z   dz         )zSet node system partition size in the node pool request message.

  Args:
   req: Create node pool request message.
   args: Command line arguments.
   messages: Message module of edgecontainer node pool.
  d   i,  z4Unsupported --node_system_partition_size_gib value: z; valid values are 100 and 300.N)	rP   rK   &NodeSystemPartitionSizeValueValuesEnumSYSTEM_PARTITION_GIB_SIZE100r   rL   nodeSystemPartitionSizeSYSTEM_PARTITION_GIB_SIZE300
ValueErrorrR   s      r   rQ   rQ      s     
((C/BB__ LL3 **c1BB__ LL3 >

-
-	.
+	, r   N)__doc__+googlecloudsdk.api_lib.edge_cloud.containerr   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.runr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   r*   r3   r%   r(   rY   r.   rQ    r   r   <module>rv      sM    < < ( . 0 < )".0#IL483Flr   