Class: Aws::AutoScaling::Fleet

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-autoscaling/fleet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Fleet

Returns a new instance of Fleet.



4
5
6
7
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 4

def initialize name, options
  @name = name
  @client = options.delete(:client)
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 10

def name
  @name
end

Class Method Details

.options_from(obj, *attributes) ⇒ Object

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



134
135
136
137
138
139
140
141
142
143
144
145
146
# 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

Instance Method Details

#any_groupGroup

Returns:

  • (Group)


56
57
58
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 56

def any_group
  group_for_tag(tags.first)
end

#any_lc_groupObject



60
61
62
63
64
65
# 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?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 71

def exists?
  !any_group.nil?
end

#group_for_tag(tag) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# 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

#groupsObject



75
76
77
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 75

def groups
  FleetGroupCollection.new(self)
end

#resume_all_processesObject

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



89
90
91
92
93
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 89

def resume_all_processes
  groups.each do |group|
    group.resume_processes
  end
end

#suspend_all_processesObject

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



81
82
83
84
85
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 81

def suspend_all_processes
  groups.each do |group|
    group.suspend_processes
  end
end

#tag_nameObject



45
46
47
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 45

def tag_name
  "asgfleet:#{name}"
end

#tags(filters = []) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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_groupGroup

Returns:

  • (Group)


50
51
52
53
# 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_groupObject



67
68
69
# 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 = {}) ⇒ Object

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.

Parameters:

  • name (String)

    The name of the new launch configuration

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

    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.



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-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