Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/gsutil/boto/ec2/autoscale/policy.py

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Removed gsutil/tests and gsutil/docs Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2009-2010 Reza Lotun http://reza.lotun.name/
2 # Copyright (c) 2011 Jann Kleen
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis-
8 # tribute, sublicense, and/or sell copies of the Software, and to permit
9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 # IN THE SOFTWARE.
22
23 from boto.resultset import ResultSet
24 from boto.ec2.elb.listelement import ListElement
25
26 class Alarm(object):
27 def __init__(self, connection=None):
28 self.connection = connection
29 self.name = None
30 self.alarm_arn = None
31
32 def __repr__(self):
33 return 'Alarm:%s' % self.name
34
35 def startElement(self, name, attrs, connection):
36 return None
37
38 def endElement(self, name, value, connection):
39 if name == 'AlarmName':
40 self.name = value
41 elif name == 'AlarmARN':
42 self.alarm_arn = value
43 else:
44 setattr(self, name, value)
45
46
47 class AdjustmentType(object):
48 def __init__(self, connection=None):
49 self.connection = connection
50 self.adjustment_types = ListElement([])
51
52 def __repr__(self):
53 return 'AdjustmentType:%s' % self.adjustment_types
54
55 def startElement(self, name, attrs, connection):
56 if name == 'AdjustmentType':
57 return self.adjustment_types
58
59 def endElement(self, name, value, connection):
60 return
61
62
63 class MetricCollectionTypes(object):
64 class BaseType(object):
65 arg = ''
66 def __init__(self, connection):
67 self.connection = connection
68 self.val = None
69 def __repr__(self):
70 return '%s:%s' % (self.arg, self.val)
71 def startElement(self, name, attrs, connection):
72 return
73 def endElement(self, name, value, connection):
74 if name == self.arg:
75 self.val = value
76 class Metric(BaseType):
77 arg = 'Metric'
78 class Granularity(BaseType):
79 arg = 'Granularity'
80
81 def __init__(self, connection=None):
82 self.connection = connection
83 self.metrics = []
84 self.granularities = []
85
86 def __repr__(self):
87 return 'MetricCollectionTypes:<%s, %s>' % (self.metrics, self.granularit ies)
88
89 def startElement(self, name, attrs, connection):
90 if name == 'Granularities':
91 self.granularities = ResultSet([('member', self.Granularity)])
92 return self.granularities
93 elif name == 'Metrics':
94 self.metrics = ResultSet([('member', self.Metric)])
95 return self.metrics
96
97 def endElement(self, name, value, connection):
98 return
99
100
101 class ScalingPolicy(object):
102 def __init__(self, connection=None, **kwargs):
103 """
104 Scaling Policy
105
106 :type name: str
107 :param name: Name of scaling policy.
108
109 :type adjustment_type: str
110 :param adjustment_type: Specifies the type of adjustment. Valid values a re `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity`.
111
112 :type as_name: str or int
113 :param as_name: Name or ARN of the Auto Scaling Group.
114
115 :type scaling_adjustment: int
116 :param scaling_adjustment: Value of adjustment (type specified in `adjus tment_type`).
117
118 :type cooldown: int
119 :param cooldown: Time (in seconds) before Alarm related Scaling Activiti es can start after the previous Scaling Activity ends.
120
121 """
122 self.name = kwargs.get('name', None)
123 self.adjustment_type = kwargs.get('adjustment_type', None)
124 self.as_name = kwargs.get('as_name', None)
125 self.scaling_adjustment = kwargs.get('scaling_adjustment', None)
126 self.cooldown = kwargs.get('cooldown', None)
127 self.connection = connection
128
129 def __repr__(self):
130 return 'ScalingPolicy(%s group:%s adjustment:%s)' % (self.name,
131 self.as_name,
132 self.adjustment_typ e)
133
134 def startElement(self, name, attrs, connection):
135 if name == 'Alarms':
136 self.alarms = ResultSet([('member', Alarm)])
137 return self.alarms
138
139 def endElement(self, name, value, connection):
140 if name == 'PolicyName':
141 self.name = value
142 elif name == 'AutoScalingGroupName':
143 self.as_name = value
144 elif name == 'PolicyARN':
145 self.policy_arn = value
146 elif name == 'ScalingAdjustment':
147 self.scaling_adjustment = int(value)
148 elif name == 'Cooldown':
149 self.cooldown = int(value)
150 elif name == 'AdjustmentType':
151 self.adjustment_type = value
152
153 def delete(self):
154 return self.connection.delete_policy(self.name, self.as_name)
155
156
157 class TerminationPolicies(list):
158 def __init__(self, connection=None, **kwargs):
159 pass
160
161 def startElement(self, name, attrs, connection):
162 pass
163
164 def endElement(self, name, value, connection):
165 if name == 'member':
166 self.append(value)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698