Class: AWS::AutoScaling::Group

Inherits:
Core::Resource show all
Includes:
GroupOptions
Defined in:
lib/aws/auto_scaling/group.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(name, options = {}) ⇒ Group

Returns a new instance of Group.



51
52
53
54
# File 'lib/aws/auto_scaling/group.rb', line 51

def initialize name, options = {}
  @name = name
  super
end

Instance Attribute Details

#availability_zone_namesArray<String> (readonly)

Returns the current value of availability_zone_names.

Returns:

  • (Array<String>)

    the current value of availability_zone_names



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def availability_zone_names
  @availability_zone_names
end

#created_timeTime (readonly)

Returns the current value of created_time.

Returns:

  • (Time)

    the current value of created_time



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def created_time
  @created_time
end

#default_cooldownInteger (readonly)

Returns the current value of default_cooldown.

Returns:

  • (Integer)

    the current value of default_cooldown



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def default_cooldown
  @default_cooldown
end

#desired_capacityInteger (readonly)

Returns the current value of desired_capacity.

Returns:

  • (Integer)

    the current value of desired_capacity



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def desired_capacity
  @desired_capacity
end

#enabled_metricsArray<Hash> (readonly)

Returns a hash of enabled metric names (keys) and granularities (values).

Returns:

  • (Array<Hash>)

    the current value of enabled_metrics



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def enabled_metrics
  @enabled_metrics
end

#health_check_grace_periodInteger (readonly)

Returns the current value of health_check_grace_period.

Returns:

  • (Integer)

    the current value of health_check_grace_period



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def health_check_grace_period
  @health_check_grace_period
end

#health_check_typeSymbol (readonly)

Returns :ec2 or :vpc.

Returns:

  • (Symbol)

    the current value of health_check_type



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def health_check_type
  @health_check_type
end

#launch_configuraiton_nameString (readonly)

Returns the current value of launch_configuraiton_name.

Returns:

  • (String)

    the current value of launch_configuraiton_name



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def launch_configuraiton_name
  @launch_configuraiton_name
end

#load_balancer_namesArray<String> (readonly)

Returns the current value of load_balancer_names.

Returns:

  • (Array<String>)

    the current value of load_balancer_names



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def load_balancer_names
  @load_balancer_names
end

#max_sizeInteger (readonly)

Returns the current value of max_size.

Returns:

  • (Integer)

    the current value of max_size



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def max_size
  @max_size
end

#min_sizeInteger (readonly)

Returns the current value of min_size.

Returns:

  • (Integer)

    the current value of min_size



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def min_size
  @min_size
end

#nameString (readonly)

Returns:

  • (String)


57
58
59
# File 'lib/aws/auto_scaling/group.rb', line 57

def name
  @name
end

#placement_groupString? (readonly)

Returns the current value of placement_group.

Returns:

  • (String, nil)

    the current value of placement_group



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def placement_group
  @placement_group
end

#suspended_processesHash (readonly)

A hash of suspended process names (keys) and reasons (values).

Returns:

  • (Hash)

    the current value of suspended_processes



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def suspended_processes
  @suspended_processes
end

Instance Method Details

#activitiesActivityCollection

Returns:



146
147
148
# File 'lib/aws/auto_scaling/group.rb', line 146

def activities
  ActivityCollection.new(:group => self)
end

#auto_scaling_instancesArray<AutoScaling::Instance>

Returns:



151
152
153
154
155
156
157
158
159
160
# File 'lib/aws/auto_scaling/group.rb', line 151

def auto_scaling_instances
  instances.collect do |details|
    Instance.new_from(
      :describe_auto_scaling_groups, 
      details,
      details.instance_id, 
      :auto_scaling_group_name => name, # not provided by the response
      :config => config)
  end
end

#availability_zonesArray<EC2::AvailabilityZone>

Returns:



187
188
189
190
191
# File 'lib/aws/auto_scaling/group.rb', line 187

def availability_zones
  availability_zone_names.collect do |az_name|
    EC2::AvailabilityZone.new(az_name, :config => config)
  end
end

#delete(options = {}) ⇒ nil

Deletes the Auto Scaling group. If you pass :force as true then all the instances associated with this group will also be terminated.

Parameters:

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

Options Hash (options):

  • :force (Boolean) — default: false

    When true, the Auto Scaling group will be deleted along with all instances associated with the group, without waiting for all instances to be terminated.

Returns:

  • (nil)

See Also:



383
384
385
386
387
388
389
# File 'lib/aws/auto_scaling/group.rb', line 383

def delete options = {}
  client_opts = {}
  client_opts[:force_delete] = options[:force] == true
  client_opts[:auto_scaling_group_name] = name
  client.delete_auto_scaling_group(client_opts)
  nil
end

#delete!nil

Deletes the Auto Scaling group along with all instances associated with the group, without waiting for all instances to be terminated.

Returns:

  • (nil)


