
    p                         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	j                        Zy)z+Command for getting a target pool's health.    )absolute_import)division)unicode_literals)base_classes)utils)base)flagsc                   0    e Zd ZdZdZed        Zd Zd Zy)	GetHealthzrGet the health of instances in a target pool.

  *{command}* displays the health of instances in a target pool.
  Nc                 p    t        j                         | _        | j                  j                  |d       y )Nzget health information for)operation_type)r	   TargetPoolArgumentTARGET_POOL_ARGAddArgument)clsparsers     .lib/surface/compute/target_pools/get_health.pyArgszGetHealth.Args%   s2    224C##; $ =    c           
          |j                  |j                  j                  d|j                  j	                  |j
                  |j                  |j                               fg      }|d   S )z!Fetches the target pool resource.Get)projectregion
targetPoolr   )MakeRequestsapitools_clienttargetPoolsmessagesComputeTargetPoolsGetRequestr   r   Name)selfclienttarget_pool_refobjectss       r   GetTargetPoolzGetHealth.GetTargetPool+   sn    !!

 
 
,
,e
//
6
6%--$++(--/ 7 1
2 	34G 1:r   c              #     K   t        j                  | j                               }|j                  }| j                  j                  ||j                  t        j                  |            }| j                  ||      }|j                  }|syg }|D ]  }|j                  j                  |j                  j                  |      |j                  |j                  |j!                               }	|j#                  |j$                  j&                  d|	f        g }
|j)                  ||
      }|D ]  }|  |
rt+        j,                  |
d       yyw)	z3Returns a list of TargetPoolInstanceHealth objects.)scope_listerN)instance)instanceReferencer   r   r   r   )requestserrors_to_collectz&Could not get health for some targets:)error_message)r   ComputeApiHolderReleaseTrackr"   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerr%   	instancesr   "ComputeTargetPoolsGetHealthRequestInstanceReferencer   r   r    appendr   r   r   r   RaiseToolException)r!   argsholderr"   r#   target_poolr3   r*   r(   request_messageerrorsr0   resources                r   RunzGetHealth.Run5   s^    **4+<+<+>?F]]F**<<"88@ = BO $$V_=K%%I HJJ"OO== > !!)) ''$))+ K -o oov--99;&( )  F##  $ "I n  
@B s   EE)	__name__
__module____qualname____doc__r   classmethodr   r%   r>    r   r   r   r      s+    
 /= =
'Br   r   N)rB   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r1   /googlecloudsdk.command_lib.compute.target_poolsDescribeCommandr   rD   r   r   <module>rK      s6     2 &  ' 7 0 ( E A?B$$ ?Br   