Class: AWS::Autoscaling::Base

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from AWS::Base

Instance Method Details

#api_versionObject



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.

Returns:

  • (Boolean)


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('.', '')
  error_message = 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), error_message
  else
    raise AWS::Error, error_message
  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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling group

  • :availability_zones (Array) — default: nil

    The availability_zones for the group

  • :launch_configuration_name (String) — default: nil

    the name of the launch_configuration group

  • :min_size (String) — default: nil

    minimum size of the group

  • :max_size (String) — default: nil

    the maximum size of the group

  • :load_balancer_names (String) — default: nil

    the names of the load balancers

  • :cooldown (String) — default: nil

    the amount of time after a scaling activity complese before any further trigger-related scaling activities can start

Raises:



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( options = {} )
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?
  raise ArgumentError, "No :availability_zones provided" if options[:availability_zones].nil? || options[:availability_zones].empty?
  raise ArgumentError, "No :launch_configuration_name provided" if options[:launch_configuration_name].nil? || options[:launch_configuration_name].empty?
  raise ArgumentError, "No :min_size provided" if options[:min_size].nil?
  raise ArgumentError, "No :max_size provided" if options[:max_size].nil?

  params = {}

  params.merge!(pathlist('AvailabilityZones.member', [options[:availability_zones]].flatten))
  params['LaunchConfigurationName'] = options[:launch_configuration_name]
  params['AutoScalingGroupName'] = options[:autoscaling_group_name]
  params['MinSize'] = options[:min_size].to_s
  params['MaxSize'] = options[:max_size].to_s
  params['LoadBalancerNames'] = options[:load_balancer_names] if options[:load_balancer_names]
  params['CoolDown'] = options[:cooldown] if options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :launch_configuration_name (String) — default: nil

    the name of the launch configuration

  • :image_id (String) — default: nil

    the image id to use with this launch configuration

  • :instance_type (String) — default: nil

    the type of instance to launch

  • :security_groups (Array) — default: nil

    the names of security_groups to launch within

  • :key_name (String) — default: nil

    the name of the EC2 key pair

  • :user_data (String) — default: nil

    the user data available to the launched EC2 instances

  • :kernel_id (String) — default: nil

    the ID of the kernel associated with the EC2 ami

  • :ramdisk_id (String) — default: nil

    the name of the RAM disk associated with the EC2 ami

  • :block_device_mappings (Array) — default: nil

    specifies how block devices are exposed to the instance

Raises:



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( options = {})
  raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
  raise ArgumentError, "No :launch_configuration_name provided" if options[:launch_configuration_name].nil? || options[:launch_configuration_name].empty?
  raise ArgumentError, "No :instance_type provided" if options[:instance_type].nil? || options[:instance_type].empty?

  params = {}
  params["ImageId"] = options[:image_id]
  params["KeyName"] = options[:key_name] if options[:key_name]
  params["LaunchConfigurationName"] = options[:launch_configuration_name]
  params.merge!(pathlist('SecurityGroups.member', [options[:security_groups]].flatten)) if options[:security_groups]
  params["UserData"] = options[:user_data] if options[:user_data]
  params["InstanceType"] = options[:instance_type] if options[:instance_type]
  params["KernelId"] = options[:kernel_id] if options[:kernel_id]
  params["RamdiskId"] = options[:ramdisk_id] if options[:ramdisk_id]
  params.merge!(pathlist('BlockDeviceMappings.member', [options[:block_device_mappings]].flatten)) if options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling group

  • :dimensions (Array|Hash) — default: nil

    The dimensions associated with the metric used by the trigger to determine whether to activate This must be given as either an array or a hash When called as a hash, the values must look like: => “name”, :value => “value” In the array format, the first value is assumed to be the name and the second is assumed to be the value

  • :measure_name (String) — default: nil

    the measure name associated with the metric used by the trigger

  • :period (String|Integer) — default: nil

    the period associated with the metric in seconds

  • :statistic (String) — default: nil

    The particular statistic used by the trigger when fetching metric statistics to examine. Must be one of the following: Minimum, Maximum, Sum, Average

  • :trigger_name (String) — default: nil

    the name for this trigger

  • :unit (String) — default: nil

    the standard unit of measurement for a given measure

  • :lower_threshold (String|Integer) — default: nil

    the lower limit for the metric. If all datapoints in the last :breach_duration seconds fall below the lower threshold, the trigger will activate

  • :lower_breach_scale_increment (String|Integer) — default: nil

    the incremental amount to use when performing scaling activities when the lower threshold has been breached

  • :upper_threshold (String|Integer) — default: nil

    the upper limit for the metric. If all datapoints in the last :breach_duration seconds exceed the upper threshold, the trigger will activate

  • :upper_breach_scale_increment (String|Integer) — default: nil

    the incremental amount to use when performing scaling activities when the upper threshold has been breached

