1
# Copyright (c) 2009 Reza Lotun http://reza.lotun.name/
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-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
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
24
from boto.ec2.autoscale.request import Request
27
class Trigger(object):
29
An auto scaling trigger.
32
def __init__(self, connection=None, name=None, autoscale_group=None,
33
dimensions=None, measure_name=None,
34
statistic=None, unit=None, period=60,
36
lower_breach_scale_increment=None,
38
upper_breach_scale_increment=None,
39
breach_duration=None):
41
Initialize an auto-scaling trigger object.
44
:param name: The name for this trigger
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
52
:type dimensions: list
53
:param dimensions: List of tuples, i.e.
54
('ImageId', 'i-13lasde') etc.
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.
62
:param statistic: The particular statistic used by the trigger when
63
fetching metric statistics to examine.
66
:param period: The period associated with the metric statistics in
67
seconds. Valid Values: 60 or a multiple of 60.
72
:type lower_threshold:
73
:param lower_threshold
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
83
self.lower_threshold = lower_threshold
85
self.lower_breach_scale_increment = lower_breach_scale_increment
86
self.statistic = statistic
90
self.autoscale_group = weakref.proxy(autoscale_group)
92
self.autoscale_group = None
93
self.measure_name = measure_name
96
return 'Trigger:%s' % (self.name)
98
def startElement(self, name, attrs, connection):
101
def endElement(self, name, value, connection):
102
if name == 'BreachDuration':
103
self.breach_duration = value
104
elif name == 'TriggerName':
106
elif name == 'Period':
108
elif name == 'CreatedTime':
109
self.created_time = value
110
elif name == 'Statistic':
111
self.statistic = 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
121
setattr(self, name, value)
124
""" Write out differences to trigger. """
125
self.connection.create_trigger(self)
128
""" Delete this trigger. """
130
'TriggerName' : self.name,
131
'AutoScalingGroupName' : self.autoscale_group_name,
133
req =self.connection.get_object('DeleteTrigger', params,
135
self.connection.last_request = req