class Aws::AutoScaling::Fleet

Attributes

name[R]

@return [String]

Public Class Methods

new(name, options) click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 4
def initialize name, options
  @name = name
  @client = options.delete(:client)
end
options_from(obj, *attributes) click to toggle source

@private Collects non-nil, non-empty-array attributes from the supplied object into a Hash. Also converts any Array-like objects into real Arrays.

# File lib/aws-sdk-autoscaling/fleet.rb, line 134
def self.options_from(obj, *attributes)
  opts = {}
  attributes.each do |key|
    value = obj.send(key)
    next if value.blank?
    if value.is_a? Array
      value = value.to_a
      next if value.empty?
    end
    opts[key] ||= value
  end
  opts
end

Public Instance Methods

any_group() click to toggle source

@return [Group]

# File lib/aws-sdk-autoscaling/fleet.rb, line 56
def any_group
  group_for_tag(tags.first)
end
any_lc_group() click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 60
def any_lc_group
  tag_with_lc = tags.detect { |tag| !group_for_tag(tag).launch_configuration.nil? }
  return nil if tag_with_lc.nil?

  group_for_tag(tag_with_lc)
end
exists?() click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 71
def exists?
  !any_group.nil?
end
group_for_tag(tag) click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 34
def group_for_tag(tag)
  return nil unless tag
  case tag.resource_type
  when 'auto-scaling-group'
    AutoScalingGroup.new(name: tag.resource_id, client: @client)
  else
    msg = "unhandled resource type: #{tag.resource_type}" # shamelessly copied from old aws-sdk
    raise ArgumentError, msg
  end
end
groups() click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 75
def groups
  FleetGroupCollection.new(self)
end
resume_all_processes() click to toggle source

Resumes all scaling processes in all Auto Scaling groups in the fleet.

# File lib/aws-sdk-autoscaling/fleet.rb, line 89
def resume_all_processes
  groups.each do |group|
    group.resume_processes
  end
end
suspend_all_processes() click to toggle source

Suspends all scaling processes in all Auto Scaling groups in the fleet.

# File lib/aws-sdk-autoscaling/fleet.rb, line 81
def suspend_all_processes
  groups.each do |group|
    group.suspend_processes
  end
end
tag_name() click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 45
def tag_name
  "asgfleet:#{name}"
end
tags(filters=[]) click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 12
def tags(filters=[])
  # mostly copied from Resource#tags
  options = {:filters => [{:name => "key", :values => [tag_name]}] + filters}
  batches = Enumerator.new do |y|
    resp = @client.describe_tags(options)
    resp.each_page do |page|
      batch = []
      page.data.tags.each do |t|
        batch << Tag.new(
          key: t.key,
          resource_id: t.resource_id,
          resource_type: t.resource_type,
          data: t,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  Tag::Collection.new(batches)
end
template_group() click to toggle source

@return [Group]

# File lib/aws-sdk-autoscaling/fleet.rb, line 50
def template_group
  tag = tags([{:name => 'value', :values => ["template"]}]).first
  group_for_tag(tag)
end
template_or_any_group() click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 67
def template_or_any_group
  template_group || any_lc_group
end
update_launch_configuration(name, options = {}) click to toggle source

Creates a new launch configuration and applies it to all the Auto Scaling groups in the fleet. Any options not specified will be pulled from the Launch Configuration currently attached to the template Auto Scaling group.

@param [String] name The name of the new launch configuration

@param [Hash] options Options for the new launch configuration.

Any options not specified in this hash will be pulled from the
existing launch configuration on the template scaling group.
# File lib/aws-sdk-autoscaling/fleet.rb, line 106
def update_launch_configuration name, options = {}
  old_lc = template_or_any_group&.launch_configuration
  # There aren't any groups using lcs, so skip updating
  return if old_lc.nil?

  options = Fleet.options_from(old_lc,
    :image_id, :instance_type,
    :block_device_mappings, :instance_monitoring, :kernel_id,
    :key_name, :ramdisk_id, :security_groups, :user_data,
    :iam_instance_profile, :spot_price).merge(options)

  options[:launch_configuration_name] = name
  @client.create_launch_configuration(options)

  groups.each do |group|
    next unless group.launch_template.nil?
    next unless group.mixed_instances_policy.nil?

    group.update(:launch_configuration_name => name)
  end

  LaunchConfiguration.new(name: name, client: @client)
end

Protected Instance Methods

resource_identifiers() click to toggle source
# File lib/aws-sdk-autoscaling/fleet.rb, line 150
def resource_identifiers
  [[:name, name]]
end