Raises:



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( options = {} )
  if options[:dimensions].nil? || options[:dimensions].empty?
    raise ArgumentError, "No :dimensions provided"
  end
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?
  raise ArgumentError, "No :measure_name provided" if options[:measure_name].nil? || options[:measure_name].empty?
  raise ArgumentError, "No :statistic provided" if options[:statistic].nil? || options[:statistic].empty?
  raise ArgumentError, "No :period provided" if options[:period].nil?
  raise ArgumentError, "No :trigger_name provided" if options[:trigger_name].nil? || options[:trigger_name].empty?
  raise ArgumentError, "No :lower_threshold provided" if options[:lower_threshold].nil?
  raise ArgumentError, "No :lower_breach_scale_increment provided" if options[:lower_breach_scale_increment].nil?
  raise ArgumentError, "No :upper_threshold provided" if options[:upper_threshold].nil?
  raise ArgumentError, "No :upper_breach_scale_increment provided" if options[:upper_breach_scale_increment].nil?
  raise ArgumentError, "No :breach_duration provided" if options[:breach_duration].nil?
  statistic_option_list = %w(minimum maximum average sum)
  unless statistic_option_list.include?(options[:statistic].downcase)

    raise ArgumentError, "The statistic option must be one of the following: #{statistic_option_list.join(", ")}"
  end

  params = {}
  params['Unit'] = options[:unit] || "Seconds"
  params['AutoScalingGroupName'] = options[:autoscaling_group_name]
  case options[:dimensions]
  when Array
    params["Dimensions.member.1.Name"] = options[:dimensions][0]
    params["Dimensions.member.1.Value"] = options[:dimensions][1]
  when Hash
    params["Dimensions.member.1.Name"] = options[:dimensions][:name]
    params["Dimensions.member.1.Value"] = options[:dimensions][:value]
  else
    raise ArgumentError, "Dimensionss must be either an array or a hash"
  end
  params['MeasureName'] = options[:measure_name]
  params['Statistic'] = options[:statistic]
  params['Period'] = options[:period].to_s
  params['TriggerName'] = options[:trigger_name]
  params['LowerThreshold'] = options[:lower_threshold].to_s
  params['LowerBreachScaleIncrement'] = options[:lower_breach_scale_increment].to_s
  params['UpperThreshold'] = options[:upper_threshold].to_s
  params['UpperBreachScaleIncrement'] = options[:upper_breach_scale_increment].to_s
  params['BreachDuration'] = options[:breach_duration].to_s

  return response_generator(:action => "CreateOrUpdateScalingTrigger", :params => params)
end

#default_hostObject



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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling group

Raises:



134
135
136
137
138
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 134

