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

Side by Side Diff: third_party/gsutil/boto/boto/ec2/autoscale/__init__.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: Review fixes, updated gsutil 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-2011 Reza Lotun http://reza.lotun.name/
2 # Copyright (c) 2011 Jann Kleen
3 # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
4 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish, dis-
10 # tribute, sublicense, and/or sell copies of the Software, and to permit
11 # persons to whom the Software is furnished to do so, subject to the fol-
12 # lowing conditions:
13 #
14 # The above copyright notice and this permission notice shall be included
15 # in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
19 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
20 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24
25 """
26 This module provides an interface to the Elastic Compute Cloud (EC2)
27 Auto Scaling service.
28 """
29
30 import base64
31
32 import boto
33 from boto.connection import AWSQueryConnection
34 from boto.ec2.regioninfo import RegionInfo
35 from boto.ec2.autoscale.request import Request
36 from boto.ec2.autoscale.launchconfig import LaunchConfiguration
37 from boto.ec2.autoscale.group import AutoScalingGroup
38 from boto.ec2.autoscale.group import ProcessType
39 from boto.ec2.autoscale.activity import Activity
40 from boto.ec2.autoscale.policy import AdjustmentType
41 from boto.ec2.autoscale.policy import MetricCollectionTypes
42 from boto.ec2.autoscale.policy import ScalingPolicy
43 from boto.ec2.autoscale.policy import TerminationPolicies
44 from boto.ec2.autoscale.instance import Instance
45 from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction
46 from boto.ec2.autoscale.tag import Tag
47
48 RegionData = {
49 'us-east-1': 'autoscaling.us-east-1.amazonaws.com',
50 'us-west-1': 'autoscaling.us-west-1.amazonaws.com',
51 'us-west-2': 'autoscaling.us-west-2.amazonaws.com',
52 'sa-east-1': 'autoscaling.sa-east-1.amazonaws.com',
53 'eu-west-1': 'autoscaling.eu-west-1.amazonaws.com',
54 'ap-northeast-1': 'autoscaling.ap-northeast-1.amazonaws.com',
55 'ap-southeast-1': 'autoscaling.ap-southeast-1.amazonaws.com',
56 'ap-southeast-2': 'autoscaling.ap-southeast-2.amazonaws.com',
57 }
58
59
60 def regions():
61 """
62 Get all available regions for the Auto Scaling service.
63
64 :rtype: list
65 :return: A list of :class:`boto.RegionInfo` instances
66 """
67 regions = []
68 for region_name in RegionData:
69 region = RegionInfo(name=region_name,
70 endpoint=RegionData[region_name],
71 connection_cls=AutoScaleConnection)
72 regions.append(region)
73 return regions
74
75
76 def connect_to_region(region_name, **kw_params):
77 """
78 Given a valid region name, return a
79 :class:`boto.ec2.autoscale.AutoScaleConnection`.
80
81 :param str region_name: The name of the region to connect to.
82
83 :rtype: :class:`boto.ec2.AutoScaleConnection` or ``None``
84 :return: A connection to the given region, or None if an invalid region
85 name is given
86 """
87 for region in regions():
88 if region.name == region_name:
89 return region.connect(**kw_params)
90 return None
91
92
93 class AutoScaleConnection(AWSQueryConnection):
94 APIVersion = boto.config.get('Boto', 'autoscale_version', '2011-01-01')
95 DefaultRegionEndpoint = boto.config.get('Boto', 'autoscale_endpoint',
96 'autoscaling.us-east-1.amazonaws.com ')
97 DefaultRegionName = boto.config.get('Boto', 'autoscale_region_name',
98 'us-east-1')
99
100 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
101 is_secure=True, port=None, proxy=None, proxy_port=None,
102 proxy_user=None, proxy_pass=None, debug=0,
103 https_connection_factory=None, region=None, path='/',
104 security_token=None, validate_certs=True):
105 """
106 Init method to create a new connection to the AutoScaling service.
107
108 B{Note:} The host argument is overridden by the host specified in the
109 boto configuration file.
110 """
111 if not region:
112 region = RegionInfo(self, self.DefaultRegionName,
113 self.DefaultRegionEndpoint,
114 AutoScaleConnection)
115 self.region = region
116 AWSQueryConnection.__init__(self, aws_access_key_id,
117 aws_secret_access_key,
118 is_secure, port, proxy, proxy_port,
119 proxy_user, proxy_pass,
120 self.region.endpoint, debug,
121 https_connection_factory, path=path,
122 security_token=security_token,
123 validate_certs=validate_certs)
124
125 def _required_auth_capability(self):
126 return ['hmac-v4']
127
128 def build_list_params(self, params, items, label):
129 """
130 Items is a list of dictionaries or strings::
131
132 [
133 {
134 'Protocol' : 'HTTP',
135 'LoadBalancerPort' : '80',
136 'InstancePort' : '80'
137 },
138 ..
139 ] etc.
140
141 or::
142
143 ['us-east-1b',...]
144 """
145 # different from EC2 list params
146 for i in xrange(1, len(items) + 1):
147 if isinstance(items[i - 1], dict):
148 for k, v in items[i - 1].iteritems():
149 if isinstance(v, dict):
150 for kk, vv in v.iteritems():
151 params['%s.member.%d.%s.%s' % (label, i, k, kk)] = v v
152 else:
153 params['%s.member.%d.%s' % (label, i, k)] = v
154 elif isinstance(items[i - 1], basestring):
155 params['%s.member.%d' % (label, i)] = items[i - 1]
156
157 def _update_group(self, op, as_group):
158 params = {'AutoScalingGroupName': as_group.name,
159 'LaunchConfigurationName': as_group.launch_config_name,
160 'MinSize': as_group.min_size,
161 'MaxSize': as_group.max_size}
162 # get availability zone information (required param)
163 zones = as_group.availability_zones
164 self.build_list_params(params, zones, 'AvailabilityZones')
165 if as_group.desired_capacity:
166 params['DesiredCapacity'] = as_group.desired_capacity
167 if as_group.vpc_zone_identifier:
168 params['VPCZoneIdentifier'] = as_group.vpc_zone_identifier
169 if as_group.health_check_period:
170 params['HealthCheckGracePeriod'] = as_group.health_check_period
171 if as_group.health_check_type:
172 params['HealthCheckType'] = as_group.health_check_type
173 if as_group.default_cooldown:
174 params['DefaultCooldown'] = as_group.default_cooldown
175 if as_group.placement_group:
176 params['PlacementGroup'] = as_group.placement_group
177 if as_group.termination_policies:
178 self.build_list_params(params, as_group.termination_policies,
179 'TerminationPolicies')
180 if op.startswith('Create'):
181 # you can only associate load balancers with an autoscale
182 # group at creation time
183 if as_group.load_balancers:
184 self.build_list_params(params, as_group.load_balancers,
185 'LoadBalancerNames')
186 if as_group.tags:
187 for i, tag in enumerate(as_group.tags):
188 tag.build_params(params, i + 1)
189 return self.get_object(op, params, Request)
190
191 def create_auto_scaling_group(self, as_group):
192 """
193 Create auto scaling group.
194 """
195 return self._update_group('CreateAutoScalingGroup', as_group)
196
197 def delete_auto_scaling_group(self, name, force_delete=False):
198 """
199 Deletes the specified auto scaling group if the group has no instances
200 and no scaling activities in progress.
201 """
202 if(force_delete):
203 params = {'AutoScalingGroupName': name, 'ForceDelete': 'true'}
204 else:
205 params = {'AutoScalingGroupName': name}
206 return self.get_object('DeleteAutoScalingGroup', params, Request)
207
208 def create_launch_configuration(self, launch_config):
209 """
210 Creates a new Launch Configuration.
211
212 :type launch_config: :class:`boto.ec2.autoscale.launchconfig.LaunchConfi guration`
213 :param launch_config: LaunchConfiguration object.
214 """
215 params = {'ImageId': launch_config.image_id,
216 'LaunchConfigurationName': launch_config.name,
217 'InstanceType': launch_config.instance_type}
218 if launch_config.key_name:
219 params['KeyName'] = launch_config.key_name
220 if launch_config.user_data:
221 params['UserData'] = base64.b64encode(launch_config.user_data)
222 if launch_config.kernel_id:
223 params['KernelId'] = launch_config.kernel_id
224 if launch_config.ramdisk_id:
225 params['RamdiskId'] = launch_config.ramdisk_id
226 if launch_config.block_device_mappings:
227 self.build_list_params(params, launch_config.block_device_mappings,
228 'BlockDeviceMappings')
229 if launch_config.security_groups:
230 self.build_list_params(params, launch_config.security_groups,
231 'SecurityGroups')
232 if launch_config.instance_monitoring:
233 params['InstanceMonitoring.Enabled'] = 'true'
234 else:
235 params['InstanceMonitoring.Enabled'] = 'false'
236 if launch_config.spot_price is not None:
237 params['SpotPrice'] = str(launch_config.spot_price)
238 if launch_config.instance_profile_name is not None:
239 params['IamInstanceProfile'] = launch_config.instance_profile_name
240 return self.get_object('CreateLaunchConfiguration', params,
241 Request, verb='POST')
242
243 def create_scaling_policy(self, scaling_policy):
244 """
245 Creates a new Scaling Policy.
246
247 :type scaling_policy: :class:`boto.ec2.autoscale.policy.ScalingPolicy`
248 :param scaling_policy: ScalingPolicy object.
249 """
250 params = {'AdjustmentType': scaling_policy.adjustment_type,
251 'AutoScalingGroupName': scaling_policy.as_name,
252 'PolicyName': scaling_policy.name,
253 'ScalingAdjustment': scaling_policy.scaling_adjustment}
254 if scaling_policy.cooldown is not None:
255 params['Cooldown'] = scaling_policy.cooldown
256
257 return self.get_object('PutScalingPolicy', params, Request)
258
259 def delete_launch_configuration(self, launch_config_name):
260 """
261 Deletes the specified LaunchConfiguration.
262
263 The specified launch configuration must not be attached to an Auto
264 Scaling group. Once this call completes, the launch configuration is no
265 longer available for use.
266 """
267 params = {'LaunchConfigurationName': launch_config_name}
268 return self.get_object('DeleteLaunchConfiguration', params, Request)
269
270 def get_all_groups(self, names=None, max_records=None, next_token=None):
271 """
272 Returns a full description of each Auto Scaling group in the given
273 list. This includes all Amazon EC2 instances that are members of the
274 group. If a list of names is not provided, the service returns the full
275 details of all Auto Scaling groups.
276
277 This action supports pagination by returning a token if there are more
278 pages to retrieve. To get the next page, call this action again with
279 the returned token as the NextToken parameter.
280
281 :type names: list
282 :param names: List of group names which should be searched for.
283
284 :type max_records: int
285 :param max_records: Maximum amount of groups to return.
286
287 :rtype: list
288 :returns: List of :class:`boto.ec2.autoscale.group.AutoScalingGroup`
289 instances.
290 """
291 params = {}
292 if max_records:
293 params['MaxRecords'] = max_records
294 if next_token:
295 params['NextToken'] = next_token
296 if names:
297 self.build_list_params(params, names, 'AutoScalingGroupNames')
298 return self.get_list('DescribeAutoScalingGroups', params,
299 [('member', AutoScalingGroup)])
300
301 def get_all_launch_configurations(self, **kwargs):
302 """
303 Returns a full description of the launch configurations given the
304 specified names.
305
306 If no names are specified, then the full details of all launch
307 configurations are returned.
308
309 :type names: list
310 :param names: List of configuration names which should be searched for.
311
312 :type max_records: int
313 :param max_records: Maximum amount of configurations to return.
314
315 :type next_token: str
316 :param next_token: If you have more results than can be returned
317 at once, pass in this parameter to page through all results.
318
319 :rtype: list
320 :returns: List of
321 :class:`boto.ec2.autoscale.launchconfig.LaunchConfiguration`
322 instances.
323 """
324 params = {}
325 max_records = kwargs.get('max_records', None)
326 names = kwargs.get('names', None)
327 if max_records is not None:
328 params['MaxRecords'] = max_records
329 if names:
330 self.build_list_params(params, names, 'LaunchConfigurationNames')
331 next_token = kwargs.get('next_token')
332 if next_token:
333 params['NextToken'] = next_token
334 return self.get_list('DescribeLaunchConfigurations', params,
335 [('member', LaunchConfiguration)])
336
337 def get_all_activities(self, autoscale_group, activity_ids=None,
338 max_records=None, next_token=None):
339 """
340 Get all activities for the given autoscaling group.
341
342 This action supports pagination by returning a token if there are more
343 pages to retrieve. To get the next page, call this action again with
344 the returned token as the NextToken parameter
345
346 :type autoscale_group: str or
347 :class:`boto.ec2.autoscale.group.AutoScalingGroup` object
348 :param autoscale_group: The auto scaling group to get activities on.
349
350 :type max_records: int
351 :param max_records: Maximum amount of activities to return.
352
353 :rtype: list
354 :returns: List of
355 :class:`boto.ec2.autoscale.activity.Activity` instances.
356 """
357 name = autoscale_group
358 if isinstance(autoscale_group, AutoScalingGroup):
359 name = autoscale_group.name
360 params = {'AutoScalingGroupName': name}
361 if max_records:
362 params['MaxRecords'] = max_records
363 if next_token:
364 params['NextToken'] = next_token
365 if activity_ids:
366 self.build_list_params(params, activity_ids, 'ActivityIds')
367 return self.get_list('DescribeScalingActivities',
368 params, [('member', Activity)])
369
370 def get_termination_policies(self):
371 """Gets all valid termination policies.
372
373 These values can then be used as the termination_policies arg
374 when creating and updating autoscale groups.
375 """
376 return self.get_object('DescribeTerminationPolicyTypes',
377 {}, TerminationPolicies)
378
379 def delete_scheduled_action(self, scheduled_action_name,
380 autoscale_group=None):
381 """
382 Deletes a previously scheduled action.
383
384 :type scheduled_action_name: str
385 :param scheduled_action_name: The name of the action you want
386 to delete.
387
388 :type autoscale_group: str
389 :param autoscale_group: The name of the autoscale group.
390 """
391 params = {'ScheduledActionName': scheduled_action_name}
392 if autoscale_group:
393 params['AutoScalingGroupName'] = autoscale_group
394 return self.get_status('DeleteScheduledAction', params)
395
396 def terminate_instance(self, instance_id, decrement_capacity=True):
397 """
398 Terminates the specified instance. The desired group size can
399 also be adjusted, if desired.
400
401 :type instance_id: str
402 :param instance_id: The ID of the instance to be terminated.
403
404 :type decrement_capability: bool
405 :param decrement_capacity: Whether to decrement the size of the
406 autoscaling group or not.
407 """
408 params = {'InstanceId': instance_id}
409 if decrement_capacity:
410 params['ShouldDecrementDesiredCapacity'] = 'true'
411 else:
412 params['ShouldDecrementDesiredCapacity'] = 'false'
413 return self.get_object('TerminateInstanceInAutoScalingGroup', params,
414 Activity)
415
416 def delete_policy(self, policy_name, autoscale_group=None):
417 """
418 Delete a policy.
419
420 :type policy_name: str
421 :param policy_name: The name or ARN of the policy to delete.
422
423 :type autoscale_group: str
424 :param autoscale_group: The name of the autoscale group.
425 """
426 params = {'PolicyName': policy_name}
427 if autoscale_group:
428 params['AutoScalingGroupName'] = autoscale_group
429 return self.get_status('DeletePolicy', params)
430
431 def get_all_adjustment_types(self):
432 return self.get_list('DescribeAdjustmentTypes', {},
433 [('member', AdjustmentType)])
434
435 def get_all_autoscaling_instances(self, instance_ids=None,
436 max_records=None, next_token=None):
437 """
438 Returns a description of each Auto Scaling instance in the instance_ids
439 list. If a list is not provided, the service returns the full details
440 of all instances up to a maximum of fifty.
441
442 This action supports pagination by returning a token if there are more
443 pages to retrieve. To get the next page, call this action again with
444 the returned token as the NextToken parameter.
445
446 :type instance_ids: list
447 :param instance_ids: List of Autoscaling Instance IDs which should be
448 searched for.
449
450 :type max_records: int
451 :param max_records: Maximum number of results to return.
452
453 :rtype: list
454 :returns: List of
455 :class:`boto.ec2.autoscale.instance.Instance` objects.
456 """
457 params = {}
458 if instance_ids:
459 self.build_list_params(params, instance_ids, 'InstanceIds')
460 if max_records:
461 params['MaxRecords'] = max_records
462 if next_token:
463 params['NextToken'] = next_token
464 return self.get_list('DescribeAutoScalingInstances',
465 params, [('member', Instance)])
466
467 def get_all_metric_collection_types(self):
468 """
469 Returns a list of metrics and a corresponding list of granularities
470 for each metric.
471 """
472 return self.get_object('DescribeMetricCollectionTypes',
473 {}, MetricCollectionTypes)
474
475 def get_all_policies(self, as_group=None, policy_names=None,
476 max_records=None, next_token=None):
477 """
478 Returns descriptions of what each policy does. This action supports
479 pagination. If the response includes a token, there are more records
480 available. To get the additional records, repeat the request with the
481 response token as the NextToken parameter.
482
483 If no group name or list of policy names are provided, all
484 available policies are returned.
485
486 :type as_name: str
487 :param as_name: The name of the
488 :class:`boto.ec2.autoscale.group.AutoScalingGroup` to filter for.
489
490 :type names: list
491 :param names: List of policy names which should be searched for.
492
493 :type max_records: int
494 :param max_records: Maximum amount of groups to return.
495 """
496 params = {}
497 if as_group:
498 params['AutoScalingGroupName'] = as_group
499 if policy_names:
500 self.build_list_params(params, policy_names, 'PolicyNames')
501 if max_records:
502 params['MaxRecords'] = max_records
503 if next_token:
504 params['NextToken'] = next_token
505 return self.get_list('DescribePolicies', params,
506 [('member', ScalingPolicy)])
507
508 def get_all_scaling_process_types(self):
509 """
510 Returns scaling process types for use in the ResumeProcesses and
511 SuspendProcesses actions.
512 """
513 return self.get_list('DescribeScalingProcessTypes', {},
514 [('member', ProcessType)])
515
516 def suspend_processes(self, as_group, scaling_processes=None):
517 """
518 Suspends Auto Scaling processes for an Auto Scaling group.
519
520 :type as_group: string
521 :param as_group: The auto scaling group to suspend processes on.
522
523 :type scaling_processes: list
524 :param scaling_processes: Processes you want to suspend. If omitted,
525 all processes will be suspended.
526 """
527 params = {'AutoScalingGroupName': as_group}
528 if scaling_processes:
529 self.build_list_params(params, scaling_processes,
530 'ScalingProcesses')
531 return self.get_status('SuspendProcesses', params)
532
533 def resume_processes(self, as_group, scaling_processes=None):
534 """
535 Resumes Auto Scaling processes for an Auto Scaling group.
536
537 :type as_group: string
538 :param as_group: The auto scaling group to resume processes on.
539
540 :type scaling_processes: list
541 :param scaling_processes: Processes you want to resume. If omitted, all
542 processes will be resumed.
543 """
544 params = {'AutoScalingGroupName': as_group}
545
546 if scaling_processes:
547 self.build_list_params(params, scaling_processes,
548 'ScalingProcesses')
549 return self.get_status('ResumeProcesses', params)
550
551 def create_scheduled_group_action(self, as_group, name, time,
552 desired_capacity=None,
553 min_size=None, max_size=None):
554 """
555 Creates a scheduled scaling action for a Auto Scaling group. If you
556 leave a parameter unspecified, the corresponding value remains
557 unchanged in the affected Auto Scaling group.
558
559 :type as_group: string
560 :param as_group: The auto scaling group to get activities on.
561
562 :type name: string
563 :param name: Scheduled action name.
564
565 :type time: datetime.datetime
566 :param time: The time for this action to start.
567
568 :type desired_capacity: int
569 :param desired_capacity: The number of EC2 instances that should
570 be running in this group.
571
572 :type min_size: int
573 :param min_size: The minimum size for the new auto scaling group.
574
575 :type max_size: int
576 :param max_size: The minimum size for the new auto scaling group.
577 """
578 params = {'AutoScalingGroupName': as_group,
579 'ScheduledActionName': name,
580 'Time': time.isoformat()}
581 if desired_capacity is not None:
582 params['DesiredCapacity'] = desired_capacity
583 if min_size is not None:
584 params['MinSize'] = min_size
585 if max_size is not None:
586 params['MaxSize'] = max_size
587 return self.get_status('PutScheduledUpdateGroupAction', params)
588
589 def get_all_scheduled_actions(self, as_group=None, start_time=None,
590 end_time=None, scheduled_actions=None,
591 max_records=None, next_token=None):
592 params = {}
593 if as_group:
594 params['AutoScalingGroupName'] = as_group
595 if scheduled_actions:
596 self.build_list_params(params, scheduled_actions,
597 'ScheduledActionNames')
598 if max_records:
599 params['MaxRecords'] = max_records
600 if next_token:
601 params['NextToken'] = next_token
602 return self.get_list('DescribeScheduledActions', params,
603 [('member', ScheduledUpdateGroupAction)])
604
605 def disable_metrics_collection(self, as_group, metrics=None):
606 """
607 Disables monitoring of group metrics for the Auto Scaling group
608 specified in AutoScalingGroupName. You can specify the list of affected
609 metrics with the Metrics parameter.
610 """
611 params = {'AutoScalingGroupName': as_group}
612
613 if metrics:
614 self.build_list_params(params, metrics, 'Metrics')
615 return self.get_status('DisableMetricsCollection', params)
616
617 def enable_metrics_collection(self, as_group, granularity, metrics=None):
618 """
619 Enables monitoring of group metrics for the Auto Scaling group
620 specified in AutoScalingGroupName. You can specify the list of enabled
621 metrics with the Metrics parameter.
622
623 Auto scaling metrics collection can be turned on only if the
624 InstanceMonitoring.Enabled flag, in the Auto Scaling group's launch
625 configuration, is set to true.
626
627 :type autoscale_group: string
628 :param autoscale_group: The auto scaling group to get activities on.
629
630 :type granularity: string
631 :param granularity: The granularity to associate with the metrics to
632 collect. Currently, the only legal granularity is "1Minute".
633
634 :type metrics: string list
635 :param metrics: The list of metrics to collect. If no metrics are
636 specified, all metrics are enabled.
637 """
638 params = {'AutoScalingGroupName': as_group,
639 'Granularity': granularity}
640 if metrics:
641 self.build_list_params(params, metrics, 'Metrics')
642 return self.get_status('EnableMetricsCollection', params)
643
644 def execute_policy(self, policy_name, as_group=None, honor_cooldown=None):
645 params = {'PolicyName': policy_name}
646 if as_group:
647 params['AutoScalingGroupName'] = as_group
648 if honor_cooldown:
649 params['HonorCooldown'] = honor_cooldown
650 return self.get_status('ExecutePolicy', params)
651
652 def put_notification_configuration(self, autoscale_group, topic, notificatio n_types):
653 """
654 Configures an Auto Scaling group to send notifications when
655 specified events take place.
656
657 :type as_group: str or
658 :class:`boto.ec2.autoscale.group.AutoScalingGroup` object
659 :param as_group: The Auto Scaling group to put notification
660 configuration on.
661
662 :type topic: str
663 :param topic: The Amazon Resource Name (ARN) of the Amazon Simple
664 Notification Service (SNS) topic.
665
666 :type notification_types: list
667 :param notification_types: The type of events that will trigger
668 the notification.
669 """
670
671 name = autoscale_group
672 if isinstance(autoscale_group, AutoScalingGroup):
673 name = autoscale_group.name
674
675 params = {'AutoScalingGroupName': name,
676 'TopicARN': topic}
677 self.build_list_params(params, notification_types, 'NotificationTypes')
678 return self.get_status('PutNotificationConfiguration', params)
679
680 def set_instance_health(self, instance_id, health_status,
681 should_respect_grace_period=True):
682 """
683 Explicitly set the health status of an instance.
684
685 :type instance_id: str
686 :param instance_id: The identifier of the EC2 instance.
687
688 :type health_status: str
689 :param health_status: The health status of the instance.
690 "Healthy" means that the instance is healthy and should remain
691 in service. "Unhealthy" means that the instance is unhealthy.
692 Auto Scaling should terminate and replace it.
693
694 :type should_respect_grace_period: bool
695 :param should_respect_grace_period: If True, this call should
696 respect the grace period associated with the group.
697 """
698 params = {'InstanceId': instance_id,
699 'HealthStatus': health_status}
700 if should_respect_grace_period:
701 params['ShouldRespectGracePeriod'] = 'true'
702 else:
703 params['ShouldRespectGracePeriod'] = 'false'
704 return self.get_status('SetInstanceHealth', params)
705
706 def set_desired_capacity(self, group_name, desired_capacity, honor_cooldown= False):
707 """
708 Adjusts the desired size of the AutoScalingGroup by initiating scaling
709 activities. When reducing the size of the group, it is not possible to d efine
710 which Amazon EC2 instances will be terminated. This applies to any Auto Scaling
711 decisions that might result in terminating instances.
712
713 :type group_name: string
714 :param group_name: name of the auto scaling group
715
716 :type desired_capacity: integer
717 :param desired_capacity: new capacity setting for auto scaling group
718
719 :type honor_cooldown: boolean
720 :param honor_cooldown: by default, overrides any cooldown period
721 """
722 params = {'AutoScalingGroupName': group_name,
723 'DesiredCapacity': desired_capacity}
724 if honor_cooldown:
725 params['HonorCooldown'] = json.dumps('True')
726
727 return self.get_status('SetDesiredCapacity', params)
728
729 # Tag methods
730
731 def get_all_tags(self, filters=None, max_records=None, next_token=None):
732 """
733 Lists the Auto Scaling group tags.
734
735 This action supports pagination by returning a token if there
736 are more pages to retrieve. To get the next page, call this
737 action again with the returned token as the NextToken
738 parameter.
739
740 :type filters: dict
741 :param filters: The value of the filter type used to identify
742 the tags to be returned. NOT IMPLEMENTED YET.
743
744 :type max_records: int
745 :param max_records: Maximum number of tags to return.
746
747 :rtype: list
748 :returns: List of :class:`boto.ec2.autoscale.tag.Tag`
749 instances.
750 """
751 params = {}
752 if max_records:
753 params['MaxRecords'] = max_records
754 if next_token:
755 params['NextToken'] = next_token
756 return self.get_list('DescribeTags', params,
757 [('member', Tag)])
758
759 def create_or_update_tags(self, tags):
760 """
761 Creates new tags or updates existing tags for an Auto Scaling group.
762
763 :type tags: List of :class:`boto.ec2.autoscale.tag.Tag`
764 :param tags: The new or updated tags.
765 """
766 params = {}
767 for i, tag in enumerate(tags):
768 tag.build_params(params, i + 1)
769 return self.get_status('CreateOrUpdateTags', params, verb='POST')
770
771 def delete_tags(self, tags):
772 """
773 Deletes existing tags for an Auto Scaling group.
774
775 :type tags: List of :class:`boto.ec2.autoscale.tag.Tag`
776 :param tags: The new or updated tags.
777 """
778 params = {}
779 for i, tag in enumerate(tags):
780 tag.build_params(params, i + 1)
781 return self.get_status('DeleteTags', params, verb='POST')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698