
?F[c           @   s   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 e f d     YZ	 d e
 f d	     YZ d
 e
 f d     YZ d S(   i(   t   datetime(   t   ListElement(   t	   Dimension(   t   json(   t   sixt   MetricAlarmsc           B   s&   e  Z d d   Z d   Z d   Z RS(   c         C   s   t  j |   | |  _ d S(   s0   
        Parses a list of MetricAlarms.
        N(   t   listt   __init__t
   connection(   t   selfR   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR      s    c         C   s-   | d k r) t  |  } |  j |  | Sd  S(   Nt   member(   t   MetricAlarmt   append(   R	   t   namet   attrsR   t   metric_alarm(    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   startElement&   s    c         C   s   d  S(   N(    (   R	   R   t   valueR   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt
   endElement,   s    N(   t   __name__t
   __module__t   NoneR   R   R   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR      s   	R   c           B   s  e  Z d  Z d Z d Z i d d 6d d 6d d 6d	 d
 6Z e d   e j e  D  Z	 d d d d d d d d d d d d d d d d  Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z d d d d d d  Z d d  Z d d  Z d d  Z d   Z RS(   t   OKt   ALARMt   INSUFFICIENT_DATAt   GreaterThanOrEqualToThresholds   >=t   GreaterThanThresholdt   >t   LessThanThresholdt   <t   LessThanOrEqualToThresholds   <=c         c   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   kt   v(    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pys	   <genexpr><   s    t    c         C   s  | |  _  | |  _ | |  _ | |  _ | |  _ | d k	 rK t |  |  _ n	 d |  _ |  j j	 |  |  _
 | d k	 r t |  |  _ n	 d |  _ |	 d k	 r t |	  |  _ n	 d |  _ d |  _ d |  _ d |  _ | |  _ | |  _ d |  _ d |  _ |
 |  _ | |  _ | |  _ | |  _ d S(   s
  
        Creates a new Alarm.

        :type name: str
        :param name: Name of alarm.

        :type metric: str
        :param metric: Name of alarm's associated metric.

        :type namespace: str
        :param namespace: The namespace for the alarm's metric.

        :type statistic: str
        :param statistic: The statistic to apply to the alarm's associated
                          metric.
                          Valid values: SampleCount|Average|Sum|Minimum|Maximum

        :type comparison: str
        :param comparison: Comparison used to compare statistic with threshold.
                           Valid values: >= | > | < | <=

        :type threshold: float
        :param threshold: The value against which the specified statistic
                          is compared.

        :type period: int
        :param period: The period in seconds over which the specified
                       statistic is applied.

        :type evaluation_periods: int
        :param evaluation_periods: The number of periods over which data is
                                  compared to the specified threshold.

        :type unit: str
        :param unit: Allowed Values are:
                     Seconds|Microseconds|Milliseconds,
                     Bytes|Kilobytes|Megabytes|Gigabytes|Terabytes,
                     Bits|Kilobits|Megabits|Gigabits|Terabits,
                     Percent|Count|
                     Bytes/Second|Kilobytes/Second|Megabytes/Second|
                     Gigabytes/Second|Terabytes/Second,
                     Bits/Second|Kilobits/Second|Megabits/Second,
                     Gigabits/Second|Terabits/Second|Count/Second|None

        :type description: str
        :param description: Description of MetricAlarm

        :type dimensions: dict
        :param dimensions: A dictionary of dimension key/values where
                           the key is the dimension name and the value
                           is either a scalar value or an iterator
                           of values to be associated with that
                           dimension.
                           Example: {
                               'InstanceId': ['i-0123456', 'i-0123457'],
                               'LoadBalancerName': 'test-lb'
                           }

        :type alarm_actions: list of strs
        :param alarm_actions: A list of the ARNs of the actions to take in
                              ALARM state

        :type insufficient_data_actions: list of strs
        :param insufficient_data_actions: A list of the ARNs of the actions to
                                          take in INSUFFICIENT_DATA state

        :type ok_actions: list of strs
        :param ok_actions: A list of the ARNs of the actions to take in OK state
        N(   R   R   t   metrict	   namespacet	   statisticR   t   floatt	   thresholdt   _cmp_mapt   gett
   comparisont   intt   periodt   evaluation_periodst   actions_enabledt	   alarm_arnt   last_updatedt   descriptiont
   dimensionst   state_reasont   state_valuet   unitt   alarm_actionst   insufficient_data_actionst
   ok_actions(   R	   R   R   R#   R$   R%   R*   R'   R,   R-   R5   R1   R2   R6   R7   R8   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR   >   s4    K																		c         C   s&   d |  j  |  j |  j |  j |  j f S(   Ns   MetricAlarm:%s[%s(%s) %s %s](   R   R#   R%   R*   R'   (   R	   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   __repr__   s    c         C   s   | d k r t    |  _ |  j S| d k r> t    |  _ |  j S| d k r] t    |  _ |  j S| d k r| t   |  _ |  j Sd  S(   Nt   AlarmActionst   InsufficientDataActionst	   OKActionst
   Dimensions(   R   R6   R7   R8   R   R2   (   R	   R   R   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR      s    c         C   s  | d k r | |  _  n| d k r0 | |  _ nh| d k rH | |  _ nP| d k r` | |  _ n8| d k rx | |  _ n | d k r t |  d |  j |  n | d k r t |  |  _ n | d	 k r | |  _	 n | d
 k r | |  _
 n | d k r
t |  |  _ n | d k r"| |  _ nv | d k r:| |  _ n^ | d k rR| |  _ nF | d k rpt |  |  _ n( | d k r| |  _ n t |  | |  d  S(   Nt   ActionsEnabledt   AlarmArnt"   AlarmConfigurationUpdatedTimestampt   AlarmDescriptiont	   AlarmNamet   ComparisonOperatorR*   t   EvaluationPeriodst
   MetricNamet	   Namespacet   Periodt   StateReasont
   StateValuet	   Statistict	   Thresholdt   Unit(   R.   R/   R0   R1   R   t   setattrt   _rev_cmp_mapR+   R-   R#   R$   R,   R3   R4   R%   R&   R'   R5   (   R	   R   R   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR      s>    c         C   s   |  j  j |  j | | |  S(   s$   Temporarily sets the state of an alarm.

        :type value: str
        :param value: OK | ALARM | INSUFFICIENT_DATA

        :type reason: str
        :param reason: Reason alarm set (human readable).

        :type data: str
        :param data: Reason data (will be jsonified).
        (   R   t   set_alarm_stateR   (   R	   R   t   reasont   data(    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt	   set_state   s    c         C   s   |  j  j |   S(   N(   R   t   update_alarm(   R	   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   update   s    c         C   s   |  j  j |  j g  S(   N(   R   t   enable_alarm_actionsR   (   R	   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   enable_actions   s    c         C   s   |  j  j |  j g  S(   N(   R   t   disable_alarm_actionsR   (   R	   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   disable_actions   s    c         C   s"   |  j  j |  j | | | | |  S(   N(   R   t   describe_alarm_historyR   (   R	   t
   start_datet   end_datet   max_recordst   history_item_typet
   next_token(    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   describe_history   s    c         C   s'   | s
 d Sd |  _  |  j j |  d S(   s&  
        Adds an alarm action, represented as an SNS topic, to this alarm.
        What do do when alarm is triggered.

        :type action_arn: str
        :param action_arn: SNS topics to which notification should be
                           sent if the alarm goes to state ALARM.
        Nt   true(   R.   R6   R   (   R	   t
   action_arn(    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   add_alarm_action   s    		c         C   s'   | s
 d Sd |  _  |  j j |  d S(   sR  
        Adds an insufficient_data action, represented as an SNS topic, to
        this alarm. What to do when the insufficient_data state is reached.

        :type action_arn: str
        :param action_arn: SNS topics to which notification should be
                           sent if the alarm goes to state INSUFFICIENT_DATA.
        NR`   (   R.   R7   R   (   R	   Ra   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   add_insufficient_data_action  s    		c         C   s'   | s
 d Sd |  _  |  j j |  d S(   s4  
        Adds an ok action, represented as an SNS topic, to this alarm. What
        to do when the ok state is reached.

        :type action_arn: str
        :param action_arn: SNS topics to which notification should be
                           sent if the alarm goes to state INSUFFICIENT_DATA.
        NR`   (   R.   R8   R   (   R	   Ra   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   add_ok_action  s    		c         C   s   |  j  j |  j g  d  S(   N(   R   t   delete_alarmsR   (   R	   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   delete'  s    N(   R   R   R   R   R   R(   t   dictR   t	   iteritemsRN   R   R   R9   R   R   RR   RT   RV   RX   R_   Rb   Rc   Rd   Rf   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR   0   s8   
				d			"				t   AlarmHistoryItemc           B   s/   e  Z d d   Z d   Z d   Z d   Z RS(   c         C   s   | |  _  d  S(   N(   R   (   R	   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR   ,  s    c         C   s   d |  j  |  j |  j f S(   Ns   AlarmHistory:%s[%s at %s](   R   t   summaryt	   timestamp(   R	   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR9   /  s    c         C   s   d  S(   N(    (   R	   R   R   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR   2  s    c         C   s   | d k r | |  _  n | d k r9 t j |  |  _ n | d k rQ | |  _ ni | d k ri | |  _ nQ | d k r y t j | d  |  _ Wq t	 k
 r t j | d  |  _ q Xn  d  S(   NRB   t   HistoryDatat   HistoryItemTypet   HistorySummaryt	   Timestamps   %Y-%m-%dT%H:%M:%S.%fZs   %Y-%m-%dT%H:%M:%SZ(
   R   R   t   loadsRQ   t   tem_typeRj   R    t   strptimeRk   t
   ValueError(   R	   R   R   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyR   5  s    	N(   R   R   R   R   R9   R   R   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyRi   +  s   		N(   R    t   boto.ec2.cloudwatch.listelementR   t   boto.ec2.cloudwatch.dimensionR   t   boto.compatR   R   R   R   t   objectR   Ri   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/cloudwatch/alarm.pyt   <module>   s   