395
396
397
398
# File 'lib/aws/auto_scaling/group.rb', line 395

def delete!
  delete(:force => true)
  nil
end

#delete_all_tagsnil

Removes all tags from this Auto Scaling group.

Returns:

  • (nil)


364
365
366
367
# File 'lib/aws/auto_scaling/group.rb', line 364

def delete_all_tags
  delete_tags(self.tags)
  nil
end

#delete_tags(*tags) ⇒ nil

Deletes specific tags from this Auto Scaling group.

group.delete_tags([
  { :key => 'role', :value => 'webserver' },
])

You may also pass Tag objects.

Parameters:

  • tags (Array<Tag,Hash>)

    An array of Tag objects or tag hashes to remove. If you pass hashes they should have the following keys:

    • :key

    • :value

    • :propagate_at_launch

Returns:

  • (nil)


352
353
354
355
356
357
358
359
360
# File 'lib/aws/auto_scaling/group.rb', line 352

def delete_tags *tags
  tags = tags.flatten.collect do |tag|
    tag.to_hash.merge(
      :resource_type => 'auto-scaling-group',
      :resource_id => name)
  end
  client.delete_tags(:tags => tags)
  nil
end

#disable_all_metrics_collectionnil

Disables all metrics collection for the Auto Scaling group.

Returns:

  • (nil)


299
300
301
# File 'lib/aws/auto_scaling/group.rb', line 299

def disable_all_metrics_collection
  disable_metrics_collection
end

#disable_metrics_collection(*metrics) ⇒ nil

Parameters:

  • metrics (Array<String>)

    A list of metrics to collect.

Returns:

  • (nil)


289
290
291
292
293
294
295
# File 'lib/aws/auto_scaling/group.rb', line 289

def disable_metrics_collection *metrics
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:metrics] = metrics.flatten
  client.disable_metrics_collection(client_opts)
  nil
end

#ec2_instancesEC2::InstanceCollection

Returns a collection that represents the instances belonging to this Auto Scaling group. You can use this collection to further refine the instances you are interested in:

group.ec2_instances.filter('availability-zone', 'us-east-1a').each do |i|
  puts instance.id
end

Returns:

  • (EC2::InstanceCollection)

    Returns an instance collection (without making a request) that represents the instances belonging to this Auto Scaling group.



174
175
176
177
# File 'lib/aws/auto_scaling/group.rb', line 174

def ec2_instances
  instances = EC2::InstanceCollection.new(:config => config)
  instances.tagged('aws:autoscaling:groupName').tagged_values(name)
end

#enable_all_metrics_collectionnil

Enables all metrics collection for the Auto Scaling group.

Returns:

  • (nil)


283
284
285
# File 'lib/aws/auto_scaling/group.rb', line 283

def enable_all_metrics_collection
  enable_metrics_collection
end

#enable_metrics_collection(*metrics) ⇒ nil

Parameters:

  • metrics (Array<String>)

    A list of metrics to collect.

Returns:

  • (nil)


272
273
274
275
276
277
278
279
# File 'lib/aws/auto_scaling/group.rb', line 272

def enable_metrics_collection *metrics
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:granularity] = '1Minute'
  client_opts[:metrics] = metrics.flatten
  client.enable_metrics_collection(client_opts)
  nil
end

#exists?Boolean

Returns:

  • (Boolean)


401
402
403
404
405
406
# File 'lib/aws/auto_scaling/group.rb', line 401

def exists?
  client_opts = {}
  client_opts[:auto_scaling_group_names] = [name]
  resp = client.describe_auto_scaling_groups(client_opts)  
  !resp.auto_scaling_groups.empty?
end

#launch_configurationLaunchConfiguration

Returns:



141
142
143
# File 'lib/aws/auto_scaling/group.rb', line 141

def launch_configuration
  LaunchConfiguration.new(launch_configuration_name, :config => config)
end

#load_balancersArray, <ELB::LoadBalancer>

Returns:



194
195
196
197
198
# File 'lib/aws/auto_scaling/group.rb', line 194

def load_balancers
  load_balancer_names.collect do |name|
    ELB::LoadBalancer.new(name, :config => config)
  end
end

#notification_configurationsNotificationConfigurationCollection



123
124
125
# File 'lib/aws/auto_scaling/group.rb', line 123

def notification_configurations
  NotificationConfigurationCollection.new(:group => self)
end

#resume_all_processesnil

Resumes all processes for this Auto Scaling group.

Returns:

  • (nil)


266
267
268
# File 'lib/aws/auto_scaling/group.rb', line 266

def resume_all_processes
  resume_processes
end

#resume_processes(*processes) ⇒ nil

Resumes processes for this Auto Scaling group.

# resume two processes by name
auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'

Parameters:

  • processes (Array<String>)

    A list of process to resume.

Returns:

  • (nil)


256
257
258
259
260
261
262
# File 'lib/aws/auto_scaling/group.rb', line 256

