~vishvananda/nova/network-refactor

« back to all changes in this revision

Viewing changes to vendor/boto/boto/ec2/autoscale/trigger.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2009 Reza Lotun http://reza.lotun.name/
 
2
#
 
3
# Permission is hereby granted, free of charge, to any person obtaining a
 
4
# copy of this software and associated documentation files (the
 
5
# "Software"), to deal in the Software without restriction, including
 
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
 
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
 
8
# persons to whom the Software is furnished to do so, subject to the fol-
 
9
# lowing conditions:
 
10
#
 
11
# The above copyright notice and this permission notice shall be included
 
12
# in all copies or substantial portions of the Software.
 
13
#
 
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
 
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
 
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
20
# IN THE SOFTWARE.
 
21
 
 
22
import weakref
 
23
 
 
24
from boto.ec2.autoscale.request import Request
 
25
 
 
26
 
 
27
class Trigger(object):
 
28
    """
 
29
    An auto scaling trigger.
 
30
    """
 
31
 
 
32
    def __init__(self, connection=None, name=None, autoscale_group=None,
 
33
                 dimensions=None, measure_name=None,
 
34
                 statistic=None, unit=None, period=60,
 
35
                 lower_threshold=None,
 
36
                 lower_breach_scale_increment=None,
 
37
                 upper_threshold=None,
 
38
                 upper_breach_scale_increment=None,
 
39
                 breach_duration=None):
 
40
        """
 
41
        Initialize an auto-scaling trigger object.
 
42
        
 
43
        :type name: str
 
44
        :param name: The name for this trigger
 
45
        
 
46
        :type autoscale_group: str
 
47
        :param autoscale_group: The name of the AutoScalingGroup that will be
 
48
                                associated with the trigger. The AutoScalingGroup
 
49
                                that will be affected by the trigger when it is
 
50
                                activated.
 
51
        
 
52
        :type dimensions: list
 
53
        :param dimensions: List of tuples, i.e.
 
54
                            ('ImageId', 'i-13lasde') etc.
 
55
        
 
56
        :type measure_name: str
 
57
        :param measure_name: The measure name associated with the metric used by
 
58
                             the trigger to determine when to activate, for
 
59
                             example, CPU, network I/O, or disk I/O.
 
60
        
 
61
        :type statistic: str
 
62
        :param statistic: The particular statistic used by the trigger when
 
63
                          fetching metric statistics to examine.
 
64
        
 
65
        :type period: int
 
66
        :param period: The period associated with the metric statistics in
 
67
                       seconds. Valid Values: 60 or a multiple of 60.
 
68
        
 
69
        :type unit:
 
70
        :param unit
 
71
        
 
72
        :type lower_threshold:
 
73
        :param lower_threshold
 
74
        """
 
75
        self.name = name
 
76
        self.connection = connection
 
77
        self.dimensions = dimensions
 
78
        self.breach_duration = breach_duration
 
79
        self.upper_breach_scale_increment = upper_breach_scale_increment
 
80
        self.created_time = None
 
81
        self.upper_threshold = upper_threshold
 
82
        self.status = None
 
83
        self.lower_threshold = lower_threshold
 
84
        self.period = period
 
85
        self.lower_breach_scale_increment = lower_breach_scale_increment
 
86
        self.statistic = statistic
 
87
        self.unit = unit
 
88
        self.namespace = None
 
89
        if autoscale_group:
 
90
            self.autoscale_group = weakref.proxy(autoscale_group)
 
91
        else:
 
92
            self.autoscale_group = None
 
93
        self.measure_name = measure_name
 
94
 
 
95
    def __repr__(self):
 
96
        return 'Trigger:%s' % (self.name)
 
97
 
 
98
    def startElement(self, name, attrs, connection):
 
99
        return None
 
100
 
 
101
    def endElement(self, name, value, connection):
 
102
        if name == 'BreachDuration':
 
103
            self.breach_duration = value
 
104
        elif name == 'TriggerName':
 
105
            self.name = value
 
106
        elif name == 'Period':
 
107
            self.period = value
 
108
        elif name == 'CreatedTime':
 
109
            self.created_time = value
 
110
        elif name == 'Statistic':
 
111
            self.statistic = value
 
112
        elif name == 'Unit':
 
113
            self.unit = value
 
114
        elif name == 'Namespace':
 
115
            self.namespace = value
 
116
        elif name == 'AutoScalingGroupName':
 
117
            self.autoscale_group_name = value
 
118
        elif name == 'MeasureName':
 
119
            self.measure_name = value
 
120
        else:
 
121
            setattr(self, name, value)
 
122
 
 
123
    def update(self):
 
124
        """ Write out differences to trigger. """
 
125
        self.connection.create_trigger(self)
 
126
 
 
127
    def delete(self):
 
128
        """ Delete this trigger. """
 
129
        params = {
 
130
                  'TriggerName'          : self.name,
 
131
                  'AutoScalingGroupName' : self.autoscale_group_name,
 
132
                  }
 
133
        req =self.connection.get_object('DeleteTrigger', params,
 
134
                                        Request)
 
135
        self.connection.last_request = req
 
136
        return req
 
137