o ckF[@sdZddlZddlZddlmZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddl m!Z!e"diZ#ddZ$ddZ%GdddeZ&dS)z\ This module provides an interface to the Elastic Compute Cloud (EC2) Auto Scaling service. N)AWSQueryConnection) RegionInfo get_regions load_regions)connect)Request)LaunchConfiguration)AutoScalingGroup) ProcessType)Activity)AdjustmentType)MetricCollectionTypes) ScalingPolicy)TerminationPolicies)Instance)ScheduledUpdateGroupAction)Tag) AccountLimits)six autoscalingcCs tdtdS)z Get all available regions for the Auto Scaling service. :rtype: list :return: A list of :class:`boto.RegionInfo` instances r)connection_cls)rAutoScaleConnectionrr=/usr/lib/python3/dist-packages/boto/ec2/autoscale/__init__.pyregions6s rcKstd|fdti|S)aF Given a valid region name, return a :class:`boto.ec2.autoscale.AutoScaleConnection`. :param str region_name: The name of the region to connect to. :rtype: :class:`boto.ec2.AutoScaleConnection` or ``None`` :return: A connection to the given region, or None if an invalid region name is given rr)rr) region_name kw_paramsrrrconnect_to_region@s rcseZdZejdddZejdddZejdddZ    dYfd d Z ddZ ddZ ddZ ddZ dZddZddZd[ddZddZdd Zd!d"Zd#d$Zd\d%d&Zd'd(Z  d\d)d*Zd+d,Z d]d-d.ZdZd/d0Zd]d1d2Zd3d4Z  d\d5d6Zd7d8Z  d^d9d:Zd;d<Z d]d=d>Z!d]d?d@Z"     d_dAdBZ#   d`dCdDZ$d]dEdFZ%d]dGdHZ&dadIdJZ'dKdLZ(dMdNZ) dZdOdPZ*d[dQdRZ+d\dSdTZ,dUdVZ-dWdXZ.Z/S)brBotoautoscale_versionz 2011-01-01autoscale_endpointz#autoscaling.us-east-1.amazonaws.comautoscale_region_namez us-east-1NTr/FcsX| s t||j|jt} | |_||_tt|j|||||||||jj| | | | ||ddS)z Init method to create a new connection to the AutoScaling service. B{Note:} The host argument is overridden by the host specified in the boto configuration file. )pathsecurity_tokenvalidate_certs profile_nameN) rDefaultRegionNameDefaultRegionEndpointrregionuse_block_device_typessuper__init__endpoint)selfaws_access_key_idaws_secret_access_key is_secureportproxy proxy_port proxy_user proxy_passdebughttps_connection_factoryr)r#r$r%r&r* __class__rrr,Vs"  zAutoScaleConnection.__init__cCsdgS)Nzhmac-v4rr.rrr_required_auth_capabilitytsz-AutoScaleConnection._required_auth_capabilityc Cstdt|dD]S}t||dtrFt||dD]'\}}t|tr;t|D]\}}||d||||f<q+q||d|||f<qq t||dtjr\||d|d||f<q dS)aH Items is a list of dictionaries or strings:: [ { 'Protocol' : 'HTTP', 'LoadBalancerPort' : '80', 'InstancePort' : '80' }, .. ] etc. or:: ['us-east-1b',...] z%s.member.%d.%s.%sz%s.member.%d.%sz %s.member.%dN)rangelen isinstancedictr iteritems string_types) r.paramsitemslabelikvkkvvrrrbuild_list_paramsws z%AutoScaleConnection.build_list_paramscCs |j|j|j|jd}|j}|||d|jdur|j|d<|jr'|j|d<|jr/|j|d<|j r7|j |d<|j r?|j |d<|j rG|j |d<|j rO|j |d <|j rZ|||j d |d r|jrj|||jd |jrt|jD] \}}|||d qr|||tS)N)AutoScalingGroupNameLaunchConfigurationNameMinSizeMaxSizeAvailabilityZonesDesiredCapacityVPCZoneIdentifierHealthCheckGracePeriodHealthCheckTypeDefaultCooldownPlacementGroup InstanceIdrCreateLoadBalancerNamesr=)namelaunch_config_namemin_sizemax_sizeavailability_zonesrLdesired_capacityvpc_zone_identifierhealth_check_periodhealth_check_typedefault_cooldownplacement_group instance_idtermination_policies startswithload_balancerstags enumerate build_params get_objectr)r.opas_grouprDzonesrGtagrrr _update_groupsD           z!AutoScaleConnection._update_groupcCs"d|i}|||d|d|S)z; Attach instances to an autoscaling group. rM InstanceIdsAttachInstancesrL get_status)r.r[ instance_idsrDrrrattach_instancess z$AutoScaleConnection.attach_instancescCs2d|i}|rdnd|d<|||d|d|S)a Detach instances from an Auto Scaling group. :type name: str :param name: The name of the Auto Scaling group from which to detach instances. :type instance_ids: list :param instance_ids: Instance ids to be detached from the Auto Scaling group. :type decrement_capacity: bool :param decrement_capacity: Whether to decrement the size of the Auto Scaling group or not. rMtruefalseShouldDecrementDesiredCapacityrsDetachInstancesru)r.r[rwdecrement_capacityrDrrrdetach_instancess z$AutoScaleConnection.detach_instancescCs |d|S)z, Create auto scaling group. CreateAutoScalingGroup)rr)r.rorrrcreate_auto_scaling_groups z-AutoScaleConnection.create_auto_scaling_groupcCs&|r|dd}nd|i}|d|tS)z Deletes the specified auto scaling group if the group has no instances and no scaling activities in progress. ry)rM ForceDeleterMDeleteAutoScalingGrouprmr)r.r[ force_deleterDrrrdelete_auto_scaling_groups z-AutoScaleConnection.delete_auto_scaling_groupcs|j|j|jd|jr|jd<|jr,|j}t|tjr"|d}t | dd<|j r4|j d<|j r<|j d<|jrIfdd|jD|jrT||jd |jr\d d <nd d <|jd urlt|jd<|jd urv|jd<|jr~d d<nd d<|jdurd d<n |jdurd d<|jr|jd<|jrd d<nd d<|jr|jd<|jr|jd<|jr||jd|jdtddS)z Creates a new Launch Configuration. :type launch_config: :class:`boto.ec2.autoscale.launchconfig.LaunchConfiguration` :param launch_config: LaunchConfiguration object. )ImageIdrN InstanceTypeKeyNamezutf-8UserDataKernelId RamdiskIdcsg|]}|qSr)autoscale_build_list_params).0xrDrr szCAutoScaleConnection.create_launch_configuration..SecurityGroupsryzInstanceMonitoring.EnabledrzN SpotPriceIamInstanceProfile EbsOptimizedTAssociatePublicIpAddressF VolumeTypeDeleteOnTerminationIopsClassicLinkVPCIdClassicLinkVPCSecurityGroupsCreateLaunchConfigurationPOSTverb)image_idr[ instance_typekey_name user_datar@r text_typeencodebase64 b64encodedecode kernel_id ramdisk_idblock_device_mappingssecurity_groupsrLinstance_monitoring spot_pricestrinstance_profile_name ebs_optimizedassociate_public_ip_address volume_typedelete_on_terminationiopsclassic_link_vpc_id classic_link_vpc_security_groupsrmr)r. launch_configrrrrcreate_launch_configurationsj                  z/AutoScaleConnection.create_launch_configurationcCsi}|d|tS)zs Returns the limits for the Auto Scaling resources currently granted for your AWS account. DescribeAccountLimits)rmr)r.rDrrrget_account_limits%sz&AutoScaleConnection.get_account_limitscCsV|j|j|j|jd}|jdkr|jdur|j|d<|jdur$|j|d<|d|tS)z Creates a new Scaling Policy. :type scaling_policy: :class:`boto.ec2.autoscale.policy.ScalingPolicy` :param scaling_policy: ScalingPolicy object. )r rM PolicyNameScalingAdjustmentPercentChangeInCapacityNMinAdjustmentStepCooldownPutScalingPolicy)adjustment_typeas_namer[scaling_adjustmentmin_adjustment_stepcooldownrmr)r.scaling_policyrDrrrcreate_scaling_policy-s     z)AutoScaleConnection.create_scaling_policycCsd|i}|d|tS)z Deletes the specified LaunchConfiguration. The specified launch configuration must not be attached to an Auto Scaling group. Once this call completes, the launch configuration is no longer available for use. rNDeleteLaunchConfigurationr)r.r\rDrrrdelete_launch_configurationBsz/AutoScaleConnection.delete_launch_configurationcCsBi}|r||d<|r||d<|r|||d|d|dtfgS)a. Returns a full description of each Auto Scaling group in the given list. This includes all Amazon EC2 instances that are members of the group. If a list of names is not provided, the service returns the full details of all Auto Scaling groups. This action supports pagination by returning a token if there are more pages to retrieve. To get the next page, call this action again with the returned token as the NextToken parameter. :type names: list :param names: List of group names which should be searched for. :type max_records: int :param max_records: Maximum amount of groups to return. :rtype: list :returns: List of :class:`boto.ec2.autoscale.group.AutoScalingGroup` instances. MaxRecords NextTokenAutoScalingGroupNamesDescribeAutoScalingGroupsmember)rLget_listr )r.names max_records next_tokenrDrrrget_all_groupsMsz"AutoScaleConnection.get_all_groupscKshi}|dd}|dd}|dur||d<|r|||d|d}|r*||d<|d|d tfgS) a Returns a full description of the launch configurations given the specified names. If no names are specified, then the full details of all launch configurations are returned. :type names: list :param names: List of configuration names which should be searched for. :type max_records: int :param max_records: Maximum amount of configurations to return. :type next_token: str :param next_token: If you have more results than can be returned at once, pass in this parameter to page through all results. :rtype: list :returns: List of :class:`boto.ec2.autoscale.launchconfig.LaunchConfiguration` instances. rNrrLaunchConfigurationNamesrrDescribeLaunchConfigurationsr)getrLrr)r.kwargsrDrrrrrrget_all_launch_configurationsls   z1AutoScaleConnection.get_all_launch_configurationscCsZ|}t|tr |j}d|i}|r||d<|r||d<|r#|||d|d|dtfgS)a Get all activities for the given autoscaling group. This action supports pagination by returning a token if there are more pages to retrieve. To get the next page, call this action again with the returned token as the NextToken parameter :type autoscale_group: str or :class:`boto.ec2.autoscale.group.AutoScalingGroup` object :param autoscale_group: The auto scaling group to get activities on. :type max_records: int :param max_records: Maximum amount of activities to return. :rtype: list :returns: List of :class:`boto.ec2.autoscale.activity.Activity` instances. rMrr ActivityIdsDescribeScalingActivitiesr)r@r r[rLrr )r.autoscale_group activity_idsrrr[rDrrrget_all_activitiess  z&AutoScaleConnection.get_all_activitiescC|ditS)zGets all valid termination policies. These values can then be used as the termination_policies arg when creating and updating autoscale groups. DescribeTerminationPolicyTypes)rmrr;rrrget_termination_policiessz,AutoScaleConnection.get_termination_policiescC d|i}|r ||d<|d|S)a$ Deletes a previously scheduled action. :type scheduled_action_name: str :param scheduled_action_name: The name of the action you want to delete. :type autoscale_group: str :param autoscale_group: The name of the autoscale group. ScheduledActionNamerMDeleteScheduledActionrv)r.scheduled_action_namerrDrrrdelete_scheduled_actions  z+AutoScaleConnection.delete_scheduled_actioncCs,d|i}|r d|d<nd|d<|d|tS)ar Terminates the specified instance. The desired group size can also be adjusted, if desired. :type instance_id: str :param instance_id: The ID of the instance to be terminated. :type decrement_capability: bool :param decrement_capacity: Whether to decrement the size of the autoscaling group or not. rXryr{rz#TerminateInstanceInAutoScalingGroup)rmr )r.rfr}rDrrrterminate_instances  z&AutoScaleConnection.terminate_instancecCr)z Delete a policy. :type policy_name: str :param policy_name: The name or ARN of the policy to delete. :type autoscale_group: str :param autoscale_group: The name of the autoscale group. rrM DeletePolicyr)r. policy_namerrDrrr delete_policys  z!AutoScaleConnection.delete_policycC|didtfgS)NDescribeAdjustmentTypesr)rr r;rrrget_all_adjustment_typessz,AutoScaleConnection.get_all_adjustment_typescCsBi}|r |||d|r||d<|r||d<|d|dtfgS)a  Returns a description of each Auto Scaling instance in the instance_ids list. If a list is not provided, the service returns the full details of all instances up to a maximum of fifty. This action supports pagination by returning a token if there are more pages to retrieve. To get the next page, call this action again with the returned token as the NextToken parameter. :type instance_ids: list :param instance_ids: List of Autoscaling Instance IDs which should be searched for. :type max_records: int :param max_records: Maximum number of results to return. :rtype: list :returns: List of :class:`boto.ec2.autoscale.instance.Instance` objects. rsrrDescribeAutoScalingInstancesr)rLrr)r.rwrrrDrrrget_all_autoscaling_instancess z1AutoScaleConnection.get_all_autoscaling_instancescCr)zn Returns a list of metrics and a corresponding list of granularities for each metric. DescribeMetricCollectionTypes)rmr r;rrrget_all_metric_collection_typessz3AutoScaleConnection.get_all_metric_collection_typescCsNi}|r||d<|r|||d|r||d<|r||d<|d|dtfgS)a Returns descriptions of what each policy does. This action supports pagination. If the response includes a token, there are more records available. To get the additional records, repeat the request with the response token as the NextToken parameter. If no group name or list of policy names are provided, all available policies are returned. :type as_group: str :param as_group: The name of the :class:`boto.ec2.autoscale.group.AutoScalingGroup` to filter for. :type policy_names: list :param policy_names: List of policy names which should be searched for. :type max_records: int :param max_records: Maximum amount of groups to return. :type next_token: str :param next_token: If you have more results than can be returned at once, pass in this parameter to page through all results. rM PolicyNamesrrDescribePoliciesr)rLrr)r.ro policy_namesrrrDrrrget_all_policiessz$AutoScaleConnection.get_all_policiescCr)zt Returns scaling process types for use in the ResumeProcesses and SuspendProcesses actions. DescribeScalingProcessTypesr)rr r;rrrget_all_scaling_process_types?sz1AutoScaleConnection.get_all_scaling_process_typescC&d|i}|r |||d|d|S)aV Suspends Auto Scaling processes for an Auto Scaling group. :type as_group: string :param as_group: The auto scaling group to suspend processes on. :type scaling_processes: list :param scaling_processes: Processes you want to suspend. If omitted, all processes will be suspended. rMScalingProcessesSuspendProcessesrur.roscaling_processesrDrrrsuspend_processesGs   z%AutoScaleConnection.suspend_processescCr)aQ Resumes Auto Scaling processes for an Auto Scaling group. :type as_group: string :param as_group: The auto scaling group to resume processes on. :type scaling_processes: list :param scaling_processes: Processes you want to resume. If omitted, all processes will be resumed. rMrResumeProcessesrurrrrresume_processesXs   z$AutoScaleConnection.resume_processesc Cs||d} |dur|| d<|dur|| d<| dur!| | d<|r)|| d<|dur1|| d<|dur9|| d<|durA|| d <|d | S) a Creates a scheduled scaling action for a Auto Scaling group. If you leave a parameter unspecified, the corresponding value remains unchanged in the affected Auto Scaling group. :type as_group: string :param as_group: The auto scaling group to get activities on. :type name: string :param name: Scheduled action name. :type time: datetime.datetime :param time: The time for this action to start. (Depracated) :type desired_capacity: int :param desired_capacity: The number of EC2 instances that should be running in this group. :type min_size: int :param min_size: The minimum size for the new auto scaling group. :type max_size: int :param max_size: The minimum size for the new auto scaling group. :type start_time: datetime.datetime :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. :type end_time: datetime.datetime :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. :type recurrence: string :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 * * *' )rMrN StartTimeEndTime RecurrenceTimerRrOrPPutScheduledUpdateGroupAction) isoformatrv) r.ror[timer`r]r^ start_timeend_time recurrencerDrrrcreate_scheduled_group_actionjs$&    z1AutoScaleConnection.create_scheduled_group_actioncCsNi}|r||d<|r|||d|r||d<|r||d<|d|dtfgS)NrMScheduledActionNamesrrDescribeScheduledActionsr)rLrr)r.rorr scheduled_actionsrrrDrrrget_all_scheduled_actionssz-AutoScaleConnection.get_all_scheduled_actionscCr)z Disables monitoring of group metrics for the Auto Scaling group specified in AutoScalingGroupName. You can specify the list of affected metrics with the Metrics parameter. rMMetricsDisableMetricsCollectionru)r.rometricsrDrrrdisable_metrics_collections z.AutoScaleConnection.disable_metrics_collectioncCs(||d}|r|||d|d|S)a[ Enables monitoring of group metrics for the Auto Scaling group specified in AutoScalingGroupName. You can specify the list of enabled metrics with the Metrics parameter. Auto scaling metrics collection can be turned on only if the InstanceMonitoring.Enabled flag, in the Auto Scaling group's launch configuration, is set to true. :type autoscale_group: string :param autoscale_group: The auto scaling group to get activities on. :type granularity: string :param granularity: The granularity to associate with the metrics to collect. Currently, the only legal granularity is "1Minute". :type metrics: string list :param metrics: The list of metrics to collect. If no metrics are specified, all metrics are enabled. )rM GranularityrEnableMetricsCollectionru)r.ro granularityrrDrrrenable_metrics_collections  z-AutoScaleConnection.enable_metrics_collectioncCs,d|i}|r ||d<|r||d<|d|S)NrrM HonorCooldown ExecutePolicyr)r.rrohonor_cooldownrDrrrexecute_policys  z"AutoScaleConnection.execute_policycCs8|}t|tr |j}||d}|||d|d|S)as Configures an Auto Scaling group to send notifications when specified events take place. :type autoscale_group: str or :class:`boto.ec2.autoscale.group.AutoScalingGroup` object :param autoscale_group: The Auto Scaling group to put notification configuration on. :type topic: str :param topic: The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic. :type notification_types: list :param notification_types: The type of events that will trigger the notification. Valid types are: 'autoscaling:EC2_INSTANCE_LAUNCH', 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR', 'autoscaling:EC2_INSTANCE_TERMINATE', 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR', 'autoscaling:TEST_NOTIFICATION' rMTopicARNNotificationTypesPutNotificationConfiguration)r@r r[rLrv)r.rtopicnotification_typesr[rDrrrput_notification_configurations  z2AutoScaleConnection.put_notification_configurationcCs*|}t|tr |j}||d}|d|S)a Deletes notifications created by put_notification_configuration. :type autoscale_group: str or :class:`boto.ec2.autoscale.group.AutoScalingGroup` object :param autoscale_group: The Auto Scaling group to put notification configuration on. :type topic: str :param topic: The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic. rDeleteNotificationConfiguration)r@r r[rv)r.rr r[rDrrr!delete_notification_configurations  z5AutoScaleConnection.delete_notification_configurationcCs,||d}|r d|d<nd|d<|d|S)a Explicitly set the health status of an instance. :type instance_id: str :param instance_id: The identifier of the EC2 instance. :type health_status: str :param health_status: The health status of the instance. "Healthy" means that the instance is healthy and should remain in service. "Unhealthy" means that the instance is unhealthy. Auto Scaling should terminate and replace it. :type should_respect_grace_period: bool :param should_respect_grace_period: If True, this call should respect the grace period associated with the group. )rX HealthStatusryShouldRespectGracePeriodrzSetInstanceHealthr)r.rf health_statusshould_respect_grace_periodrDrrrset_instance_healths  z'AutoScaleConnection.set_instance_healthcCs"||d}|r d|d<|d|S)a Adjusts the desired size of the AutoScalingGroup by initiating scaling activities. When reducing the size of the group, it is not possible to define which Amazon EC2 instances will be terminated. This applies to any Auto Scaling decisions that might result in terminating instances. :type group_name: string :param group_name: name of the auto scaling group :type desired_capacity: integer :param desired_capacity: new capacity setting for auto scaling group :type honor_cooldown: boolean :param honor_cooldown: by default, overrides any cooldown period )rMrRryrSetDesiredCapacityr)r. group_namer`rrDrrrset_desired_capacity3s  z(AutoScaleConnection.set_desired_capacitycCs0i}|r||d<|r||d<|d|dtfgS)aw Lists the Auto Scaling group tags. This action supports pagination by returning a token if there are more pages to retrieve. To get the next page, call this action again with the returned token as the NextToken parameter. :type filters: dict :param filters: The value of the filter type used to identify the tags to be returned. NOT IMPLEMENTED YET. :type max_records: int :param max_records: Maximum number of tags to return. :rtype: list :returns: List of :class:`boto.ec2.autoscale.tag.Tag` instances. rr DescribeTagsr)rr)r.filtersrrrDrrr get_all_tagsLsz AutoScaleConnection.get_all_tagscC6i}t|D] \}}|||dq|jd|ddS)z Creates new tags or updates existing tags for an Auto Scaling group. :type tags: List of :class:`boto.ec2.autoscale.tag.Tag` :param tags: The new or updated tags. r=CreateOrUpdateTagsrrrkrlrvr.rjrDrGrqrrrcreate_or_update_tagshz)AutoScaleConnection.create_or_update_tagscCr1)z Deletes existing tags for an Auto Scaling group. :type tags: List of :class:`boto.ec2.autoscale.tag.Tag` :param tags: The new or updated tags. r= DeleteTagsrrr3r4rrr delete_tagstr6zAutoScaleConnection.delete_tags)NNTNNNNNrNNr"NTNF)T)F)NNN)N)NNNN)NNNNNNN)NNNNNN)NN)0__name__ __module__ __qualname__botoconfigr APIVersionr(r'r,r<rLrrrxr~rrrrrrrrrrrrrrrrrrrrr rrrrr"r$r*r-r0r5r8 __classcell__rrr9rrOs  $   = $ !     %   8  !   r)'__doc__rr<boto.connectionrboto.regioninforrrrboto.ec2.autoscale.requestrboto.ec2.autoscale.launchconfigrboto.ec2.autoscale.groupr r boto.ec2.autoscale.activityr boto.ec2.autoscale.policyr r rrboto.ec2.autoscale.instancerboto.ec2.autoscale.scheduledrboto.ec2.autoscale.tagrboto.ec2.autoscale.limitsr boto.compatrr RegionDatarrrrrrrs0