
    2                         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	Z G d
 de      Zd Zd Zd Zd Zy)zCloud vmware API utilities.    )absolute_import)division)unicode_literalsN)apis)waiter)	resourcesv1c                   t    e Zd ZdZefdZed        Zed        Zd Z	d e
j                  d      fd	Zd
 Zy)VmwareClientBasez*Base class for vwmare API client wrappers.c                     t        j                  d|      | _        t        j                  d|      | _        d | _        | j                  j                  | _        y )Nvmwareengine)	r   GetClientInstance_clientGetMessagesModule	_messagesserviceclientprojects_locations_operationsoperations_service)selfapi_versions     )lib/googlecloudsdk/api_lib/vmware/util.py__init__zVmwareClientBase.__init__"   sC    )).+FDL++NKHDNDL"kkGGD    c                     | j                   S N)r   r   s    r   r   zVmwareClientBase.client(   s    <<r   c                     | j                   S r   )r   r   s    r   messageszVmwareClientBase.messages,   s    >>r   c                 X    t         j                  j                  |j                  d      S )zPConverts an Operation to a Resource that can be used with `waiter.WaitFor`.
    z*vmwareengine.projects.locations.operations)
collection)r   REGISTRYParseRelativeNamename)r   	operations     r   GetOperationRefz VmwareClientBase.GetOperationRef0   s.     //#O 0 Q Qr   Ti  )secondsc                     |r+t        j                  | j                  | j                        }nt        j                  | j                        }t        j
                  ||||j                  dz        S )a  Waits for an operation to complete.

    Polls the IDS Operation service until the operation completes, fails, or
    max_wait_seconds elapses.

    Args:
      operation_ref: a Resource created by GetOperationRef describing the
        operation.
      message: the message to display to the user while they wait.
      has_result: if True, the function will return the target of the operation
        when it completes. If False, nothing will be returned (useful for Delete
        operations)
      max_wait: The time to wait for the operation to succeed before returning.

    Returns:
      if has_result = True, an Endpoint entity.
      Otherwise, None.
    i  )max_wait_ms)r   CloudOperationPollerr   r   CloudOperationPollerNoResourcesWaitForr'   )r   operation_refmessage
has_resultmax_waitpollers         r   WaitForOperationz!VmwareClientBase.WaitForOperation6   sf    . **4<<+/+B+BDf 55d6M6MNf>>wH4D4Dt4KM Mr   c                 x    t        j                  | j                  | j                        }|j	                  |      S r   )r   r*   r   r   	GetResult)r   r%   r1   s      r   GetResponsezVmwareClientBase.GetResponseV   s/    ((t7N7NOFI&&r   N)__name__
__module____qualname____doc___DEFAULT_API_VERSIONr   propertyr   r   r&   datetime	timedeltar2   r5    r   r   r   r      s]    2!5 H    Q #' 2 2 24 @	M@'r   r   c                 *    | j                  d      d   S )N/)split)resource_names    r   GetResourceIdrD   [   s    			S	!"	%%r   c                    g }|D ]s  }|j                   dk(  r ||j                         }|j                  dkD  r|j                  |_        | j                  |j                  |      }|j                  |       u  | |      S )zConstructs a node configs API message.

  Args:
    map_class: The map message class.
    config_class: The config (map-entry) message class.
    nodes_configs: The list of nodes configurations.

  Returns:
    The constructed message.
  r   )	nodeCountkeyvalueadditionalProperties)countcustom_core_countcustomCoreCountAdditionalPropertytypeappend)	map_classconfig_classnodes_configs
propertiesnodes_confignode_type_configprops          r   #ConstructNodeParameterConfigMessagerY   _   s     *#lQ#l.@.@A%%))5)G)G&''%5 ( D d $ 

	33r   c           
         |sy |        }|j                   |_        |j                  |_        |j                  |_        i }|j                  j                         D ]  \  }} |       }|j                  |_	        |j                  |_        |j                  |_        |j                  |_        t!        |j"                  |      |_        t!        |j&                  |      |_        t!        |j*                  |      |_        t!        |j.                  |      |_        |||<    | j3                  |j                         D cg c]"  \  }}| j2                  j5                  ||      $ c}}      |_        |S c c}}w )aj  Constructs autoscaling settings API message.

  Args:
    settings_message_class: Top-level autoscaling settings message class.
    policy_message_class: Autoscaling policy message class.
    thresholds_message_class: Autoscaling policy thresholds message class.
    autoscaling_settings: Desired autoscaling settings.

  Returns:
    The constructed message.
  NrG   rJ   )min_cluster_node_countminClusterNodeCountmax_cluster_node_countmaxClusterNodeCountcool_down_periodcoolDownPeriodautoscaling_policiesitemsnode_type_id
nodeTypeIdscale_out_sizescaleOutSizemin_node_countminNodeCountmax_node_countmaxNodeCount_ConstructThresholdsMessagecpu_thresholdscpuThresholdsgranted_memory_thresholdsgrantedMemoryThresholdsconsumed_memory_thresholdsconsumedMemoryThresholdsstorage_thresholdsstorageThresholdsAutoscalingPoliciesValuerO   autoscalingPolicies)	settings_message_classpolicy_message_classthresholds_message_classautoscaling_settingssettings_messagepolicy_messagesr$   policypolicy_messages	            r   #ConstructAutoscalingSettingsMessager~   z   s   " 
+-11 & 11 & %9$I$I!/*??EEGldF)+N & 3 3N"("7"7N"("7"7N"("7"7N#>7$N  .I((*B.N* /J))+C/N+ (C!!#;(N$ +OD) H, *@)X)X )8(=(=(? )@$n !
9
9
L
Ln M (? *Y *& 
s   <'E3
c                 ^     |       }| y | j                   |_        | j                  |_        |S r   )scale_inscaleIn	scale_outscaleOut)
thresholdsrx   thresholds_messages      r   rk   rk      s8    /1)22 * 4 4	r   )r9   
__future__r   r   r   r<   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   r:   objectr   rD   rY   r~   rk   r>   r   r   <module>r      sI    " &  '  , . )  9'v 9'x&46;|r   