OLD | NEW |
| (Empty) |
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 AutoScalingGrou
p | |
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: str | |
70 :param unit: The unit of measurement. | |
71 """ | |
72 self.name = name | |
73 self.connection = connection | |
74 self.dimensions = dimensions | |
75 self.breach_duration = breach_duration | |
76 self.upper_breach_scale_increment = upper_breach_scale_increment | |
77 self.created_time = None | |
78 self.upper_threshold = upper_threshold | |
79 self.status = None | |
80 self.lower_threshold = lower_threshold | |
81 self.period = period | |
82 self.lower_breach_scale_increment = lower_breach_scale_increment | |
83 self.statistic = statistic | |
84 self.unit = unit | |
85 self.namespace = None | |
86 if autoscale_group: | |
87 self.autoscale_group = weakref.proxy(autoscale_group) | |
88 else: | |
89 self.autoscale_group = None | |
90 self.measure_name = measure_name | |
91 | |
92 def __repr__(self): | |
93 return 'Trigger:%s' % (self.name) | |
94 | |
95 def startElement(self, name, attrs, connection): | |
96 return None | |
97 | |
98 def endElement(self, name, value, connection): | |
99 if name == 'BreachDuration': | |
100 self.breach_duration = value | |
101 elif name == 'TriggerName': | |
102 self.name = value | |
103 elif name == 'Period': | |
104 self.period = value | |
105 elif name == 'CreatedTime': | |
106 self.created_time = value | |
107 elif name == 'Statistic': | |
108 self.statistic = value | |
109 elif name == 'Unit': | |
110 self.unit = value | |
111 elif name == 'Namespace': | |
112 self.namespace = value | |
113 elif name == 'AutoScalingGroupName': | |
114 self.autoscale_group_name = value | |
115 elif name == 'MeasureName': | |
116 self.measure_name = value | |
117 else: | |
118 setattr(self, name, value) | |
119 | |
120 def update(self): | |
121 """ Write out differences to trigger. """ | |
122 self.connection.create_trigger(self) | |
123 | |
124 def delete(self): | |
125 """ Delete this trigger. """ | |
126 params = { | |
127 'TriggerName' : self.name, | |
128 'AutoScalingGroupName' : self.autoscale_group_name, | |
129 } | |
130 req =self.connection.get_object('DeleteTrigger', params, | |
131 Request) | |
132 self.connection.last_request = req | |
133 return req | |
134 | |
OLD | NEW |