
    a                         d Z ddlmZ ddlmZ ddlmZ ddlmZ dej                  fdZde	fd	Z
dej                  fd
Zdej                  fdZdee	   fdZdej                  fdZdej                  fdZy)z6Modify request hooks, specifically for health-sources.    )absolute_import)division)unicode_literals)	resourcesresource_refc                 <    | j                   |j                   _        |S )zModify the request message, carrying resource name into it.

  Args:
    resource_ref: the resource reference.
    request_msg: the request message constructed by the framework

  Returns:
    the modified request message.
  )healthSourcename)r   _request_msgs      Ilib/googlecloudsdk/api_lib/compute/health_sources/modify_request_hooks.pyadd_name_to_payloadr      s     #/";";+	    health_aggregation_policyc                 f   d|v r|S d|v rHt         j                  j                  |d| j                         j                        j                         S t         j                  j                  |d| j                         j                  | j                  | j                  d      j                         S )a  Helper function for parsing the health aggregation policy string.

  Args:
    resource_ref: the resource reference.
    health_aggregation_policy: the health aggregation policy string to parse.

  Returns:
    the parsed health aggregation policy self link.
  ://	projects/z'compute.regionHealthAggregationPolicies
collectionapi_versionprojectregionr   r   params)r   REGISTRYParseGetCollectionInfor   SelfLinkr   r   )r   r   s     r   parse_health_aggregation_policyr    )   s      ''$$ //##!< 224@@ $  hj	 
			!	!:002>>%--9L9LM	 
" 

 HJr   c                 l    |j                   s|S t        | |j                         |j                  _        |S a  Modify the request message, parsing the health aggregation policy.

  Args:
    resource_ref: the resource reference.
    args: the arguments passed to the command.
    request_msg: the request message constructed by the framework

  Returns:
    the modified request message.
  )r   r    r	   healthAggregationPolicyr   argsr   s      r   &parse_health_aggregation_policy_creater&   N   s>     
	'	' &
66 2
 
r   c                 l    |j                   s|S t        | |j                         |j                  _        |S r"   )r   r    healthSourceResourcer#   r$   s      r   &parse_health_aggregation_policy_updater)   h   s>      
	'	' &
66 "":
 
r   sourcesc                    g }|D ]  }d|v r|j                  |       d|v rX|j                  t        j                  j                  |d| j	                         j
                        j                                u|j                  t        j                  j                  |d| j	                         j
                  | j                  | j                  d      j                                 |S )zHelper function for parsing the sources list.

  Args:
    resource_ref: the resource reference.
    sources: the list of sources to parse.

  Returns:
    the list of parsed sources self links.
  r   r   zcompute.regionBackendServicesr   r   r   )	appendr   r   r   r   r   r   r   r   )r   r*   resultsources       r   parse_sourcesr/      s     &f mmF 
	mm



"
"8&88:FF #  HJ mm



"
"8&88:FF)11(//	 #  HJ
' < 
-r   c                     |j                   s|S |j                  j                   j                          |j                  j                   j                  t	        | |j                                |S a
  Modify the request message, parsing the sources list.

  Args:
    resource_ref: the resource reference.
    args: the arguments passed to the command.
    request_msg: the request message constructed by the framework

  Returns:
    the modified request message.
  )r*   r	   clearextendr/   r$   s      r   parse_sources_creater4      sY     
""((*""))L$,,/ 
r   c                     |j                   s|S |j                  j                   j                          |j                  j                   j                  t	        | |j                                |S r1   )r*   r(   r2   r3   r/   r$   s      r   parse_sources_updater6      sY      
""**002""**11L$,,/ 
r   N)__doc__
__future__r   r   r   googlecloudsdk.corer   Resourcer   strr    r&   r)   listr/   r4   r6    r   r   <module>r>      s    = &  ' )$$$"-0"J$$4$$6*c *Z$$2$$r   