comparison env/lib/python3.9/site-packages/boto/ec2/autoscale/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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.regioninfo import RegionInfo, get_regions, load_regions
35 from boto.regioninfo import connect
36 from boto.ec2.autoscale.request import Request
37 from boto.ec2.autoscale.launchconfig import LaunchConfiguration
38 from boto.ec2.autoscale.group import AutoScalingGroup
39 from boto.ec2.autoscale.group import ProcessType
40 from boto.ec2.autoscale.activity import Activity
41 from boto.ec2.autoscale.policy import AdjustmentType
42 from boto.ec2.autoscale.policy import MetricCollectionTypes
43 from boto.ec2.autoscale.policy import ScalingPolicy
44 from boto.ec2.autoscale.policy import TerminationPolicies
45 from boto.ec2.autoscale.instance import Instance
46 from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction
47 from boto.ec2.autoscale.tag import Tag
48 from boto.ec2.autoscale.limits import AccountLimits
49 from boto.compat import six
50
51 RegionData = load_regions().get('autoscaling', {})
52
53
54 def regions():
55 """
56 Get all available regions for the Auto Scaling service.
57
58 :rtype: list
59 :return: A list of :class:`boto.RegionInfo` instances
60 """
61 return get_regions('autoscaling', connection_cls=AutoScaleConnection)
62
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 return connect('autoscaling', region_name,
76 connection_cls=AutoScaleConnection, **kw_params)
77
78
79 class AutoScaleConnection(AWSQueryConnection):
80 APIVersion = boto.config.get('Boto', 'autoscale_version', '2011-01-01')
81 DefaultRegionEndpoint = boto.config.get('Boto', 'autoscale_endpoint',
82 'autoscaling.us-east-1.amazonaws.com')
83 DefaultRegionName = boto.config.get('Boto', 'autoscale_region_name',
84 'us-east-1')
85
86 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
87 is_secure=True, port=None, proxy=None, proxy_port=None,
88 proxy_user=None, proxy_pass=None, debug=0,
89 https_connection_factory=None, region=None, path='/',
90 security_token=None, validate_certs=True, profile_name=None,
91 use_block_device_types=False):
92 """
93 Init method to create a new connection to the AutoScaling service.
94
95 B{Note:} The host argument is overridden by the host specified in the
96 boto configuration file.
97
98
99 """
100 if not region:
101 region = RegionInfo(self, self.DefaultRegionName,
102 self.DefaultRegionEndpoint,
103 AutoScaleConnection)
104 self.region = region
105 self.use_block_device_types = use_block_device_types
106 super(AutoScaleConnection, self).__init__(aws_access_key_id,
107 aws_secret_access_key,
108 is_secure, port, proxy, proxy_port,
109 proxy_user, proxy_pass,
110 self.region.endpoint, debug,
111 https_connection_factory, path=path,
112 security_token=security_token,
113 validate_certs=validate_certs,
114 profile_name=profile_name)
115
116 def _required_auth_capability(self):
117 return ['hmac-v4']
118
119 def build_list_params(self, params, items, label):
120 """
121 Items is a list of dictionaries or strings::
122
123 [
124 {
125 'Protocol' : 'HTTP',
126 'LoadBalancerPort' : '80',
127 'InstancePort' : '80'
128 },
129 ..
130 ] etc.
131
132 or::
133
134 ['us-east-1b',...]
135 """
136 # different from EC2 list params
137 for i in range(1, len(items) + 1):
138 if isinstance(items[i - 1], dict):
139 for k, v in six.iteritems(items[i - 1]):
140 if isinstance(v, dict):
141 for kk, vv in six.iteritems(v):
142 params['%s.member.%d.%s.%s' % (label, i, k, kk)] = vv
143 else:
144 params['%s.member.%d.%s' % (label, i, k)] = v
145 elif isinstance(items[i - 1], six.string_types):
146 params['%s.member.%d' % (label, i)] = items[i - 1]
147
148 def _update_group(self, op, as_group):
149 params = {'AutoScalingGroupName': as_group.name,
150 'LaunchConfigurationName': as_group.launch_config_name,
151 'MinSize': as_group.min_size,
152 'MaxSize': as_group.max_size}
153 # get availability zone information (required param)
154 zones = as_group.availability_zones
155 self.build_list_params(params, zones, 'AvailabilityZones')
156 if as_group.desired_capacity is not None:
157 params['DesiredCapacity'] = as_group.desired_capacity
158 if as_group.vpc_zone_identifier:
159 params['VPCZoneIdentifier'] = as_group.vpc_zone_identifier
160 if as_group.health_check_period:
161 params['HealthCheckGracePeriod'] = as_group.health_check_period
162 if as_group.health_check_type:
163 params['HealthCheckType'] = as_group.health_check_type
164 if as_group.default_cooldown:
165 params['DefaultCooldown'] = as_group.default_cooldown
166 if as_group.placement_group:
167 params['PlacementGroup'] = as_group.placement_group
168 if as_group.instance_id:
169 params['InstanceId'] = as_group.instance_id
170 if as_group.termination_policies:
171 self.build_list_params(params, as_group.termination_policies,
172 'TerminationPolicies')
173 if op.startswith('Create'):
174 # you can only associate load balancers with an autoscale
175 # group at creation time
176 if as_group.load_balancers:
177 self.build_list_params(params, as_group.load_balancers,
178 'LoadBalancerNames')
179 if as_group.tags:
180 for i, tag in enumerate(as_group.tags):
181 tag.build_params(params, i + 1)
182 return self.get_object(op, params, Request)
183
184 def attach_instances(self, name, instance_ids):
185 """
186 Attach instances to an autoscaling group.
187 """
188 params = {
189 'AutoScalingGroupName': name,
190 }
191 self.build_list_params(params, instance_ids, 'InstanceIds')
192 return self.get_status('AttachInstances', params)
193
194 def detach_instances(self, name, instance_ids, decrement_capacity=True):
195 """
196 Detach instances from an Auto Scaling group.
197
198 :type name: str
199 :param name: The name of the Auto Scaling group from which to detach instances.
200
201 :type instance_ids: list
202 :param instance_ids: Instance ids to be detached from the Auto Scaling group.
203
204 :type decrement_capacity: bool
205 :param decrement_capacity: Whether to decrement the size of the
206 Auto Scaling group or not.
207 """
208
209 params = {'AutoScalingGroupName': name}
210 params['ShouldDecrementDesiredCapacity'] = 'true' if decrement_capacity else 'false'
211
212 self.build_list_params(params, instance_ids, 'InstanceIds')
213 return self.get_status('DetachInstances', params)
214
215 def create_auto_scaling_group(self, as_group):
216 """
217 Create auto scaling group.
218 """
219 return self._update_group('CreateAutoScalingGroup', as_group)
220
221 def delete_auto_scaling_group(self, name, force_delete=False):
222 """
223 Deletes the specified auto scaling group if the group has no instances
224 and no scaling activities in progress.
225 """
226 if(force_delete):
227 params = {'AutoScalingGroupName': name, 'ForceDelete': 'true'}
228 else:
229 params = {'AutoScalingGroupName': name}
230 return self.get_object('DeleteAutoScalingGroup', params, Request)
231
232 def create_launch_configuration(self, launch_config):
233 """
234 Creates a new Launch Configuration.
235
236 :type launch_config: :class:`boto.ec2.autoscale.launchconfig.LaunchConfiguration`
237 :param launch_config: LaunchConfiguration object.
238 """
239 params = {'ImageId': launch_config.image_id,
240 'LaunchConfigurationName': launch_config.name,
241 'InstanceType': launch_config.instance_type}
242 if launch_config.key_name:
243 params['KeyName'] = launch_config.key_name
244 if launch_config.user_data:
245 user_data = launch_config.user_data
246 if isinstance(user_data, six.text_type):
247 user_data = user_data.encode('utf-8')
248 params['UserData'] = base64.b64encode(user_data).decode('utf-8')
249 if launch_config.kernel_id:
250 params['KernelId'] = launch_config.kernel_id
251 if launch_config.ramdisk_id:
252 params['RamdiskId'] = launch_config.ramdisk_id
253 if launch_config.block_device_mappings:
254 [x.autoscale_build_list_params(params) for x in launch_config.block_device_mappings]
255 if launch_config.security_groups:
256 self.build_list_params(params, launch_config.security_groups,
257 'SecurityGroups')
258 if launch_config.instance_monitoring:
259 params['InstanceMonitoring.Enabled'] = 'true'
260 else:
261 params['InstanceMonitoring.Enabled'] = 'false'
262 if launch_config.spot_price is not None:
263 params['SpotPrice'] = str(launch_config.spot_price)
264 if launch_config.instance_profile_name is not None:
265 params['IamInstanceProfile'] = launch_config.instance_profile_name
266 if launch_config.ebs_optimized:
267 params['EbsOptimized'] = 'true'
268 else:
269 params['EbsOptimized'] = 'false'
270 if launch_config.associate_public_ip_address is True:
271 params['AssociatePublicIpAddress'] = 'true'
272 elif launch_config.associate_public_ip_address is False:
273 params['AssociatePublicIpAddress'] = 'false'
274 if launch_config.volume_type:
275 params['VolumeType'] = launch_config.volume_type
276 if launch_config.delete_on_termination:
277 params['DeleteOnTermination'] = 'true'
278 else:
279 params['DeleteOnTermination'] = 'false'
280 if launch_config.iops:
281 params['Iops'] = launch_config.iops
282 if launch_config.classic_link_vpc_id:
283 params['ClassicLinkVPCId'] = launch_config.classic_link_vpc_id
284 if launch_config.classic_link_vpc_security_groups:
285 self.build_list_params(
286 params,
287 launch_config.classic_link_vpc_security_groups,
288 'ClassicLinkVPCSecurityGroups'
289 )
290 return self.get_object('CreateLaunchConfiguration', params,
291 Request, verb='POST')
292
293 def get_account_limits(self):
294 """
295 Returns the limits for the Auto Scaling resources currently granted for
296 your AWS account.
297 """
298 params = {}
299 return self.get_object('DescribeAccountLimits', params, AccountLimits)
300
301 def create_scaling_policy(self, scaling_policy):
302 """
303 Creates a new Scaling Policy.
304
305 :type scaling_policy: :class:`boto.ec2.autoscale.policy.ScalingPolicy`
306 :param scaling_policy: ScalingPolicy object.
307 """
308 params = {'AdjustmentType': scaling_policy.adjustment_type,
309 'AutoScalingGroupName': scaling_policy.as_name,
310 'PolicyName': scaling_policy.name,
311 'ScalingAdjustment': scaling_policy.scaling_adjustment}
312
313 if scaling_policy.adjustment_type == "PercentChangeInCapacity" and \
314 scaling_policy.min_adjustment_step is not None:
315 params['MinAdjustmentStep'] = scaling_policy.min_adjustment_step
316
317 if scaling_policy.cooldown is not None:
318 params['Cooldown'] = scaling_policy.cooldown
319
320 return self.get_object('PutScalingPolicy', params, Request)
321
322 def delete_launch_configuration(self, launch_config_name):
323 """
324 Deletes the specified LaunchConfiguration.
325
326 The specified launch configuration must not be attached to an Auto
327 Scaling group. Once this call completes, the launch configuration is no
328 longer available for use.
329 """
330 params = {'LaunchConfigurationName': launch_config_name}
331 return self.get_object('DeleteLaunchConfiguration', params, Request)
332
333 def get_all_groups(self, names=None, max_records=None, next_token=None):
334 """
335 Returns a full description of each Auto Scaling group in the given
336 list. This includes all Amazon EC2 instances that are members of the
337 group. If a list of names is not provided, the service returns the full
338 details of all Auto Scaling groups.
339
340 This action supports pagination by returning a token if there are more
341 pages to retrieve. To get the next page, call this action again with
342 the returned token as the NextToken parameter.
343
344 :type names: list
345 :param names: List of group names which should be searched for.
346
347 :type max_records: int
348 :param max_records: Maximum amount of groups to return.
349
350 :rtype: list
351 :returns: List of :class:`boto.ec2.autoscale.group.AutoScalingGroup`
352 instances.
353 """
354 params = {}
355 if max_records:
356 params['MaxRecords'] = max_records
357 if next_token:
358 params['NextToken'] = next_token
359 if names:
360 self.build_list_params(params, names, 'AutoScalingGroupNames')
361 return self.get_list('DescribeAutoScalingGroups', params,
362 [('member', AutoScalingGroup)])
363
364 def get_all_launch_configurations(self, **kwargs):
365 """
366 Returns a full description of the launch configurations given the
367 specified names.
368
369 If no names are specified, then the full details of all launch
370 configurations are returned.
371
372 :type names: list
373 :param names: List of configuration names which should be searched for.
374
375 :type max_records: int
376 :param max_records: Maximum amount of configurations to return.
377
378 :type next_token: str
379 :param next_token: If you have more results than can be returned
380 at once, pass in this parameter to page through all results.
381
382 :rtype: list
383 :returns: List of
384 :class:`boto.ec2.autoscale.launchconfig.LaunchConfiguration`
385 instances.
386 """
387 params = {}
388 max_records = kwargs.get('max_records', None)
389 names = kwargs.get('names', None)
390 if max_records is not None:
391 params['MaxRecords'] = max_records
392 if names:
393 self.build_list_params(params, names, 'LaunchConfigurationNames')
394 next_token = kwargs.get('next_token')
395 if next_token:
396 params['NextToken'] = next_token
397 return self.get_list('DescribeLaunchConfigurations', params,
398 [('member', LaunchConfiguration)])
399
400 def get_all_activities(self, autoscale_group, activity_ids=None,
401 max_records=None, next_token=None):
402 """
403 Get all activities for the given autoscaling group.
404
405 This action supports pagination by returning a token if there are more
406 pages to retrieve. To get the next page, call this action again with
407 the returned token as the NextToken parameter
408
409 :type autoscale_group: str or
410 :class:`boto.ec2.autoscale.group.AutoScalingGroup` object
411 :param autoscale_group: The auto scaling group to get activities on.
412
413 :type max_records: int
414 :param max_records: Maximum amount of activities to return.
415
416 :rtype: list
417 :returns: List of
418 :class:`boto.ec2.autoscale.activity.Activity` instances.
419 """
420 name = autoscale_group
421 if isinstance(autoscale_group, AutoScalingGroup):
422 name = autoscale_group.name
423 params = {'AutoScalingGroupName': name}
424 if max_records:
425 params['MaxRecords'] = max_records
426 if next_token:
427 params['NextToken'] = next_token
428 if activity_ids:
429 self.build_list_params(params, activity_ids, 'ActivityIds')
430 return self.get_list('DescribeScalingActivities',
431 params, [('member', Activity)])
432
433 def get_termination_policies(self):
434 """Gets all valid termination policies.
435
436 These values can then be used as the termination_policies arg
437 when creating and updating autoscale groups.
438 """
439 return self.get_object('DescribeTerminationPolicyTypes',
440 {}, TerminationPolicies)
441
442 def delete_scheduled_action(self, scheduled_action_name,
443 autoscale_group=None):
444 """
445 Deletes a previously scheduled action.
446
447 :type scheduled_action_name: str
448 :param scheduled_action_name: The name of the action you want
449 to delete.
450
451 :type autoscale_group: str
452 :param autoscale_group: The name of the autoscale group.
453 """
454 params = {'ScheduledActionName': scheduled_action_name}
455 if autoscale_group:
456 params['AutoScalingGroupName'] = autoscale_group
457 return self.get_status('DeleteScheduledAction', params)
458
459 def terminate_instance(self, instance_id, decrement_capacity=True):
460 """
461 Terminates the specified instance. The desired group size can
462 also be adjusted, if desired.
463
464 :type instance_id: str
465 :param instance_id: The ID of the instance to be terminated.
466
467 :type decrement_capability: bool
468 :param decrement_capacity: Whether to decrement the size of the
469 autoscaling group or not.
470 """
471 params = {'InstanceId': instance_id}
472 if decrement_capacity:
473 params['ShouldDecrementDesiredCapacity'] = 'true'
474 else:
475 params['ShouldDecrementDesiredCapacity'] = 'false'
476 return self.get_object('TerminateInstanceInAutoScalingGroup', params,
477 Activity)
478
479 def delete_policy(self, policy_name, autoscale_group=None):
480 """
481 Delete a policy.
482
483 :type policy_name: str
484 :param policy_name: The name or ARN of the policy to delete.
485
486 :type autoscale_group: str
487 :param autoscale_group: The name of the autoscale group.
488 """
489 params = {'PolicyName': policy_name}
490 if autoscale_group:
491 params['AutoScalingGroupName'] = autoscale_group
492 return self.get_status('DeletePolicy', params)
493
494 def get_all_adjustment_types(self):
495 return self.get_list('DescribeAdjustmentTypes', {},
496 [('member', AdjustmentType)])
497
498 def get_all_autoscaling_instances(self, instance_ids=None,
499 max_records=None, next_token=None):
500 """
501 Returns a description of each Auto Scaling instance in the instance_ids
502 list. If a list is not provided, the service returns the full details
503 of all instances up to a maximum of fifty.
504
505 This action supports pagination by returning a token if there are more
506 pages to retrieve. To get the next page, call this action again with
507 the returned token as the NextToken parameter.
508
509 :type instance_ids: list
510 :param instance_ids: List of Autoscaling Instance IDs which should be
511 searched for.
512
513 :type max_records: int
514 :param max_records: Maximum number of results to return.
515
516 :rtype: list
517 :returns: List of
518 :class:`boto.ec2.autoscale.instance.Instance` objects.
519 """
520 params = {}
521 if instance_ids:
522 self.build_list_params(params, instance_ids, 'InstanceIds')
523 if max_records:
524 params['MaxRecords'] = max_records
525 if next_token:
526 params['NextToken'] = next_token
527 return self.get_list('DescribeAutoScalingInstances',
528 params, [('member', Instance)])
529
530 def get_all_metric_collection_types(self):
531 """
532 Returns a list of metrics and a corresponding list of granularities
533 for each metric.
534 """
535 return self.get_object('DescribeMetricCollectionTypes',
536 {}, MetricCollectionTypes)
537
538 def get_all_policies(self, as_group=None, policy_names=None,
539 max_records=None, next_token=None):
540 """
541 Returns descriptions of what each policy does. This action supports
542 pagination. If the response includes a token, there are more records
543 available. To get the additional records, repeat the request with the
544 response token as the NextToken parameter.
545
546 If no group name or list of policy names are provided, all
547 available policies are returned.
548
549 :type as_group: str
550 :param as_group: The name of the
551 :class:`boto.ec2.autoscale.group.AutoScalingGroup` to filter for.
552
553 :type policy_names: list
554 :param policy_names: List of policy names which should be searched for.
555
556 :type max_records: int
557 :param max_records: Maximum amount of groups to return.
558
559 :type next_token: str
560 :param next_token: If you have more results than can be returned
561 at once, pass in this parameter to page through all results.
562 """
563 params = {}
564 if as_group:
565 params['AutoScalingGroupName'] = as_group
566 if policy_names:
567 self.build_list_params(params, policy_names, 'PolicyNames')
568 if max_records:
569 params['MaxRecords'] = max_records
570 if next_token:
571 params['NextToken'] = next_token
572 return self.get_list('DescribePolicies', params,
573 [('member', ScalingPolicy)])
574
575 def get_all_scaling_process_types(self):
576 """
577 Returns scaling process types for use in the ResumeProcesses and
578 SuspendProcesses actions.
579 """
580 return self.get_list('DescribeScalingProcessTypes', {},
581 [('member', ProcessType)])
582
583 def suspend_processes(self, as_group, scaling_processes=None):
584 """
585 Suspends Auto Scaling processes for an Auto Scaling group.
586
587 :type as_group: string
588 :param as_group: The auto scaling group to suspend processes on.
589
590 :type scaling_processes: list
591 :param scaling_processes: Processes you want to suspend. If omitted,
592 all processes will be suspended.
593 """
594 params = {'AutoScalingGroupName': as_group}
595 if scaling_processes:
596 self.build_list_params(params, scaling_processes,
597 'ScalingProcesses')
598 return self.get_status('SuspendProcesses', params)
599
600 def resume_processes(self, as_group, scaling_processes=None):
601 """
602 Resumes Auto Scaling processes for an Auto Scaling group.
603
604 :type as_group: string
605 :param as_group: The auto scaling group to resume processes on.
606
607 :type scaling_processes: list
608 :param scaling_processes: Processes you want to resume. If omitted, all
609 processes will be resumed.
610 """
611 params = {'AutoScalingGroupName': as_group}
612
613 if scaling_processes:
614 self.build_list_params(params, scaling_processes,
615 'ScalingProcesses')
616 return self.get_status('ResumeProcesses', params)
617
618 def create_scheduled_group_action(self, as_group, name, time=None,
619 desired_capacity=None,
620 min_size=None, max_size=None,
621 start_time=None, end_time=None,
622 recurrence=None):
623 """
624 Creates a scheduled scaling action for a Auto Scaling group. If you
625 leave a parameter unspecified, the corresponding value remains
626 unchanged in the affected Auto Scaling group.
627
628 :type as_group: string
629 :param as_group: The auto scaling group to get activities on.
630
631 :type name: string
632 :param name: Scheduled action name.
633
634 :type time: datetime.datetime
635 :param time: The time for this action to start. (Depracated)
636
637 :type desired_capacity: int
638 :param desired_capacity: The number of EC2 instances that should
639 be running in this group.
640
641 :type min_size: int
642 :param min_size: The minimum size for the new auto scaling group.
643
644 :type max_size: int
645 :param max_size: The minimum size for the new auto scaling group.
646
647 :type start_time: datetime.datetime
648 :param start_time: The time for this action to start. When StartTime and EndTime are specified with Recurrence, they form the boundaries of when the recurring action will start and stop.
649
650 :type end_time: datetime.datetime
651 :param end_time: The time for this action to end. When StartTime and EndTime are specified with Recurrence, they form the boundaries of when the recurring action will start and stop.
652
653 :type recurrence: string
654 :param recurrence: The time when recurring future actions will start. Start time is specified by the user following the Unix cron syntax format. EXAMPLE: '0 10 * * *'
655 """
656 params = {'AutoScalingGroupName': as_group,
657 'ScheduledActionName': name}
658 if start_time is not None:
659 params['StartTime'] = start_time.isoformat()
660 if end_time is not None:
661 params['EndTime'] = end_time.isoformat()
662 if recurrence is not None:
663 params['Recurrence'] = recurrence
664 if time:
665 params['Time'] = time.isoformat()
666 if desired_capacity is not None:
667 params['DesiredCapacity'] = desired_capacity
668 if min_size is not None:
669 params['MinSize'] = min_size
670 if max_size is not None:
671 params['MaxSize'] = max_size
672 return self.get_status('PutScheduledUpdateGroupAction', params)
673
674 def get_all_scheduled_actions(self, as_group=None, start_time=None,
675 end_time=None, scheduled_actions=None,
676 max_records=None, next_token=None):
677 params = {}
678 if as_group:
679 params['AutoScalingGroupName'] = as_group
680 if scheduled_actions:
681 self.build_list_params(params, scheduled_actions,
682 'ScheduledActionNames')
683 if max_records:
684 params['MaxRecords'] = max_records
685 if next_token:
686 params['NextToken'] = next_token
687 return self.get_list('DescribeScheduledActions', params,
688 [('member', ScheduledUpdateGroupAction)])
689
690 def disable_metrics_collection(self, as_group, metrics=None):
691 """
692 Disables monitoring of group metrics for the Auto Scaling group
693 specified in AutoScalingGroupName. You can specify the list of affected
694 metrics with the Metrics parameter.
695 """
696 params = {'AutoScalingGroupName': as_group}
697
698 if metrics:
699 self.build_list_params(params, metrics, 'Metrics')
700 return self.get_status('DisableMetricsCollection', params)
701
702 def enable_metrics_collection(self, as_group, granularity, metrics=None):
703 """
704 Enables monitoring of group metrics for the Auto Scaling group
705 specified in AutoScalingGroupName. You can specify the list of enabled
706 metrics with the Metrics parameter.
707
708 Auto scaling metrics collection can be turned on only if the
709 InstanceMonitoring.Enabled flag, in the Auto Scaling group's launch
710 configuration, is set to true.
711
712 :type autoscale_group: string
713 :param autoscale_group: The auto scaling group to get activities on.
714
715 :type granularity: string
716 :param granularity: The granularity to associate with the metrics to
717 collect. Currently, the only legal granularity is "1Minute".
718
719 :type metrics: string list
720 :param metrics: The list of metrics to collect. If no metrics are
721 specified, all metrics are enabled.
722 """
723 params = {'AutoScalingGroupName': as_group,
724 'Granularity': granularity}
725 if metrics:
726 self.build_list_params(params, metrics, 'Metrics')
727 return self.get_status('EnableMetricsCollection', params)
728
729 def execute_policy(self, policy_name, as_group=None, honor_cooldown=None):
730 params = {'PolicyName': policy_name}
731 if as_group:
732 params['AutoScalingGroupName'] = as_group
733 if honor_cooldown:
734 params['HonorCooldown'] = honor_cooldown
735 return self.get_status('ExecutePolicy', params)
736
737 def put_notification_configuration(self, autoscale_group, topic, notification_types):
738 """
739 Configures an Auto Scaling group to send notifications when
740 specified events take place.
741
742 :type autoscale_group: str or
743 :class:`boto.ec2.autoscale.group.AutoScalingGroup` object
744 :param autoscale_group: The Auto Scaling group to put notification
745 configuration on.
746
747 :type topic: str
748 :param topic: The Amazon Resource Name (ARN) of the Amazon Simple
749 Notification Service (SNS) topic.
750
751 :type notification_types: list
752 :param notification_types: The type of events that will trigger
753 the notification. Valid types are:
754 'autoscaling:EC2_INSTANCE_LAUNCH',
755 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR',
756 'autoscaling:EC2_INSTANCE_TERMINATE',
757 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR',
758 'autoscaling:TEST_NOTIFICATION'
759 """
760
761 name = autoscale_group
762 if isinstance(autoscale_group, AutoScalingGroup):
763 name = autoscale_group.name
764
765 params = {'AutoScalingGroupName': name,
766 'TopicARN': topic}
767 self.build_list_params(params, notification_types, 'NotificationTypes')
768 return self.get_status('PutNotificationConfiguration', params)
769
770 def delete_notification_configuration(self, autoscale_group, topic):
771 """
772 Deletes notifications created by put_notification_configuration.
773
774 :type autoscale_group: str or
775 :class:`boto.ec2.autoscale.group.AutoScalingGroup` object
776 :param autoscale_group: The Auto Scaling group to put notification
777 configuration on.
778
779 :type topic: str
780 :param topic: The Amazon Resource Name (ARN) of the Amazon Simple
781 Notification Service (SNS) topic.
782 """
783
784 name = autoscale_group
785 if isinstance(autoscale_group, AutoScalingGroup):
786 name = autoscale_group.name
787
788 params = {'AutoScalingGroupName': name,
789 'TopicARN': topic}
790
791 return self.get_status('DeleteNotificationConfiguration', params)
792
793 def set_instance_health(self, instance_id, health_status,
794 should_respect_grace_period=True):
795 """
796 Explicitly set the health status of an instance.
797
798 :type instance_id: str
799 :param instance_id: The identifier of the EC2 instance.
800
801 :type health_status: str
802 :param health_status: The health status of the instance.
803 "Healthy" means that the instance is healthy and should remain
804 in service. "Unhealthy" means that the instance is unhealthy.
805 Auto Scaling should terminate and replace it.
806
807 :type should_respect_grace_period: bool
808 :param should_respect_grace_period: If True, this call should
809 respect the grace period associated with the group.
810 """
811 params = {'InstanceId': instance_id,
812 'HealthStatus': health_status}
813 if should_respect_grace_period:
814 params['ShouldRespectGracePeriod'] = 'true'
815 else:
816 params['ShouldRespectGracePeriod'] = 'false'
817 return self.get_status('SetInstanceHealth', params)
818
819 def set_desired_capacity(self, group_name, desired_capacity, honor_cooldown=False):
820 """
821 Adjusts the desired size of the AutoScalingGroup by initiating scaling
822 activities. When reducing the size of the group, it is not possible to define
823 which Amazon EC2 instances will be terminated. This applies to any Auto Scaling
824 decisions that might result in terminating instances.
825
826 :type group_name: string
827 :param group_name: name of the auto scaling group
828
829 :type desired_capacity: integer
830 :param desired_capacity: new capacity setting for auto scaling group
831
832 :type honor_cooldown: boolean
833 :param honor_cooldown: by default, overrides any cooldown period
834 """
835 params = {'AutoScalingGroupName': group_name,
836 'DesiredCapacity': desired_capacity}
837 if honor_cooldown:
838 params['HonorCooldown'] = 'true'
839
840 return self.get_status('SetDesiredCapacity', params)
841
842 # Tag methods
843
844 def get_all_tags(self, filters=None, max_records=None, next_token=None):
845 """
846 Lists the Auto Scaling group tags.
847
848 This action supports pagination by returning a token if there
849 are more pages to retrieve. To get the next page, call this
850 action again with the returned token as the NextToken
851 parameter.
852
853 :type filters: dict
854 :param filters: The value of the filter type used to identify
855 the tags to be returned. NOT IMPLEMENTED YET.
856
857 :type max_records: int
858 :param max_records: Maximum number of tags to return.
859
860 :rtype: list
861 :returns: List of :class:`boto.ec2.autoscale.tag.Tag`
862 instances.
863 """
864 params = {}
865 if max_records:
866 params['MaxRecords'] = max_records
867 if next_token:
868 params['NextToken'] = next_token
869 return self.get_list('DescribeTags', params,
870 [('member', Tag)])
871
872 def create_or_update_tags(self, tags):
873 """
874 Creates new tags or updates existing tags for an Auto Scaling group.
875
876 :type tags: List of :class:`boto.ec2.autoscale.tag.Tag`
877 :param tags: The new or updated tags.
878 """
879 params = {}
880 for i, tag in enumerate(tags):
881 tag.build_params(params, i + 1)
882 return self.get_status('CreateOrUpdateTags', params, verb='POST')
883
884 def delete_tags(self, tags):
885 """
886 Deletes existing tags for an Auto Scaling group.
887
888 :type tags: List of :class:`boto.ec2.autoscale.tag.Tag`
889 :param tags: The new or updated tags.
890 """
891 params = {}
892 for i, tag in enumerate(tags):
893 tag.build_params(params, i + 1)
894 return self.get_status('DeleteTags', params, verb='POST')