
    &`iX                         d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ  e j        e          Z G d de
          ZdS )	    N)AnyDict)ClusterOperatorClient)bootstrap_vsphere)NodeProvider)STATUS_SETTING_UPTAG_RAY_CLUSTER_NAMETAG_RAY_NODE_NAMETAG_RAY_NODE_STATUSc                       e Zd ZdZdZd Zed             Zd Zd Z	d Z
d Zd	 Zd
 Zd Zdeeef         fdZd Zd ZdefdZdS )VsphereWcpNodeProvideri  Nc                     t          j        | ||           i | _        t          j                    | _        t          ||t          j                  | _	        d S N)
r   __init__	tag_cache	threadingLocktag_cache_lockr   r   cluster_configclient)selfprovider_configcluster_names      /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/_private/vsphere/node_provider.pyr   zVsphereWcpNodeProvider.__init__   sN    dO\BBB'n..+/+A+P
 
    c                 <    t          |           }|t          _        |S r   )r   r   r   )r   configs     r   bootstrap_configz'VsphereWcpNodeProvider.bootstrap_config    s    ">2206-r   c                    | j                             |          \  }}| j        5  |D ]h}||                                         D ]K\  }}|| j                                        v r|| j        |         |<   1i | j        |<   || j        |         |<   Li	 d d d            n# 1 swxY w Y   t                              d| j                    |S )NzNon terminated nodes' tags are )r   list_vmsr   itemsr   keysloggerinfo)r   tag_filtersnodesr   node_idkvs          r   non_terminated_nodesz+VsphereWcpNodeProvider.non_terminated_nodes&   s(   ;//<<y  	7 	7  7 7%g.4466 7 7DAq$."5"5"7"77756w/2224w/56w/2277	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	FdnFFGGGs   A,BB"%B"c                 6    | j                             |          S r   )r   is_vm_power_onr   r'   s     r   
is_runningz!VsphereWcpNodeProvider.is_running3   s    {))'222r   c                 p    | j                             |          rdS | j                             |           S )NF)r   r,   is_vm_creatingr-   s     r   is_terminatedz$VsphereWcpNodeProvider.is_terminated6   s:    ;%%g.. 	;5
 {11'::::r   c                 ^    | j         5  | j        |         cd d d            S # 1 swxY w Y   d S r   )r   r   r-   s     r   	node_tagsz VsphereWcpNodeProvider.node_tags?   sy      	+ 	+>'*	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   "&&c                 6    | j                             |          S r   r   get_vm_external_ipr-   s     r   external_ipz"VsphereWcpNodeProvider.external_ipC   s    {--g666r   c                 6    | j                             |          S r   r5   r-   s     r   internal_ipz"VsphereWcpNodeProvider.internal_ipF   s     {--g666r   c                     | j         5  |                                D ]\  }}|| j        |         |<   t                              d| d| j        |                     d d d            d S # 1 swxY w Y   d S )NzUpdated tags for z to: )r   r!   r   r#   r$   )r   r'   tagsr(   r)   s        r   set_node_tagsz$VsphereWcpNodeProvider.set_node_tagsK   s       	U 	U

 / /1-.w'**KKSGSS$.:QSSTTT		U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us   AA++A/2A/returnc           	         |}i }|dk    r| j                             |||          }| j        5  |                                D ]}|                                | j        |<   t          | j        |         t          <   || j        |         t          <   | j	        | j        |         t          <   t                              d| d| j        |                     	 ddd           n# 1 swxY w Y   |S )zuCreates instances.

        Returns dict mapping instance id to VM object for the created
        instances.
        r   zNode z created with tags: N)r   create_nodesr   r"   copyr   r   r   r
   r   r	   r#   r$   )r   node_configr;   countto_be_launched_node_countcreated_nodes_dictr'   s          r   create_nodez"VsphereWcpNodeProvider.create_nodeT   sE    %*!$q((!%!9!9/" "
   	 	-2244  *.))++w'?Pw'(;<=Dw'(9:@D@Qw'(<=RGRR9PRR   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 "!s   B(C##C'*C'c                     |r| j                             |          rd S | j                             |           | j        5  || j        v r| j                            |           d d d            d S # 1 swxY w Y   d S r   )r   r0   delete_noder   r   popr-   s     r   terminate_nodez%VsphereWcpNodeProvider.terminate_nodem   s     	$+44W== 	F(((  	, 	,$.((""7+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s    $A11A58A5c                 B    |sd S |D ]}|                      |           d S r   )rI   )r   node_idsr'   s      r   terminate_nodesz&VsphereWcpNodeProvider.terminate_nodesv   s?     	F 	) 	)G((((	) 	)r   c                 4    | j                                         S r   )r   safe_to_scale)r   s    r   rN   z$VsphereWcpNodeProvider.safe_to_scale|   s    {((***r   )__name__
__module____qualname__max_terminate_nodesr   r   staticmethodr   r*   r.   r1   r3   r7   r9   r<   r   strr   rE   rI   rL   boolrN    r   r   r   r      s       N
 
 
   \
  3 3 3; ; ;+ + +7 7 77 7 7
U U U"tCH~ " " " "2, , ,) ) )+t + + + + + +r   r   )loggingr   typingr   r   7ray.autoscaler._private.vsphere.cluster_operator_clientr   &ray.autoscaler._private.vsphere.configr   ray.autoscaler.node_providerr   ray.autoscaler.tagsr   r	   r
   r   	getLoggerrO   r#   r   rV   r   r   <module>r^      s                     E D D D D D 5 5 5 5 5 5            
	8	$	$i+ i+ i+ i+ i+\ i+ i+ i+ i+ i+r   