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

Side by Side Diff: boto/ec2/autoscale/__init__.py

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month 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
« no previous file with comments | « boto/ec2/address.py ('k') | boto/ec2/autoscale/activity.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2009 Reza Lotun http://reza.lotun.name/ 1 # Copyright (c) 2009-2011 Reza Lotun http://reza.lotun.name/
2 # Copyright (c) 2011 Jann Kleen
2 # 3 #
3 # Permission is hereby granted, free of charge, to any person obtaining a 4 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the 5 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 6 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis- 7 # 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 # 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 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions: 10 # lowing conditions:
10 # 11 #
11 # The above copyright notice and this permission notice shall be included 12 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software. 13 # in all copies or substantial portions of the Software.
13 # 14 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 # 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 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17 # 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 # 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 # 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 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE. 21 # IN THE SOFTWARE.
21 22
22 """ 23 """
23 This module provides an interface to the Elastic Compute Cloud (EC2) 24 This module provides an interface to the Elastic Compute Cloud (EC2)
24 Auto Scaling service. 25 Auto Scaling service.
25 """ 26 """
26 27
28 import base64
29
27 import boto 30 import boto
28 from boto.connection import AWSQueryConnection 31 from boto.connection import AWSQueryConnection
29 from boto.ec2.regioninfo import RegionInfo 32 from boto.ec2.regioninfo import RegionInfo
30 from boto.ec2.autoscale.request import Request 33 from boto.ec2.autoscale.request import Request
31 from boto.ec2.autoscale.trigger import Trigger
32 from boto.ec2.autoscale.launchconfig import LaunchConfiguration 34 from boto.ec2.autoscale.launchconfig import LaunchConfiguration
33 from boto.ec2.autoscale.group import AutoScalingGroup 35 from boto.ec2.autoscale.group import AutoScalingGroup, ProcessType
34 from boto.ec2.autoscale.activity import Activity 36 from boto.ec2.autoscale.activity import Activity
37 from boto.ec2.autoscale.policy import AdjustmentType, MetricCollectionTypes, Sca lingPolicy
38 from boto.ec2.autoscale.instance import Instance
39 from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction
40
41
42 RegionData = {
43 'us-east-1' : 'autoscaling.us-east-1.amazonaws.com',
44 'us-west-1' : 'autoscaling.us-west-1.amazonaws.com',
45 'eu-west-1' : 'autoscaling.eu-west-1.amazonaws.com',
46 'ap-northeast-1' : 'autoscaling.ap-northeast-1.amazonaws.com',
47 'ap-southeast-1' : 'autoscaling.ap-southeast-1.amazonaws.com'}
48
49 def regions():
50 """
51 Get all available regions for the Auto Scaling service.
52
53 :rtype: list
54 :return: A list of :class:`boto.RegionInfo` instances
55 """
56 regions = []
57 for region_name in RegionData:
58 region = RegionInfo(name=region_name,
59 endpoint=RegionData[region_name],
60 connection_cls=AutoScaleConnection)
61 regions.append(region)
62 return regions
63
64 def connect_to_region(region_name, **kw_params):
65 """
66 Given a valid region name, return a
67 :class:`boto.ec2.autoscale.AutoScaleConnection`.
68
69 :param str region_name: The name of the region to connect to.
70
71 :rtype: :class:`boto.ec2.AutoScaleConnection` or ``None``
72 :return: A connection to the given region, or None if an invalid region
73 name is given
74 """
75 for region in regions():
76 if region.name == region_name:
77 return region.connect(**kw_params)
78 return None
35 79
36 80
37 class AutoScaleConnection(AWSQueryConnection): 81 class AutoScaleConnection(AWSQueryConnection):
38 APIVersion = boto.config.get('Boto', 'autoscale_version', '2009-05-15') 82 APIVersion = boto.config.get('Boto', 'autoscale_version', '2011-01-01')
39 Endpoint = boto.config.get('Boto', 'autoscale_endpoint', 83 DefaultRegionEndpoint = boto.config.get('Boto', 'autoscale_endpoint',
40 'autoscaling.amazonaws.com') 84 'autoscaling.amazonaws.com')
41 DefaultRegionName = 'us-east-1' 85 DefaultRegionName = boto.config.get('Boto', 'autoscale_region_name', 'us-ea st-1')
42 DefaultRegionEndpoint = 'autoscaling.amazonaws.com'
43 86
44 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, 87 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
45 is_secure=True, port=None, proxy=None, proxy_port=None, 88 is_secure=True, port=None, proxy=None, proxy_port=None,
46 proxy_user=None, proxy_pass=None, debug=1, 89 proxy_user=None, proxy_pass=None, debug=None,
47 https_connection_factory=None, region=None, path='/'): 90 https_connection_factory=None, region=None, path='/'):
48 """ 91 """
49 Init method to create a new connection to the AutoScaling service. 92 Init method to create a new connection to the AutoScaling service.
50 93
51 B{Note:} The host argument is overridden by the host specified in the 94 B{Note:} The host argument is overridden by the host specified in the
52 boto configuration file. 95 boto configuration file.
53 """ 96 """
54 if not region: 97 if not region:
55 region = RegionInfo(self, self.DefaultRegionName, 98 region = RegionInfo(self, self.DefaultRegionName,
56 self.DefaultRegionEndpoint, 99 self.DefaultRegionEndpoint,
57 AutoScaleConnection) 100 AutoScaleConnection)
58 self.region = region 101 self.region = region
59 AWSQueryConnection.__init__(self, aws_access_key_id, 102 AWSQueryConnection.__init__(self, aws_access_key_id,
60 aws_secret_access_key, 103 aws_secret_access_key,
61 is_secure, port, proxy, proxy_port, 104 is_secure, port, proxy, proxy_port,
62 proxy_user, proxy_pass, 105 proxy_user, proxy_pass,
63 self.region.endpoint, debug, 106 self.region.endpoint, debug,
64 https_connection_factory, path=path) 107 https_connection_factory, path=path)
65 108
66 def _required_auth_capability(self): 109 def _required_auth_capability(self):
67 return ['ec2'] 110 return ['ec2']
68 111
69 def build_list_params(self, params, items, label): 112 def build_list_params(self, params, items, label):
70 """ items is a list of dictionaries or strings: 113 """
71 [{'Protocol' : 'HTTP', 114 Items is a list of dictionaries or strings::
72 'LoadBalancerPort' : '80', 115
73 'InstancePort' : '80'},..] etc. 116 [
74 or 117 {
75 ['us-east-1b',...] 118 'Protocol' : 'HTTP',
119 'LoadBalancerPort' : '80',
120 'InstancePort' : '80'
121 },
122 ..
123 ] etc.
124
125 or::
126
127 ['us-east-1b',...]
76 """ 128 """
77 # different from EC2 list params 129 # different from EC2 list params
78 for i in xrange(1, len(items)+1): 130 for i in xrange(1, len(items)+1):
79 if isinstance(items[i-1], dict): 131 if isinstance(items[i-1], dict):
80 for k, v in items[i-1].iteritems(): 132 for k, v in items[i-1].iteritems():
81 params['%s.member.%d.%s' % (label, i, k)] = v 133 if isinstance(v, dict):
134 for kk, vv in v.iteritems():
135 params['%s.member.%d.%s.%s' % (label, i, k, kk)] = v v
136 else:
137 params['%s.member.%d.%s' % (label, i, k)] = v
82 elif isinstance(items[i-1], basestring): 138 elif isinstance(items[i-1], basestring):
83 params['%s.member.%d' % (label, i)] = items[i-1] 139 params['%s.member.%d' % (label, i)] = items[i-1]
84 140
85 def _update_group(self, op, as_group): 141 def _update_group(self, op, as_group):
86 params = { 142 params = {
87 'AutoScalingGroupName' : as_group.name, 143 'AutoScalingGroupName' : as_group.name,
88 'Cooldown' : as_group.cooldown,
89 'LaunchConfigurationName' : as_group.launch_config_name, 144 'LaunchConfigurationName' : as_group.launch_config_name,
90 'MinSize' : as_group.min_size, 145 'MinSize' : as_group.min_size,
91 'MaxSize' : as_group.max_size, 146 'MaxSize' : as_group.max_size,
92 } 147 }
148 # get availability zone information (required param)
149 zones = as_group.availability_zones
150 self.build_list_params(params, zones,
151 'AvailabilityZones')
152 if as_group.desired_capacity:
153 params['DesiredCapacity'] = as_group.desired_capacity
154 if as_group.vpc_zone_identifier:
155 params['VPCZoneIdentifier'] = as_group.vpc_zone_identifier
156 if as_group.health_check_period:
157 params['HealthCheckGracePeriod'] = as_group.health_check_period
158 if as_group.health_check_type:
159 params['HealthCheckType'] = as_group.health_check_type
160 if as_group.default_cooldown:
161 params['DefaultCooldown'] = as_group.default_cooldown
162 if as_group.placement_group:
163 params['PlacementGroup'] = as_group.placement_group
93 if op.startswith('Create'): 164 if op.startswith('Create'):
94 if as_group.availability_zones: 165 # you can only associate load balancers with an autoscale group at c reation time
95 zones = as_group.availability_zones 166 if as_group.load_balancers:
96 else: 167 self.build_list_params(params, as_group.load_balancers,
97 zones = [as_group.availability_zone] 168 'LoadBalancerNames')
98 self.build_list_params(params, as_group.load_balancers,
99 'LoadBalancerNames')
100 self.build_list_params(params, zones,
101 'AvailabilityZones')
102 return self.get_object(op, params, Request) 169 return self.get_object(op, params, Request)
103 170
104 def create_auto_scaling_group(self, as_group): 171 def create_auto_scaling_group(self, as_group):
105 """ 172 """
106 Create auto scaling group. 173 Create auto scaling group.
107 """ 174 """
108 return self._update_group('CreateAutoScalingGroup', as_group) 175 return self._update_group('CreateAutoScalingGroup', as_group)
109 176
177 def delete_auto_scaling_group(self, name, force_delete=False):
178 """
179 Deletes the specified auto scaling group if the group has no instances
180 and no scaling activities in progress.
181 """
182 if(force_delete):
183 params = {'AutoScalingGroupName' : name, 'ForceDelete' : 'true'}
184 else:
185 params = {'AutoScalingGroupName' : name}
186 return self.get_object('DeleteAutoScalingGroup', params, Request)
187
110 def create_launch_configuration(self, launch_config): 188 def create_launch_configuration(self, launch_config):
111 """ 189 """
112 Creates a new Launch Configuration. 190 Creates a new Launch Configuration.
113 191
114 :type launch_config: boto.ec2.autoscale.launchconfig.LaunchConfiguration 192 :type launch_config: :class:`boto.ec2.autoscale.launchconfig.LaunchConfi guration`
115 :param launch_config: LaunchConfiguraiton object. 193 :param launch_config: LaunchConfiguration object.
116 194
117 """ 195 """
118 params = { 196 params = {
119 'ImageId' : launch_config.image_id, 197 'ImageId' : launch_config.image_id,
120 'KeyName' : launch_config.key_name,
121 'LaunchConfigurationName' : launch_config.name, 198 'LaunchConfigurationName' : launch_config.name,
122 'InstanceType' : launch_config.instance_type, 199 'InstanceType' : launch_config.instance_type,
123 } 200 }
201 if launch_config.key_name:
202 params['KeyName'] = launch_config.key_name
124 if launch_config.user_data: 203 if launch_config.user_data:
125 params['UserData'] = launch_config.user_data 204 params['UserData'] = base64.b64encode(launch_config.user_data)
126 if launch_config.kernel_id: 205 if launch_config.kernel_id:
127 params['KernelId'] = launch_config.kernel_id 206 params['KernelId'] = launch_config.kernel_id
128 if launch_config.ramdisk_id: 207 if launch_config.ramdisk_id:
129 params['RamdiskId'] = launch_config.ramdisk_id 208 params['RamdiskId'] = launch_config.ramdisk_id
130 if launch_config.block_device_mappings: 209 if launch_config.block_device_mappings:
131 self.build_list_params(params, launch_config.block_device_mappings, 210 self.build_list_params(params, launch_config.block_device_mappings,
132 'BlockDeviceMappings') 211 'BlockDeviceMappings')
133 self.build_list_params(params, launch_config.security_groups, 212 if launch_config.security_groups:
134 'SecurityGroups') 213 self.build_list_params(params, launch_config.security_groups,
214 'SecurityGroups')
215 if launch_config.instance_monitoring:
216 params['InstanceMonitoring.member.Enabled'] = 'true'
135 return self.get_object('CreateLaunchConfiguration', params, 217 return self.get_object('CreateLaunchConfiguration', params,
136 Request, verb='POST') 218 Request, verb='POST')
137 219
138 def create_trigger(self, trigger): 220 def create_scaling_policy(self, scaling_policy):
139 """ 221 """
140 222 Creates a new Scaling Policy.
141 """ 223
142 params = {'TriggerName' : trigger.name, 224 :type scaling_policy: :class:`boto.ec2.autoscale.policy.ScalingPolicy`
143 'AutoScalingGroupName' : trigger.autoscale_group.name, 225 :param scaling_policy: ScalingPolicy object.
144 'MeasureName' : trigger.measure_name, 226 """
145 'Statistic' : trigger.statistic, 227 params = {'AdjustmentType' : scaling_policy.adjustment_type,
146 'Period' : trigger.period, 228 'AutoScalingGroupName': scaling_policy.as_name,
147 'Unit' : trigger.unit, 229 'PolicyName' : scaling_policy.name,
148 'LowerThreshold' : trigger.lower_threshold, 230 'ScalingAdjustment' : scaling_policy.scaling_adjustment,}
149 'LowerBreachScaleIncrement' : trigger.lower_breach_scale_inc rement, 231
150 'UpperThreshold' : trigger.upper_threshold, 232 if scaling_policy.cooldown is not None:
151 'UpperBreachScaleIncrement' : trigger.upper_breach_scale_inc rement, 233 params['Cooldown'] = scaling_policy.cooldown
152 'BreachDuration' : trigger.breach_duration} 234
153 # dimensions should be a list of tuples 235 return self.get_object('PutScalingPolicy', params, Request)
154 dimensions = [] 236
155 for dim in trigger.dimensions: 237 def delete_launch_configuration(self, launch_config_name):
156 name, value = dim 238 """
157 dimensions.append(dict(Name=name, Value=value)) 239 Deletes the specified LaunchConfiguration.
158 self.build_list_params(params, dimensions, 'Dimensions') 240
159 241 The specified launch configuration must not be attached to an Auto
160 req = self.get_object('CreateOrUpdateScalingTrigger', params, 242 Scaling group. Once this call completes, the launch configuration is no
161 Request) 243 longer available for use.
162 return req 244 """
163 245 params = {'LaunchConfigurationName' : launch_config_name}
164 def get_all_groups(self, names=None): 246 return self.get_object('DeleteLaunchConfiguration', params, Request)
165 """ 247
166 """ 248 def get_all_groups(self, names=None, max_records=None, next_token=None):
167 params = {} 249 """
250 Returns a full description of each Auto Scaling group in the given
251 list. This includes all Amazon EC2 instances that are members of the
252 group. If a list of names is not provided, the service returns the full
253 details of all Auto Scaling groups.
254
255 This action supports pagination by returning a token if there are more
256 pages to retrieve. To get the next page, call this action again with
257 the returned token as the NextToken parameter.
258
259 :type names: list
260 :param names: List of group names which should be searched for.
261
262 :type max_records: int
263 :param max_records: Maximum amount of groups to return.
264
265 :rtype: list
266 :returns: List of :class:`boto.ec2.autoscale.group.AutoScalingGroup` ins tances.
267 """
268 params = {}
269 if max_records:
270 params['MaxRecords'] = max_records
271 if next_token:
272 params['NextToken'] = next_token
168 if names: 273 if names:
169 self.build_list_params(params, names, 'AutoScalingGroupNames') 274 self.build_list_params(params, names, 'AutoScalingGroupNames')
170 return self.get_list('DescribeAutoScalingGroups', params, 275 return self.get_list('DescribeAutoScalingGroups', params,
171 [('member', AutoScalingGroup)]) 276 [('member', AutoScalingGroup)])
172 277
173 def get_all_launch_configurations(self, names=None): 278 def get_all_launch_configurations(self, **kwargs):
174 """ 279 """
175 """ 280 Returns a full description of the launch configurations given the
176 params = {} 281 specified names.
282
283 If no names are specified, then the full details of all launch
284 configurations are returned.
285
286 :type names: list
287 :param names: List of configuration names which should be searched for.
288
289 :type max_records: int
290 :param max_records: Maximum amount of configurations to return.
291
292 :type next_token: str
293 :param next_token: If you have more results than can be returned at once , pass in this
294 parameter to page through all results.
295
296 :rtype: list
297 :returns: List of :class:`boto.ec2.autoscale.launchconfig.LaunchConfigur ation` instances.
298 """
299 params = {}
300 max_records = kwargs.get('max_records', None)
301 names = kwargs.get('names', None)
302 if max_records is not None:
303 params['MaxRecords'] = max_records
177 if names: 304 if names:
178 self.build_list_params(params, names, 'LaunchConfigurationNames') 305 self.build_list_params(params, names, 'LaunchConfigurationNames')
306 next_token = kwargs.get('next_token')
307 if next_token:
308 params['NextToken'] = next_token
179 return self.get_list('DescribeLaunchConfigurations', params, 309 return self.get_list('DescribeLaunchConfigurations', params,
180 [('member', LaunchConfiguration)]) 310 [('member', LaunchConfiguration)])
181 311
182 def get_all_activities(self, autoscale_group, 312 def get_all_activities(self, autoscale_group, activity_ids=None, max_records =None, next_token=None):
183 activity_ids=None,
184 max_records=100):
185 """ 313 """
186 Get all activities for the given autoscaling group. 314 Get all activities for the given autoscaling group.
187 315
188 :type autoscale_group: str or AutoScalingGroup object 316 This action supports pagination by returning a token if there are more
317 pages to retrieve. To get the next page, call this action again with
318 the returned token as the NextToken parameter
319
320 :type autoscale_group: str or :class:`boto.ec2.autoscale.group.AutoScali ngGroup` object
189 :param autoscale_group: The auto scaling group to get activities on. 321 :param autoscale_group: The auto scaling group to get activities on.
190 322
191 @max_records: int 323 :type max_records: int
192 :param max_records: Maximum amount of activities to return. 324 :param max_records: Maximum amount of activities to return.
325
326 :rtype: list
327 :returns: List of :class:`boto.ec2.autoscale.activity.Activity` instance s.
193 """ 328 """
194 name = autoscale_group 329 name = autoscale_group
195 if isinstance(autoscale_group, AutoScalingGroup): 330 if isinstance(autoscale_group, AutoScalingGroup):
196 name = autoscale_group.name 331 name = autoscale_group.name
197 params = {'AutoScalingGroupName' : name} 332 params = {'AutoScalingGroupName' : name}
333 if max_records:
334 params['MaxRecords'] = max_records
335 if next_token:
336 params['NextToken'] = next_token
198 if activity_ids: 337 if activity_ids:
199 self.build_list_params(params, activity_ids, 'ActivityIds') 338 self.build_list_params(params, activity_ids, 'ActivityIds')
200 return self.get_list('DescribeScalingActivities', params, 339 return self.get_list('DescribeScalingActivities',
201 [('member', Activity)]) 340 params, [('member', Activity)])
202 341
203 def get_all_triggers(self, autoscale_group): 342 def delete_scheduled_action(self, scheduled_action_name,
204 params = {'AutoScalingGroupName' : autoscale_group} 343 autoscale_group=None):
205 return self.get_list('DescribeTriggers', params, 344 """
206 [('member', Trigger)]) 345 Deletes a previously scheduled action.
346
347 :param str scheduled_action_name: The name of the action you want
348 to delete.
349 :param str autoscale_group: The name of the autoscale group.
350 """
351 params = {'ScheduledActionName' : scheduled_action_name}
352 if autoscale_group:
353 params['AutoScalingGroupName'] = autoscale_group
354 return self.get_status('DeleteScheduledAction', params)
207 355
208 def terminate_instance(self, instance_id, decrement_capacity=True): 356 def terminate_instance(self, instance_id, decrement_capacity=True):
209 params = { 357 """
210 'InstanceId' : instance_id, 358 Terminates the specified instance. The desired group size can
211 'ShouldDecrementDesiredCapacity' : decrement_capacity 359 also be adjusted, if desired.
212 } 360
361 :param str instance_id: The ID of the instance to be terminated.
362 :param bool decrement_capacity: Whether to decrement the size of the
363 autoscaling group or not.
364 """
365 params = {'InstanceId' : instance_id}
366 if decrement_capacity:
367 params['ShouldDecrementDesiredCapacity'] = 'true'
368 else:
369 params['ShouldDecrementDesiredCapacity'] = 'false'
213 return self.get_object('TerminateInstanceInAutoScalingGroup', params, 370 return self.get_object('TerminateInstanceInAutoScalingGroup', params,
214 Activity) 371 Activity)
215 372
373 def delete_policy(self, policy_name, autoscale_group=None):
374 """
375 Delete a policy.
376
377 :type policy_name: str
378 :param policy_name: The name or ARN of the policy to delete.
379
380 :type autoscale_group: str
381 :param autoscale_group: The name of the autoscale group.
382 """
383 params = {'PolicyName': policy_name}
384 if autoscale_group:
385 params['AutoScalingGroupName'] = autoscale_group
386 return self.get_status('DeletePolicy', params)
387
388 def get_all_adjustment_types(self):
389 return self.get_list('DescribeAdjustmentTypes', {}, [('member', Adjustme ntType)])
390
391 def get_all_autoscaling_instances(self, instance_ids=None,
392 max_records=None, next_token=None):
393 """
394 Returns a description of each Auto Scaling instance in the instance_ids
395 list. If a list is not provided, the service returns the full details
396 of all instances up to a maximum of fifty.
397
398 This action supports pagination by returning a token if there are more
399 pages to retrieve. To get the next page, call this action again with
400 the returned token as the NextToken parameter.
401
402 :type instance_ids: list
403 :param instance_ids: List of Autoscaling Instance IDs which should be
404 searched for.
405
406 :type max_records: int
407 :param max_records: Maximum number of results to return.
408
409 :rtype: list
410 :returns: List of :class:`boto.ec2.autoscale.activity.Activity` instance s.
411 """
412 params = {}
413 if instance_ids:
414 self.build_list_params(params, instance_ids, 'InstanceIds')
415 if max_records:
416 params['MaxRecords'] = max_records
417 if next_token:
418 params['NextToken'] = next_token
419 return self.get_list('DescribeAutoScalingInstances',
420 params, [('member', Instance)])
421
422 def get_all_metric_collection_types(self):
423 """
424 Returns a list of metrics and a corresponding list of granularities
425 for each metric.
426 """
427 return self.get_object('DescribeMetricCollectionTypes',
428 {}, MetricCollectionTypes)
429
430 def get_all_policies(self, as_group=None, policy_names=None,
431 max_records=None, next_token=None):
432 """
433 Returns descriptions of what each policy does. This action supports
434 pagination. If the response includes a token, there are more records
435 available. To get the additional records, repeat the request with the
436 response token as the NextToken parameter.
437
438 If no group name or list of policy names are provided, all available pol icies
439 are returned.
440
441 :type as_name: str
442 :param as_name: the name of the :class:`boto.ec2.autoscale.group.AutoSca lingGroup` to filter for.
443
444 :type names: list
445 :param names: List of policy names which should be searched for.
446
447 :type max_records: int
448 :param max_records: Maximum amount of groups to return.
449 """
450 params = {}
451 if as_group:
452 params['AutoScalingGroupName'] = as_group
453 if policy_names:
454 self.build_list_params(params, policy_names, 'PolicyNames')
455 if max_records:
456 params['MaxRecords'] = max_records
457 if next_token:
458 params['NextToken'] = next_token
459 return self.get_list('DescribePolicies', params,
460 [('member', ScalingPolicy)])
461
462 def get_all_scaling_process_types(self):
463 """ Returns scaling process types for use in the ResumeProcesses and
464 SuspendProcesses actions.
465 """
466 return self.get_list('DescribeScalingProcessTypes', {},
467 [('member', ProcessType)])
468
469 def suspend_processes(self, as_group, scaling_processes=None):
470 """ Suspends Auto Scaling processes for an Auto Scaling group.
471
472 :type as_group: string
473 :param as_group: The auto scaling group to suspend processes on.
474
475 :type scaling_processes: list
476 :param scaling_processes: Processes you want to suspend. If omitted, all
477 processes will be suspended.
478 """
479 params = {'AutoScalingGroupName' : as_group}
480 if scaling_processes:
481 self.build_list_params(params, scaling_processes, 'ScalingProcesses' )
482 return self.get_status('SuspendProcesses', params)
483
484 def resume_processes(self, as_group, scaling_processes=None):
485 """ Resumes Auto Scaling processes for an Auto Scaling group.
486
487 :type as_group: string
488 :param as_group: The auto scaling group to resume processes on.
489
490 :type scaling_processes: list
491 :param scaling_processes: Processes you want to resume. If omitted, all
492 processes will be resumed.
493 """
494 params = {
495 'AutoScalingGroupName' : as_group
496 }
497 if scaling_processes:
498 self.build_list_params(params, scaling_processes, 'ScalingProcesses' )
499 return self.get_status('ResumeProcesses', params)
500
501 def create_scheduled_group_action(self, as_group, name, time, desired_capaci ty=None,
502 min_size=None, max_size=None):
503 """ Creates a scheduled scaling action for a Auto Scaling group. If you
504 leave a parameter unspecified, the corresponding value remains
505 unchanged in the affected Auto Scaling group.
506
507 :type as_group: string
508 :param as_group: The auto scaling group to get activities on.
509
510 :type name: string
511 :param name: Scheduled action name.
512
513 :type time: datetime.datetime
514 :param time: The time for this action to start.
515
516 :type desired_capacity: int
517 :param desired_capacity: The number of EC2 instances that should be runn ing in
518 this group.
519
520 :type min_size: int
521 :param min_size: The minimum size for the new auto scaling group.
522
523 :type max_size: int
524 :param max_size: The minimum size for the new auto scaling group.
525 """
526 params = {
527 'AutoScalingGroupName' : as_group,
528 'ScheduledActionName' : name,
529 'Time' : time.isoformat(),
530 }
531 if desired_capacity is not None:
532 params['DesiredCapacity'] = desired_capacity
533 if min_size is not None:
534 params['MinSize'] = min_size
535 if max_size is not None:
536 params['MaxSize'] = max_size
537 return self.get_status('PutScheduledUpdateGroupAction', params)
538
539 def get_all_scheduled_actions(self, as_group=None, start_time=None, end_time =None, scheduled_actions=None,
540 max_records=None, next_token=None):
541 params = {}
542 if as_group:
543 params['AutoScalingGroupName'] = as_group
544 if scheduled_actions:
545 self.build_list_params(params, scheduled_actions, 'ScheduledActionNa mes')
546 if max_records:
547 params['MaxRecords'] = max_records
548 if next_token:
549 params['NextToken'] = next_token
550 return self.get_list('DescribeScheduledActions', params, [('member', Sch eduledUpdateGroupAction)])
551
552 def disable_metrics_collection(self, as_group, metrics=None):
553 """
554 Disables monitoring of group metrics for the Auto Scaling group
555 specified in AutoScalingGroupName. You can specify the list of affected
556 metrics with the Metrics parameter.
557 """
558 params = {
559 'AutoScalingGroupName' : as_group,
560 }
561 if metrics:
562 self.build_list_params(params, metrics, 'Metrics')
563 return self.get_status('DisableMetricsCollection', params)
564
565 def enable_metrics_collection(self, as_group, granularity, metrics=None):
566 """
567 Enables monitoring of group metrics for the Auto Scaling group
568 specified in AutoScalingGroupName. You can specify the list of enabled
569 metrics with the Metrics parameter.
570
571 Auto scaling metrics collection can be turned on only if the
572 InstanceMonitoring.Enabled flag, in the Auto Scaling group's launch
573 configuration, is set to true.
574
575 :type autoscale_group: string
576 :param autoscale_group: The auto scaling group to get activities on.
577
578 :type granularity: string
579 :param granularity: The granularity to associate with the metrics to
580 collect. Currently, the only legal granularity is "1 Minute".
581
582 :type metrics: string list
583 :param metrics: The list of metrics to collect. If no metrics are
584 specified, all metrics are enabled.
585 """
586 params = {
587 'AutoScalingGroupName' : as_group,
588 'Granularity' : granularity,
589 }
590 if metrics:
591 self.build_list_params(params, metrics, 'Metrics')
592 return self.get_status('EnableMetricsCollection', params)
593
594 def execute_policy(self, policy_name, as_group=None, honor_cooldown=None):
595 params = {
596 'PolicyName' : policy_name,
597 }
598 if as_group:
599 params['AutoScalingGroupName'] = as_group
600 if honor_cooldown:
601 params['HonorCooldown'] = honor_cooldown
602 return self.get_status('ExecutePolicy', params)
603
216 def set_instance_health(self, instance_id, health_status, 604 def set_instance_health(self, instance_id, health_status,
217 should_respect_grace_period=True): 605 should_respect_grace_period=True):
218 """ 606 """
219 Explicitly set the health status of an instance. 607 Explicitly set the health status of an instance.
220 608
221 :type instance_id: str 609 :type instance_id: str
222 :param instance_id: The identifier of the EC2 instance. 610 :param instance_id: The identifier of the EC2 instance.
223 611
224 :type health_status: str 612 :type health_status: str
225 :param health_status: The health status of the instance. 613 :param health_status: The health status of the instance.
226 "Healthy" means that the instance is 614 "Healthy" means that the instance is
227 healthy and should remain in service. 615 healthy and should remain in service.
228 "Unhealthy" means that the instance is 616 "Unhealthy" means that the instance is
229 unhealthy. Auto Scaling should terminate 617 unhealthy. Auto Scaling should terminate
230 and replace it. 618 and replace it.
231 619
232 :type should_respect_grace_period: bool 620 :type should_respect_grace_period: bool
233 :param should_respect_grace_period: If True, this call should 621 :param should_respect_grace_period: If True, this call should
234 respect the grace period 622 respect the grace period
235 associated with the group. 623 associated with the group.
236 """ 624 """
237 params = {'InstanceId' : instance_id, 625 params = {'InstanceId' : instance_id,
238 'HealthStatus' : health_status} 626 'HealthStatus' : health_status}
239 if should_respect_grace_period: 627 if should_respect_grace_period:
240 params['ShouldRespectGracePeriod'] = 'true' 628 params['ShouldRespectGracePeriod'] = 'true'
241 else: 629 else:
242 params['ShouldRespectGracePeriod'] = 'false' 630 params['ShouldRespectGracePeriod'] = 'false'
243 return self.get_status('SetInstanceHealth', params) 631 return self.get_status('SetInstanceHealth', params)
244 632
OLDNEW
« no previous file with comments | « boto/ec2/address.py ('k') | boto/ec2/autoscale/activity.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698