def delete_autoscaling_group( options = {} )
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?
  params = { 'AutoScalingGroupName' => options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :launch_configuration_name (String) — default: nil

    the name of the launch_configuration

Raises:



144
145
146
147
148
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 144

def delete_launch_configuration( options = {} )
  raise ArgumentError, "No :launch_configuration_name provided" if options[:launch_configuration_name].nil? || options[:launch_configuration_name].empty?
  params = { 'LaunchConfigurationName' => options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :trigger_name (String) — default: nil

    the name of the trigger to delete

Raises:



154
155
156
157
158
159
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 154

def delete_trigger( options = {} )
  raise ArgumentError, "No :trigger_name provided" if options[:trigger_name].nil? || options[:trigger_name].empty?
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?
  params = { 'TriggerName' => options[:trigger_name], 'AutoScalingGroupName' => options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_names (Array) — default: nil

    the name of the autoscaling groups to describe



165
166
167
168
169
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 165

def describe_autoscaling_groups( options = {} )
  options = { :autoscaling_group_names => [] }.merge(options)
  params = pathlist("AutoScalingGroupNames.member", options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :launch_configuration_names (Array) — default: nil

    the name of the launch_configurations to describe



175
176
177
178
179
180
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 175

def describe_launch_configurations( options = {} )
  options = { :launch_configuration_names => [] }.merge(options)
  params = pathlist("AutoScalingGroupNames.member", options[:launch_configuration_names])
  params['MaxRecords'] = options[:max_records].to_s if options.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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling_group_name

  • :max_records (String) — default: nil

    the maximum number of scaling activities to return

  • :launch_configuration_names (String) — default: nil

    activity_ids to return

Raises:



188
189
190
191
192
193
194
195
196
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 188

def describe_scaling_activities( options = {} )
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?

  params = {}
  params['AutoScalingGroupName'] = options[:autoscaling_group_name]
  params['MaxRecords'] = options[:max_records] if options.has_key?(:max_records)
  params['ActivityIds'] = options[:activity_ids] if options.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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling_group_name

Raises:



202
203
204
205
206
207
208
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 202

def describe_triggers( options = {} )
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?
  params = {}
  params['AutoScalingGroupName'] = options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling_group_name

  • :desired_capacity (String) — default: nil

    the new capacity setting for the group

Raises:



216
217
218
219
220
221
222
223
224
225
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 216

def set_desired_capacity( options = {} )
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?
  raise ArgumentError, "No :desired_capacity provided" if options[:desired_capacity].nil? || options[:desired_capacity].empty?

  params = {}
  params['AutoScalingGroupName'] = options[:autoscaling_group_name]
  params['DesiredCapacity'] = options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :instance_id (String) — default: nil

    the instance id to terminate

  • :decrement_desired_capacity (String) — default: nil

    specified whether terminating this instance should also decrement the size of the autoscaling group

Raises:



234
235
236
237
238
239
240
241
242
# File 'lib/AWS/Autoscaling/autoscaling.rb', line 234

def terminate_instance_in_autoscaling_group( options = {} )
  raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?

  params = {}
  params['InstanceId'] = options[:instance_id]
  params['ShouldDecrementDesiredCapacity'] = options[:decrement_desired_capacity].to_s if options.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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :autoscaling_group_name (String) — default: nil

    the name of the autoscaling group

  • :availability_zones (Array) — default: nil

    The availability_zones for the group

  • :launch_configuration_name (String) — default: nil

    the name of the launch_configuration group

  • :min_size (String) — default: nil

    minimum size of the group

  • :max_size (String) — default: nil

    the maximum size of the group

  • :cooldown (String) — default: nil

    the amount of time after a scaling activity complese before any further trigger-related scaling activities can start

Raises:



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( options = {})
  raise ArgumentError, "No :autoscaling_group_name provided" if options[:autoscaling_group_name].nil? || options[:autoscaling_group_name].empty?

  params = {}

  params.merge!(pathlist('AvailabilityZones.member', [options[:availability_zones]].flatten)) if options.has_key?(:availability_zones)
  params['LaunchConfigurationName'] = options[:launch_configuration_name] if options.has_key?(:launch_configuration_name)
  params['AutoScalingGroupName'] = options[:autoscaling_group_name]
  params['MinSize'] = options[:min_size] if options.has_key?(:min_size)
  params['MaxSize'] = options[:max_size] if options.has_key?(:max_size)
  params['CoolDown'] = options[:cooldown]  if options.has_key?(:cooldown)

  return response_generator(:action => "UpdateAutoScalingGroup", :params => params)

end