Class: AWS::Autoscaling::Base
- Defined in:
- lib/AWS/Autoscaling.rb,
lib/AWS/Autoscaling/autoscaling.rb
Instance Attribute Summary
Attributes inherited from Base
#port, #proxy_server, #server, #use_ssl
Instance Method Summary collapse
- #api_version ⇒ Object
-
#aws_error?(response) ⇒ Boolean
Raises the appropriate error if the specified Net::HTTPResponse object contains an Amazon EC2 error; returns
false
otherwise. -
#create_autoscaling_group(options = {}) ⇒ Object
Creates a new AutoScalingGroup with the specified name.
-
#create_launch_configuration(options = {}) ⇒ Object
Create a launch configuration Creates a new Launch Configuration.
-
#create_or_updated_scaling_trigger(options = {}) ⇒ Object
Create or update scaling trigger This call sets the parameters that governs when and how to scale an AutoScalingGroup.
- #default_host ⇒ Object
-
#delete_autoscaling_group(options = {}) ⇒ Object
Deletes all configuration for this AutoScalingGroup and also deletes the group.
-
#delete_launch_configuration(options = {}) ⇒ Object
Deletes the given Launch Configuration.
-
#delete_trigger(options = {}) ⇒ Object
Deletes the given trigger If a trigger is currently in progress, it will continue to run until its activities are complete.
-
#describe_autoscaling_groups(options = {}) ⇒ Object
Describe autoscaling group Returns a full description of the AutoScalingGroups from the given list.
-
#describe_launch_configurations(options = {}) ⇒ Object
Describe launch configurations Returns a full description of the launch configurations given the specified names.
-
#describe_scaling_activities(options = {}) ⇒ Object
Describe autoscaling activities Returns the scaling activities specified for the given group.
-
#describe_triggers(options = {}) ⇒ Object
Describe triggers Returns a full description of the trigger (see Trigger), in the specified AutoScalingGroup.
-
#set_desired_capacity(options = {}) ⇒ Object
Set desired capacity This API adjusts the desired size of the AutoScalingGroup by initiating scaling activities, as necessary.
-
#terminate_instance_in_autoscaling_group(options = {}) ⇒ Object
Terminate instance in an autoscaling group This call will terminate the specified Instance.
-
#update_autoscaling_group(options = {}) ⇒ Object
Creates a new AutoScalingGroup with the specified name.
Methods inherited from Base
Constructor Details
This class inherits a constructor from AWS::Base
Instance Method Details
#api_version ⇒ Object
21 22 23 |
# File 'lib/AWS/Autoscaling.rb', line 21 def api_version API_VERSION end |
#aws_error?(response) ⇒ Boolean
Raises the appropriate error if the specified Net::HTTPResponse object contains an Amazon EC2 error; returns false
otherwise.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/AWS/Autoscaling.rb', line 31 def aws_error?(response) # return false if we got a HTTP 200 code, # otherwise there is some type of error (40x,50x) and # we should try to raise an appropriate exception # from one of our exception classes defined in # exceptions.rb return false if response.is_a?(Net::HTTPSuccess) # parse the XML document so we can walk through it doc = REXML::Document.new(response.body) # Check that the Error element is in the place we would expect. # and if not raise a generic error exception unless doc.root.elements[1].name == "Error" raise Error, "Unexpected error format. response.body is: #{response.body}" end # An valid error response looks like this: # <?xml version="1.0"?><Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>Unknown parameter: foo</Message></Error></Errors><RequestID>291cef62-3e86-414b-900e-17246eccfae8</RequestID></Response> # AWS EC2 throws some exception codes that look like Error.SubError. Since we can't name classes this way # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this # non '.' name as well. error_code = doc.root.elements['//ErrorResponse/Error/Code'].text.gsub('.', '') = doc.root.elements['//ErrorResponse/Error/Message'].text # Raise one of our specific error classes if it exists. # otherwise, throw a generic EC2 Error with a few details. if AWS.const_defined?(error_code) raise AWS.const_get(error_code), else raise AWS::Error, end end |
#create_autoscaling_group(options = {}) ⇒ Object
Creates a new AutoScalingGroup with the specified name. You must not have already used up your entire quota of AutoScalingGroups in order for this call to be successful. Once the creation request is completed, the AutoScalingGroup is ready to be used in other calls.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 47 def create_autoscaling_group( = {} ) raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? raise ArgumentError, "No :availability_zones provided" if [:availability_zones].nil? || [:availability_zones].empty? raise ArgumentError, "No :launch_configuration_name provided" if [:launch_configuration_name].nil? || [:launch_configuration_name].empty? raise ArgumentError, "No :min_size provided" if [:min_size].nil? raise ArgumentError, "No :max_size provided" if [:max_size].nil? params = {} params.merge!(pathlist('AvailabilityZones.member', [[:availability_zones]].flatten)) params['LaunchConfigurationName'] = [:launch_configuration_name] params['AutoScalingGroupName'] = [:autoscaling_group_name] params['MinSize'] = [:min_size].to_s params['MaxSize'] = [:max_size].to_s params['LoadBalancerNames'] = [:load_balancer_names] if [:load_balancer_names] params['CoolDown'] = [:cooldown] if [:cooldown] return response_generator(:action => "CreateAutoScalingGroup", :params => params) end |
#create_launch_configuration(options = {}) ⇒ Object
Create a launch configuration Creates a new Launch Configuration. Please note that the launch configuration name used must be unique, within the scope of your AWS account, and the maximum limit of launch configurations must not yet have been met, or else the call will fail. Once created, the new launch configuration is available for immediate use.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 18 def create_launch_configuration( = {}) raise ArgumentError, "No :image_id provided" if [:image_id].nil? || [:image_id].empty? raise ArgumentError, "No :launch_configuration_name provided" if [:launch_configuration_name].nil? || [:launch_configuration_name].empty? raise ArgumentError, "No :instance_type provided" if [:instance_type].nil? || [:instance_type].empty? params = {} params["ImageId"] = [:image_id] params["KeyName"] = [:key_name] if [:key_name] params["LaunchConfigurationName"] = [:launch_configuration_name] params.merge!(pathlist('SecurityGroups.member', [[:security_groups]].flatten)) if [:security_groups] params["UserData"] = [:user_data] if [:user_data] params["InstanceType"] = [:instance_type] if [:instance_type] params["KernelId"] = [:kernel_id] if [:kernel_id] params["RamdiskId"] = [:ramdisk_id] if [:ramdisk_id] params.merge!(pathlist('BlockDeviceMappings.member', [[:block_device_mappings]].flatten)) if [:block_device_mappings] return response_generator(:action => "CreateLaunchConfiguration", :params => params) end |
#create_or_updated_scaling_trigger(options = {}) ⇒ Object
Create or update scaling trigger This call sets the parameters that governs when and how to scale an AutoScalingGroup.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 84 def create_or_updated_scaling_trigger( = {} ) if [:dimensions].nil? || [:dimensions].empty? raise ArgumentError, "No :dimensions provided" end raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? raise ArgumentError, "No :measure_name provided" if [:measure_name].nil? || [:measure_name].empty? raise ArgumentError, "No :statistic provided" if [:statistic].nil? || [:statistic].empty? raise ArgumentError, "No :period provided" if [:period].nil? raise ArgumentError, "No :trigger_name provided" if [:trigger_name].nil? || [:trigger_name].empty? raise ArgumentError, "No :lower_threshold provided" if [:lower_threshold].nil? raise ArgumentError, "No :lower_breach_scale_increment provided" if [:lower_breach_scale_increment].nil? raise ArgumentError, "No :upper_threshold provided" if [:upper_threshold].nil? raise ArgumentError, "No :upper_breach_scale_increment provided" if [:upper_breach_scale_increment].nil? raise ArgumentError, "No :breach_duration provided" if [:breach_duration].nil? statistic_option_list = %w(minimum maximum average sum) unless statistic_option_list.include?([:statistic].downcase) raise ArgumentError, "The statistic option must be one of the following: #{statistic_option_list.join(", ")}" end params = {} params['Unit'] = [:unit] || "Seconds" params['AutoScalingGroupName'] = [:autoscaling_group_name] case [:dimensions] when Array params["Dimensions.member.1.Name"] = [:dimensions][0] params["Dimensions.member.1.Value"] = [:dimensions][1] when Hash params["Dimensions.member.1.Name"] = [:dimensions][:name] params["Dimensions.member.1.Value"] = [:dimensions][:value] else raise ArgumentError, "Dimensionss must be either an array or a hash" end params['MeasureName'] = [:measure_name] params['Statistic'] = [:statistic] params['Period'] = [:period].to_s params['TriggerName'] = [:trigger_name] params['LowerThreshold'] = [:lower_threshold].to_s params['LowerBreachScaleIncrement'] = [:lower_breach_scale_increment].to_s params['UpperThreshold'] = [:upper_threshold].to_s params['UpperBreachScaleIncrement'] = [:upper_breach_scale_increment].to_s params['BreachDuration'] = [:breach_duration].to_s return response_generator(:action => "CreateOrUpdateScalingTrigger", :params => params) end |
#default_host ⇒ Object
25 26 27 |
# File 'lib/AWS/Autoscaling.rb', line 25 def default_host DEFAULT_HOST end |
#delete_autoscaling_group(options = {}) ⇒ Object
Deletes all configuration for this AutoScalingGroup and also deletes the group. In order to successfully call this API, no triggers (and therefore, Scaling Activity) can be currently in progress. Once this call successfully executes, no further triggers will begin and the AutoScalingGroup will not be available for use in other API calls. See key term Trigger.
134 135 136 137 138 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 134 def delete_autoscaling_group( = {} ) raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? params = { 'AutoScalingGroupName' => [:autoscaling_group_name] } return response_generator(:action => "DeleteAutoScalingGroup", :params => params) end |
#delete_launch_configuration(options = {}) ⇒ Object
Deletes the given Launch Configuration. The launch configuration to be deleted must not be currently attached to any AutoScalingGroup. Once this call completes, the launch configuration is no longer available for use by any other API call.
144 145 146 147 148 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 144 def delete_launch_configuration( = {} ) raise ArgumentError, "No :launch_configuration_name provided" if [:launch_configuration_name].nil? || [:launch_configuration_name].empty? params = { 'LaunchConfigurationName' => [:launch_configuration_name] } return response_generator(:action => "DeleteLaunchConfiguration", :params => params) end |
#delete_trigger(options = {}) ⇒ Object
Deletes the given trigger If a trigger is currently in progress, it will continue to run until its activities are complete.
154 155 156 157 158 159 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 154 def delete_trigger( = {} ) raise ArgumentError, "No :trigger_name provided" if [:trigger_name].nil? || [:trigger_name].empty? raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? params = { 'TriggerName' => [:trigger_name], 'AutoScalingGroupName' => [:autoscaling_group_name] } return response_generator(:action => "DeleteTrigger", :params => params) end |
#describe_autoscaling_groups(options = {}) ⇒ Object
Describe autoscaling group Returns a full description of the AutoScalingGroups from the given list. This includes all EC2 instances that are members of the group. If a list of names is not provided, then the full details of all AutoScalingGroups is returned. This style conforms to the EC2 DescribeInstances API behavior. See key term AutoScalingGroup.
165 166 167 168 169 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 165 def describe_autoscaling_groups( = {} ) = { :autoscaling_group_names => [] }.merge() params = pathlist("AutoScalingGroupNames.member", [:autoscaling_group_names]) return response_generator(:action => "DescribeAutoScalingGroups", :params => params) end |
#describe_launch_configurations(options = {}) ⇒ Object
Describe launch configurations 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. See key term Launch Configuration.
175 176 177 178 179 180 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 175 def describe_launch_configurations( = {} ) = { :launch_configuration_names => [] }.merge() params = pathlist("AutoScalingGroupNames.member", [:launch_configuration_names]) params['MaxRecords'] = [:max_records].to_s if .has_key?(:max_records) return response_generator(:action => "DescribeLaunchConfigurations", :params => params) end |
#describe_scaling_activities(options = {}) ⇒ Object
Describe autoscaling activities Returns the scaling activities specified for the given group. If the input list is empty, all the activities from the past six weeks will be returned. Activities will be sorted by completion time. Activities that have no completion time will be considered as using the most recent possible time. See key term Scaling Activity.
188 189 190 191 192 193 194 195 196 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 188 def describe_scaling_activities( = {} ) raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? params = {} params['AutoScalingGroupName'] = [:autoscaling_group_name] params['MaxRecords'] = [:max_records] if .has_key?(:max_records) params['ActivityIds'] = [:activity_ids] if .has_key?(:activity_ids) return response_generator(:action => "DescribeScalingActivities", :params => params) end |
#describe_triggers(options = {}) ⇒ Object
Describe triggers Returns a full description of the trigger (see Trigger), in the specified AutoScalingGroup.
202 203 204 205 206 207 208 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 202 def describe_triggers( = {} ) raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? params = {} params['AutoScalingGroupName'] = [:autoscaling_group_name] return response_generator(:action => "DescribeTriggers", :params => params) end |
#set_desired_capacity(options = {}) ⇒ Object
Set desired capacity This API adjusts the desired size of the AutoScalingGroup by initiating scaling activities, as necessary. When adjusting the size of the group downward, it is not possible to define which EC2 instances will be terminated. This applies to any auto-scaling decisions that might result in the termination of instances. To check the scaling status of the system, query the desired capacity using DescribeAutoScalingGroups and then query the actual capacity using DescribeAutoScalingGroups and looking at the instance lifecycle state in order to understand how close the system is to the desired capacity at any given time.
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 216 def set_desired_capacity( = {} ) raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? raise ArgumentError, "No :desired_capacity provided" if [:desired_capacity].nil? || [:desired_capacity].empty? params = {} params['AutoScalingGroupName'] = [:autoscaling_group_name] params['DesiredCapacity'] = [:desired_capacity].to_s return response_generator(:action => "SetDesiredCapacity", :params => params) end |
#terminate_instance_in_autoscaling_group(options = {}) ⇒ Object
Terminate instance in an autoscaling group This call will terminate the specified Instance. Optionally, the desired group size can be adjusted. If set to true, the default, the AutoScalingGroup size will decrease by one. If the AutoScalingGroup is associated with a LoadBalancer, the system will deregister the instance before terminating it. This call simply registers a termination request. The termination of the instance can not happen immediately.
234 235 236 237 238 239 240 241 242 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 234 def terminate_instance_in_autoscaling_group( = {} ) raise ArgumentError, "No :instance_id provided" if [:instance_id].nil? || [:instance_id].empty? params = {} params['InstanceId'] = [:instance_id] params['ShouldDecrementDesiredCapacity'] = [:decrement_desired_capacity].to_s if .has_key?(:decrement_desired_capacity) return response_generator(:action => "TerminateInstanceInAutoScalingGroup", :params => params) end |
#update_autoscaling_group(options = {}) ⇒ Object
Creates a new AutoScalingGroup with the specified name. Updates the configuration for the given AutoScalingGroup. If MaxSize is lower than the current size, then there will be an implicit call to SetDesiredCapacity to set the group to the new MaxSize. The same is true for MinSize there will also be an implicit call to SetDesiredCapacity. All optional parameters are left unchanged if not passed in the request.= The new settings are registered upon the completion of this call. Any launch configuration settings will take effect on any triggers after this call returns. However, triggers that are currently in progress can not be affected. See key term Trigger.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 254 def update_autoscaling_group( = {}) raise ArgumentError, "No :autoscaling_group_name provided" if [:autoscaling_group_name].nil? || [:autoscaling_group_name].empty? params = {} params.merge!(pathlist('AvailabilityZones.member', [[:availability_zones]].flatten)) if .has_key?(:availability_zones) params['LaunchConfigurationName'] = [:launch_configuration_name] if .has_key?(:launch_configuration_name) params['AutoScalingGroupName'] = [:autoscaling_group_name] params['MinSize'] = [:min_size] if .has_key?(:min_size) params['MaxSize'] = [:max_size] if .has_key?(:max_size) params['CoolDown'] = [:cooldown] if .has_key?(:cooldown) return response_generator(:action => "UpdateAutoScalingGroup", :params => params) end |