
    6                     ^    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddZddZ G d	 d
e	      Z
y)z,Utilities for Cloud Monitoring Policies API.    )absolute_import)division)unicode_literals)apisc                 2    t        j                  dd|       S )N
monitoringv3no_http)r   GetClientInstancer
   s    1lib/googlecloudsdk/api_lib/monitoring/policies.pyr   r      s    			dG	DD    Nc                 6    | xs
 t               } | j                  S N)r   MESSAGES_MODULE)clients    r   GetMessagesModuler      s    (&(&			r   c                   4    e Zd ZdZddZd Zd Zd	dZd	dZy)
AlertPolicyClientzFClient for the Alert Policy service in the Stackdriver Monitoring API.Nc                     |xs
 t               | _        |xs t        |      | _        | j                  j                  | _        y r   )r   r   r   messagesprojects_alertPolicies_service)selfr   r   s      r   __init__zAlertPolicyClient.__init__$   s5    /-/DK9 1& 9DMKK66DMr   c                     | j                   j                  |j                         |      }| j                  j	                  |      S )z&Creates a Stackdriver alerting policy.)namealertPolicy)r   ,MonitoringProjectsAlertPoliciesCreateRequestRelativeNamer   Create)r   project_refpolicyreqs       r   r!   zAlertPolicyClient.Create)   sB    
--
D
D%%' E C ==$$r   c                     | j                   j                  |j                               }| j                  j	                  |      S )z Gets an Monitoring Alert Policy.)r   )r   )MonitoringProjectsAlertPoliciesGetRequestr    r   Get)r   
policy_refrequests      r   r'   zAlertPolicyClient.Get0   s=    mmEE$$& F (G==W%%r   c                     | j                   j                  |j                         |xs d      }| j                  j	                  |      S )a  List Monitoring Alert Policies.

    "list_filter" must be a valid filter expression or an empty value. For more
    information, see
    https://cloud.google.com/monitoring/api/v3/sorting-and-filtering

    Args:
      project_ref: resources.Resource, Resource reference to the policy to be
        updated.
      list_filter: str, filter to be included in the ListAlertPOliciesRequest.

    Returns:
      Alert policies that match the given filter. If no filter is given, fetches
      all policies from the target project.
     )r   filter)r   *MonitoringProjectsAlertPoliciesListRequestr    r   List)r   r"   list_filterr)   s       r   r.   zAlertPolicyClient.List6   sH      mmFF%%'0Ar G G ==g&&r   c                     | j                   j                  |j                         ||      }| j                  j	                  |      S )a  Updates a Monitoring Alert Policy.

    If fields is not specified, then the policy is replaced entirely. If
    fields are specified, then only the fields are replaced.

    Args:
      policy_ref: resources.Resource, Resource reference to the policy to be
          updated.
      policy: AlertPolicy, The policy message to be sent with the request.
      fields: str, Comma separated list of field masks.
    Returns:
      AlertPolicy, The updated AlertPolicy.
    )r   r   
updateMask)r   +MonitoringProjectsAlertPoliciesPatchRequestr    r   Patch)r   r(   r#   fieldsr)   s        r   UpdatezAlertPolicyClient.UpdateK   sG     mmGG$$& H G ==w''r   )NNr   )	__name__
__module____qualname____doc__r   r!   r'   r.   r5    r   r   r   r   !   s    N7
%&'*(r   r   )Fr   )r9   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   r   objectr   r:   r   r   <module>r>      s-    3 &  ' ,E 
<( <(r   