
    K                     ~    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  G d
 de      Zy)zNode group api client.    )absolute_import)division)unicode_literals)utils)poller)waiter)util)mapc                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Z	 	 	 	 	 ddZy
)NodeGroupsClientz.Client for node groups service in the GCE API.c                 d    || _         || _        || _        | j                   j                  | _        y N)clientmessages	resources
nodeGroups_service)selfr   r   r   s       >lib/googlecloudsdk/api_lib/compute/sole_tenancy/node_groups.py__init__zNodeGroupsClient.__init__   s(    DKDMDNKK**DM    c                    t        j                  | j                  ||j                  t	        j
                  |j                              }| j                  j                  |j                               }| j                  j                  ||j                         |j                  |j                        }| j                  j                  |      S )z/Sets the node template field on the node group.)projectregion)nodeTemplate) nodeGroupsSetNodeTemplateRequest	nodeGroupr   zone)r	   ParseNodeTemplater   r   compute_utilZoneNameToRegionNamer   r    NodeGroupsSetNodeTemplateRequestRelativeName'ComputeNodeGroupsSetNodeTemplateRequestNamer   SetNodeTemplate)r   node_group_refnode_templatenode_template_refset_requestrequests         r   r&   z NodeGroupsClient.SetNodeTemplate%   s    ..&&001D1DE	G
 --@@&335 A 7KmmCC)4 %%'&&  	 D "G
 ==((11r   c                     | j                   j                  | j                   j                  |      |j                         |j                  |j
                        }| j                  j                  |      S )N)additionalNodeCount)nodeGroupsAddNodesRequestr   r   r   )r    ComputeNodeGroupsAddNodesRequestNodeGroupsAddNodesRequestr%   r   r   r   AddNodes)r   r'   additional_node_countr+   s       r   r1   zNodeGroupsClient.AddNodes5   sk    mm<<"&--"I"I 5 #J #7 %%'&&   = "G ==!!'**r   c                     | j                   j                  | j                   j                  |      |j                         |j                  |j
                        }| j                  j                  |      S )N)nodes)nodeGroupsDeleteNodesRequestr   r   r   )r   #ComputeNodeGroupsDeleteNodesRequestNodeGroupsDeleteNodesRequestr%   r   r   r   DeleteNodes)r   r'   r4   r+   s       r   r8   zNodeGroupsClient.DeleteNodes>   sl    mm??%)]]%O%O &P & %%'&&   @ "G ==$$W--r   c                 2   t        j                  || j                        }| j                  j                  |      }| j                  j	                  ||j                         |j                  |j                        }| j                  j                  |      S )z,Sets the autoscaling policy on a node group.)autoscalingPolicynodeGroupResourcer   r   r   )
r	   BuildAutoscalingr   	NodeGroupComputeNodeGroupsPatchRequestr%   r   r   r   Patch)r   r'   argsautoscaling_policy_refr*   r+   s         r   r@   zNodeGroupsClient.PatchG   s    !224G--))0 * 2Kmm99% %%'&&  	 : "G
 ==w''r   c                 2   t        j                  | j                  |      }| j                  j                  |      }| j                  j	                  ||j                         |j                  |j                        }| j                  j                  |      S )z'Sets the share setting on a node group.)shareSettingsr;   )
r	   BuildShareSettingsr   r>   r?   r%   r   r   r   r@   )r   r'   share_settingshare_setting_refr*   r+   s         r   UpdateShareSettingz#NodeGroupsClient.UpdateShareSettingS   s    //}M--))8I)JKmm99% %%'&&  	 : "G
 ==w''r   c                 P    | j                   j                  |j                  d      S )Nzcompute.zoneOperations)
collection)r   ParseselfLink)r   	operations     r   _GetOperationsRefz"NodeGroupsClient._GetOperationsRef^   s+    >>	 2 2+C   E Er   c                 6    |rt        j                  |||      S y r   )r   WaitFor)r   operation_polleroperation_refmessages       r   _WaitForResultzNodeGroupsClient._WaitForResultb   s    ^^,mWEEr   Nc                 X   d}d}d}	d}
d}|r#| j                  ||      }| j                  |      }|r#| j                  ||      }| j                  |      }|r#| j                  ||      }| j                  |      }	|r#| j	                  ||      }| j                  |      }
|r#| j                  ||      }| j                  |      }|j                         }t        j                  | j                        }d}| j                  ||dj                  ||            xs |}| j                  ||dj                  ||            xs |}dj                  t        t        |xs g             }| j                  ||	dj                  ||            xs |}g }|r|j                  r,dj                  |j                        }|j!                  |       |j#                  d      r,dj                  |j$                        }|j!                  |       |j#                  d	      r,d
j                  |j&                        }|j!                  |       dj                  |      }| j                  ||
dj                  ||            xs |}g }|rsdj                  |j(                        }|j!                  |       |j*                  r;dj                  dj                  |j*                              }|j!                  |       dj                  |      }| j                  ||dj                  ||            xs |}|S )zUpdates a Compute Node Group.Nz(Setting node template on [{0}] to [{1}].zAdding [{0}] nodes to [{1}].,zDeleting nodes [{0}] in [{1}].zautoscaler-mode={0}	min_nodeszmin-nodes={0}	max_nodeszmax-nodes={0}z.Updating autoscaling policy on [{0}] to [{1}].zshare-setting={0}zshare-with={0}z)Updating share setting on [{0}] to [{1}].)r&   rN   r1   r8   r@   rH   r%   r   Pollerr   rT   formatjoinr
   strautoscaler_modeappendIsSpecifiedrW   rX   rF   
share_with)r   r'   r(   r2   delete_nodesautoscaling_policy_argsshare_setting_argsset_node_template_refadd_nodes_refdelete_nodes_refrB   share_settings_refrM   node_group_namerQ   resultdeleted_nodes_strautoscaling_policy_str_listmode_strmin_strmax_strautoscaling_policy_strshare_setting_str_listtype_strwith_strshare_setting_strs                             r   UpdatezNodeGroupsClient.Updateg   sf    !M!&&~}Ei"44Y?--0EFi,,Y7m""><@i//	:**^-DEi#55i@)).:LMi11)<$))+O}}T]]3F  /299]	,- 7 17    -&--!?	45 ? 9?  S,*<"!=>  *(//	01 ; 5; 
 #%	 	0	0(//#335#**84	 	,	,[	9!(()@)J)JK#**73	 	,	,[	9!(()@)J)JK#**73 XX&AB  08??3	56 @ :@   $++,>,L,LMh##H-		&	&#**388)),+ ,%%h/!78  ,3::.	01 ; 5;  Mr   )NNNNN)__name__
__module____qualname____doc__r   r&   r1   r8   r@   rH   rN   rT   rt    r   r   r   r      sE    6+2 +.
(	(E  #'%) $Qr   r   N)rx   
__future__r   r   r   googlecloudsdk.api_lib.computer   r    )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   ;googlecloudsdk.command_lib.compute.sole_tenancy.node_groupsr	   	six.movesr
   objectr   ry   r   r   <module>r      s0     &  ' @ < . L \v \r   