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.



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 121

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

#exists?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 64

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



68
69
70
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 68

def groups
  FleetGroupCollection.new(self)
end

#resume_all_processesObject

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



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

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.



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

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



60
61
62
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 60

def template_or_any_group
  template_group || any_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.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/aws-sdk-autoscaling/fleet.rb', line 99

def update_launch_configuration name, options = {}
  old_lc = template_or_any_group.launch_configuration
  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|
    group.update(:launch_configuration_name => name)
  end

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