def resume_processes *processes
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:scaling_processes] = processes.flatten
  client.resume_processes(client_opts)
  nil
end

#scaling_policiesScalingPolicyCollection



118
119
120
# File 'lib/aws/auto_scaling/group.rb', line 118

def scaling_policies
  ScalingPolicyCollection.new(self)
end

#scheduled_actionsScheduledActionCollection



128
129
130
131
# File 'lib/aws/auto_scaling/group.rb', line 128

def scheduled_actions
  actions = ScheduledActionCollection.new(:config => config)
  actions.filter(:group => self)
end

#set_desired_capacity(capacity, options = {}) ⇒ nil

Adjusts the desired size of the Auto Scaling group 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.

Parameters:

  • capacity (Integer)

    The new capacity setting for this Auto Scaling group.

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

Options Hash (options):

  • :honor_cooldown (Boolean) — default: false

Returns:

  • (nil)


215
216
217
218
219
220
221
222
# File 'lib/aws/auto_scaling/group.rb', line 215

def set_desired_capacity capacity, options = {}
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:desired_capacity] = capacity
  client_opts[:honor_cooldown] = options[:honor_cooldown] == true
  client.set_desired_capacity(client_opts)
  nil
end

#subnetsArray<EC2::Subnet>

Returns:



180
181
182
183
184
# File 'lib/aws/auto_scaling/group.rb', line 180

def subnets
  vpc_zone_identifier.to_s.split(/,/).collect do |subnet_id|
    EC2::Subnet.new(subnet_id, :config => config)
  end
end

#suspend_all_processesnil

Suspends all processes for this Auto Scaling group.

Returns:

  • (nil)


243
244
245
# File 'lib/aws/auto_scaling/group.rb', line 243

def suspend_all_processes
  suspend_processes
end

#suspend_processes(*processes) ⇒ nil

Suspends processes for this Auto Scaling group.

# suspend two processes by name
auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'

Parameters:

  • processes (Array<String>)

    A list of process to suspend.

Returns:

  • (nil)


233
234
235
236
237
238
239
# File 'lib/aws/auto_scaling/group.rb', line 233

def suspend_processes *processes
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:scaling_processes] = processes.flatten
  client.suspend_processes(client_opts)
  nil
end

#tagsTag

Returns:



134
135
136
137
138
# File 'lib/aws/auto_scaling/group.rb', line 134

def tags
  tag_details.collect do |tag|
    Tag.new(tag.to_hash.merge(:config => config))
  end
end

#update(options = {}) ⇒ nil

Update one or more attributes on the Auto Scaling group.

Parameters:

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

Options Hash (options):

  • :min_size (required, Integer)

    The maximum size of the Auto Scaling group.

  • :max_size (required, Integer)

    The minimum size of the Auto Scaling group.

  • :launch_configuration (required, LaunchConfiguration, String)

    The launch configuration to use with the Auto Scaling group. This may be a LaunchConfiguration object or a launch configuration name string.

  • :availability_zones (required, Array<String>)

    A list of Availability Zones for the Auto Scaling group. This can be EC2::AvailabilityZone objects or availability zone names.

  • :default_cooldown (Integer)

    The amount of time, in seconds, after a scaling activity completes before any further trigger-related scaling activities can start.

  • :desired_capacity (Integer)

    The number of Amazon EC2 instances that should be running in the group.

  • :health_check_grace_period (Integer)

    Length of time in seconds after a new Amazon EC2 instance comes into service that Auto Scaling starts checking its health.

  • :health_check_type (Symbol)

    The service you want the health status from, Amazon EC2 or Elastic Load Balancer. Valid values are :ec2 or :elb.

  • :placement_group (String)

    Physical location of your cluster placement group created in Amazon EC2. For more information about cluster placement group, see Using Cluster Instances.

  • :tags (Array<Hash>)

    A list of tags to apply launched instances. Each tag hash may have the following keys:

    • :key - (required,String) The tag name.

    • :value - (String) The optional tag value.

    • :propagate_at_launch - (Boolean) Whether or not to propagate to instances, defaults to true.

  • :subnets (Array<EC2::Subnet>, Array<String>)

    A list of subnet identifiers of Amazon Virtual Private Clouds (Amazon VPCs). Ensure the subnets’ Availability Zones match the Availability Zones specified.

Returns:

  • (nil)


311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/aws/auto_scaling/group.rb', line 311

def update options = {}

  group_opts = group_options(options) 

  # tags must be updated using a separate request from the
  # other attributes, *sigh*
  if tags = group_opts.delete(:tags)
    tags.map(&:to_hash).each do |tag|
      tag[:resource_type] = 'auto-scaling-group'
      tag[:resource_id] = name
    end
    client.create_or_update_tags(:tags => tags)
  end

  unless group_opts.empty?
    client_opts = group_opts.merge(:auto_scaling_group_name => name)
    client.update_auto_scaling_group(client_opts)
  end

  nil

end