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

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

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2009-2011 Reza Lotun http://reza.lotun.name/ 1 # Copyright (c) 2009-2011 Reza Lotun http://reza.lotun.name/
2 # 2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a 3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the 4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis- 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 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- 8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions: 9 # lowing conditions:
10 # 10 #
11 # The above copyright notice and this permission notice shall be included 11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software. 12 # in all copies or substantial portions of the Software.
13 # 13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 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- 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 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, 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, 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 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE. 20 # IN THE SOFTWARE.
21 21
22
23 from boto.ec2.elb.listelement import ListElement 22 from boto.ec2.elb.listelement import ListElement
24 from boto.resultset import ResultSet 23 from boto.resultset import ResultSet
25 from boto.ec2.autoscale.launchconfig import LaunchConfiguration 24 from boto.ec2.autoscale.launchconfig import LaunchConfiguration
26 from boto.ec2.autoscale.request import Request 25 from boto.ec2.autoscale.request import Request
27 from boto.ec2.autoscale.instance import Instance 26 from boto.ec2.autoscale.instance import Instance
28 27 from boto.ec2.autoscale.tag import Tag
29 28
30 class ProcessType(object): 29 class ProcessType(object):
31 def __init__(self, connection=None): 30 def __init__(self, connection=None):
32 self.connection = connection 31 self.connection = connection
33 self.process_name = None 32 self.process_name = None
34 33
35 def __repr__(self): 34 def __repr__(self):
36 return 'ProcessType(%s)' % self.process_name 35 return 'ProcessType(%s)' % self.process_name
37 36
38 def startElement(self, name, attrs, connection): 37 def startElement(self, name, attrs, connection):
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 self.granularity = value 78 self.granularity = value
80 elif name == 'Metric': 79 elif name == 'Metric':
81 self.metric = value 80 self.metric = value
82 81
83 82
84 class AutoScalingGroup(object): 83 class AutoScalingGroup(object):
85 def __init__(self, connection=None, name=None, 84 def __init__(self, connection=None, name=None,
86 launch_config=None, availability_zones=None, 85 launch_config=None, availability_zones=None,
87 load_balancers=None, default_cooldown=None, 86 load_balancers=None, default_cooldown=None,
88 health_check_type=None, health_check_period=None, 87 health_check_type=None, health_check_period=None,
89 placement_group=None, vpc_zone_identifier=None, desired_capacit y=None, 88 placement_group=None, vpc_zone_identifier=None,
90 min_size=None, max_size=None, **kwargs): 89 desired_capacity=None, min_size=None, max_size=None, **kwargs):
91 """ 90 """
92 Creates a new AutoScalingGroup with the specified name. 91 Creates a new AutoScalingGroup with the specified name.
93 92
94 You must not have already used up your entire quota of 93 You must not have already used up your entire quota of
95 AutoScalingGroups in order for this call to be successful. Once the 94 AutoScalingGroups in order for this call to be successful. Once the
96 creation request is completed, the AutoScalingGroup is ready to be 95 creation request is completed, the AutoScalingGroup is ready to be
97 used in other calls. 96 used in other calls.
98 97
99 :type name: str 98 :type name: str
100 :param name: Name of autoscaling group (required). 99 :param name: Name of autoscaling group (required).
101 100
102 :type availability_zones: list 101 :type availability_zones: list
103 :param availability_zones: List of availability zones (required). 102 :param availability_zones: List of availability zones (required).
104 103
105 :type default_cooldown: int 104 :type default_cooldown: int
106 :param default_cooldown: Number of seconds after a Scaling Activity comp letes 105 :param default_cooldown: Number of seconds after a Scaling Activity
107 before any further scaling activities can start . 106 completes before any further scaling activities can start.
108 107
109 :type desired_capacity: int 108 :type desired_capacity: int
110 :param desired_capacity: The desired capacity for the group. 109 :param desired_capacity: The desired capacity for the group.
111 110
112 :type health_check_period: str 111 :type health_check_period: str
113 :param health_check_period: Length of time in seconds after a new EC2 in stance 112 :param health_check_period: Length of time in seconds after a new
114 comes into service that Auto Scaling starts checking its 113 EC2 instance comes into service that Auto Scaling starts
115 health. 114 checking its health.
116 115
117 :type health_check_type: str 116 :type health_check_type: str
118 :param health_check_type: The service you want the health status from, 117 :param health_check_type: The service you want the health status from,
119 Amazon EC2 or Elastic Load Balancer. 118 Amazon EC2 or Elastic Load Balancer.
120 119
121 :type launch_config: str or LaunchConfiguration 120 :type launch_config: str or LaunchConfiguration
122 :param launch_config: Name of launch configuration (required). 121 :param launch_config: Name of launch configuration (required).
123 122
124
125 :type load_balancers: list 123 :type load_balancers: list
126 :param load_balancers: List of load balancers. 124 :param load_balancers: List of load balancers.
127 125
128 :type max_size: int 126 :type max_size: int
129 :param maxsize: Maximum size of group (required). 127 :param maxsize: Maximum size of group (required).
130 128
131 :type min_size: int 129 :type min_size: int
132 :param minsize: Minimum size of group (required). 130 :param minsize: Minimum size of group (required).
133 131
134 :type placement_group: str 132 :type placement_group: str
135 :param placement_group: Physical location of your cluster placement 133 :param placement_group: Physical location of your cluster placement
136 group created in Amazon EC2. 134 group created in Amazon EC2.
137 135
138 :type vpc_zone_identifier: str 136 :type vpc_zone_identifier: str
139 :param vpc_zone_identifier: The subnet identifier of the Virtual Private Cloud. 137 :param vpc_zone_identifier: The subnet identifier of the Virtual
140 138 Private Cloud.
139
141 :rtype: :class:`boto.ec2.autoscale.group.AutoScalingGroup` 140 :rtype: :class:`boto.ec2.autoscale.group.AutoScalingGroup`
142 :return: An autoscale group. 141 :return: An autoscale group.
143 """ 142 """
144 self.name = name or kwargs.get('group_name') # backwards compatibility 143 self.name = name or kwargs.get('group_name') # backwards compatibility
145 self.connection = connection 144 self.connection = connection
146 self.min_size = int(min_size) if min_size is not None else None 145 self.min_size = int(min_size) if min_size is not None else None
147 self.max_size = int(max_size) if max_size is not None else None 146 self.max_size = int(max_size) if max_size is not None else None
148 self.created_time = None 147 self.created_time = None
149 default_cooldown = default_cooldown or kwargs.get('cooldown') # backwar ds compatibility 148 # backwards compatibility
150 self.default_cooldown = int(default_cooldown) if default_cooldown is not None else None 149 default_cooldown = default_cooldown or kwargs.get('cooldown')
150 if default_cooldown is not None:
151 default_cooldown = int(default_cooldown)
152 self.default_cooldown = default_cooldown
151 self.launch_config_name = launch_config 153 self.launch_config_name = launch_config
152 if launch_config and isinstance(launch_config, LaunchConfiguration): 154 if launch_config and isinstance(launch_config, LaunchConfiguration):
153 self.launch_config_name = launch_config.name 155 self.launch_config_name = launch_config.name
154 self.desired_capacity = desired_capacity 156 self.desired_capacity = desired_capacity
155 lbs = load_balancers or [] 157 lbs = load_balancers or []
156 self.load_balancers = ListElement(lbs) 158 self.load_balancers = ListElement(lbs)
157 zones = availability_zones or [] 159 zones = availability_zones or []
158 self.availability_zones = ListElement(zones) 160 self.availability_zones = ListElement(zones)
159 self.health_check_period = health_check_period 161 self.health_check_period = health_check_period
160 self.health_check_type = health_check_type 162 self.health_check_type = health_check_type
161 self.placement_group = placement_group 163 self.placement_group = placement_group
162 self.autoscaling_group_arn = None 164 self.autoscaling_group_arn = None
163 self.vpc_zone_identifier = vpc_zone_identifier 165 self.vpc_zone_identifier = vpc_zone_identifier
164 self.instances = None 166 self.instances = None
167 self.tags = None
165 168
166 # backwards compatible access to 'cooldown' param 169 # backwards compatible access to 'cooldown' param
167 def _get_cooldown(self): 170 def _get_cooldown(self):
168 return self.default_cooldown 171 return self.default_cooldown
172
169 def _set_cooldown(self, val): 173 def _set_cooldown(self, val):
170 self.default_cooldown = val 174 self.default_cooldown = val
175
171 cooldown = property(_get_cooldown, _set_cooldown) 176 cooldown = property(_get_cooldown, _set_cooldown)
172 177
173 def __repr__(self): 178 def __repr__(self):
174 return 'AutoScalingGroup<%s>: created:%s, minsize:%s, maxsize:%s, capaci ty:%s' % (self.name, 179 return 'AutoScaleGroup<%s>' % self.name
175 self.created_time,
176 self.min_size,
177 self.max_size,
178 self.desired_capacity)
179 180
180 def startElement(self, name, attrs, connection): 181 def startElement(self, name, attrs, connection):
181 if name == 'Instances': 182 if name == 'Instances':
182 self.instances = ResultSet([('member', Instance)]) 183 self.instances = ResultSet([('member', Instance)])
183 return self.instances 184 return self.instances
184 elif name == 'LoadBalancerNames': 185 elif name == 'LoadBalancerNames':
185 return self.load_balancers 186 return self.load_balancers
186 elif name == 'AvailabilityZones': 187 elif name == 'AvailabilityZones':
187 return self.availability_zones 188 return self.availability_zones
188 elif name == 'EnabledMetrics': 189 elif name == 'EnabledMetrics':
189 self.enabled_metrics = ResultSet([('member', EnabledMetric)]) 190 self.enabled_metrics = ResultSet([('member', EnabledMetric)])
190 return self.enabled_metrics 191 return self.enabled_metrics
191 elif name == 'SuspendedProcesses': 192 elif name == 'SuspendedProcesses':
192 self.suspended_processes = ResultSet([('member', SuspendedProcess)]) 193 self.suspended_processes = ResultSet([('member', SuspendedProcess)])
193 return self.suspended_processes 194 return self.suspended_processes
195 elif name == 'Tags':
196 self.tags = ResultSet([('member', Tag)])
197 return self.tags
194 else: 198 else:
195 return 199 return
196 200
197 def endElement(self, name, value, connection): 201 def endElement(self, name, value, connection):
198 if name == 'MinSize': 202 if name == 'MinSize':
199 self.min_size = int(value) 203 self.min_size = int(value)
200 elif name == 'AutoScalingGroupARN': 204 elif name == 'AutoScalingGroupARN':
201 self.autoscaling_group_arn = value 205 self.autoscaling_group_arn = value
202 elif name == 'CreatedTime': 206 elif name == 'CreatedTime':
203 self.created_time = value 207 self.created_time = value
204 elif name == 'DefaultCooldown': 208 elif name == 'DefaultCooldown':
205 self.default_cooldown = int(value) 209 self.default_cooldown = int(value)
206 elif name == 'LaunchConfigurationName': 210 elif name == 'LaunchConfigurationName':
207 self.launch_config_name = value 211 self.launch_config_name = value
208 elif name == 'DesiredCapacity': 212 elif name == 'DesiredCapacity':
209 self.desired_capacity = int(value) 213 self.desired_capacity = int(value)
210 elif name == 'MaxSize': 214 elif name == 'MaxSize':
211 self.max_size = int(value) 215 self.max_size = int(value)
212 elif name == 'AutoScalingGroupName': 216 elif name == 'AutoScalingGroupName':
213 self.name = value 217 self.name = value
214 elif name == 'PlacementGroup': 218 elif name == 'PlacementGroup':
215 self.placement_group = value 219 self.placement_group = value
216 elif name == 'HealthCheckGracePeriod': 220 elif name == 'HealthCheckGracePeriod':
217 self.health_check_period = int(value) 221 try:
222 self.health_check_period = int(value)
223 except ValueError:
224 self.health_check_period = None
218 elif name == 'HealthCheckType': 225 elif name == 'HealthCheckType':
219 self.health_check_type = value 226 self.health_check_type = value
220 elif name == 'VPCZoneIdentifier': 227 elif name == 'VPCZoneIdentifier':
221 self.vpc_zone_identifier = value 228 self.vpc_zone_identifier = value
222 else: 229 else:
223 setattr(self, name, value) 230 setattr(self, name, value)
224 231
225 def set_capacity(self, capacity): 232 def set_capacity(self, capacity):
226 """ Set the desired capacity for the group. """ 233 """
227 params = { 234 Set the desired capacity for the group.
228 'AutoScalingGroupName' : self.name, 235 """
229 'DesiredCapacity' : capacity, 236 params = {'AutoScalingGroupName' : self.name,
230 } 237 'DesiredCapacity' : capacity}
231 req = self.connection.get_object('SetDesiredCapacity', params, 238 req = self.connection.get_object('SetDesiredCapacity', params,
232 Request) 239 Request)
233 self.connection.last_request = req 240 self.connection.last_request = req
234 return req 241 return req
235 242
236 def update(self): 243 def update(self):
237 """ Sync local changes with AutoScaling group. """ 244 """
245 Sync local changes with AutoScaling group.
246 """
238 return self.connection._update_group('UpdateAutoScalingGroup', self) 247 return self.connection._update_group('UpdateAutoScalingGroup', self)
239 248
240 def shutdown_instances(self): 249 def shutdown_instances(self):
241 """ Convenience method which shuts down all instances associated with 250 """
251 Convenience method which shuts down all instances associated with
242 this group. 252 this group.
243 """ 253 """
244 self.min_size = 0 254 self.min_size = 0
245 self.max_size = 0 255 self.max_size = 0
246 self.desired_capacity = 0 256 self.desired_capacity = 0
247 self.update() 257 self.update()
248 258
249 def delete(self): 259 def delete(self, force_delete=False):
250 """ Delete this auto-scaling group if no instances attached or no 260 """
261 Delete this auto-scaling group if no instances attached or no
251 scaling activities in progress. 262 scaling activities in progress.
252 """ 263 """
253 return self.connection.delete_auto_scaling_group(self.name) 264 return self.connection.delete_auto_scaling_group(self.name, force_delete )
254 265
255 def get_activities(self, activity_ids=None, max_records=50): 266 def get_activities(self, activity_ids=None, max_records=50):
256 """ 267 """
257 Get all activies for this group. 268 Get all activies for this group.
258 """ 269 """
259 return self.connection.get_all_activities(self, activity_ids, max_record s) 270 return self.connection.get_all_activities(self, activity_ids,
271 max_records)
260 272
261 def suspend_processes(self, scaling_processes=None): 273 def suspend_processes(self, scaling_processes=None):
262 """ Suspends Auto Scaling processes for an Auto Scaling group. """ 274 """
275 Suspends Auto Scaling processes for an Auto Scaling group.
276 """
263 return self.connection.suspend_processes(self.name, scaling_processes) 277 return self.connection.suspend_processes(self.name, scaling_processes)
264 278
265 def resume_processes(self, scaling_processes=None): 279 def resume_processes(self, scaling_processes=None):
266 """ Resumes Auto Scaling processes for an Auto Scaling group. """ 280 """
281 Resumes Auto Scaling processes for an Auto Scaling group.
282 """
267 return self.connection.resume_processes(self.name, scaling_processes) 283 return self.connection.resume_processes(self.name, scaling_processes)
268 284
269 285
270 class AutoScalingGroupMetric(object): 286 class AutoScalingGroupMetric(object):
271 def __init__(self, connection=None): 287 def __init__(self, connection=None):
272 288
273 self.connection = connection 289 self.connection = connection
274 self.metric = None 290 self.metric = None
275 self.granularity = None 291 self.granularity = None
276 292
277 def __repr__(self): 293 def __repr__(self):
278 return 'AutoScalingGroupMetric:%s' % self.metric 294 return 'AutoScalingGroupMetric:%s' % self.metric
279 295
280 def startElement(self, name, attrs, connection): 296 def startElement(self, name, attrs, connection):
281 return 297 return
282 298
283 def endElement(self, name, value, connection): 299 def endElement(self, name, value, connection):
284 if name == 'Metric': 300 if name == 'Metric':
285 self.metric = value 301 self.metric = value
286 elif name == 'Granularity': 302 elif name == 'Granularity':
287 self.granularity = value 303 self.granularity = value
288 else: 304 else:
289 setattr(self, name, value) 305 setattr(self, name, value)
290 306
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/boto/ec2/autoscale/activity.py ('k') | third_party/gsutil/boto/boto/ec2/autoscale/instance.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698