class Skipper::Servers::EC2

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/skipper/servers/ec2.rb, line 9
def initialize(options)
  @options = options
end

Public Instance Methods

hosts() click to toggle source
# File lib/skipper/servers/ec2.rb, line 17
def hosts
  @hosts ||= instances.map { |instance| instance.ip_address }.compact
end
instances() click to toggle source
# File lib/skipper/servers/ec2.rb, line 13
def instances
  @instances ||= find_instances
end
to_s() click to toggle source
# File lib/skipper/servers/ec2.rb, line 21
def to_s
  @to_s ||= details_table(instances)
end

Private Instance Methods

details_table(list) click to toggle source
# File lib/skipper/servers/ec2.rb, line 58
def details_table(list)
  table = StringIO.new
  original_stdout, $stdout = $stdout, table

  tp(list, :id, :ip_address)

  $stdout = original_stdout
  table.read
end
ec2() click to toggle source
# File lib/skipper/servers/ec2.rb, line 27
def ec2
  @ec2 ||= AWS::EC2.new(region: options[:region])
end
filter_auto_scaling_groups(filtered) click to toggle source
# File lib/skipper/servers/ec2.rb, line 44
def filter_auto_scaling_groups(filtered)
  options.auto_scaling_groups.each do |value|
    filtered = filtered.filter('tag:aws:autoscaling:groupName', value)
  end
  filtered
end
filter_auto_scaling_roles(filtered) click to toggle source
# File lib/skipper/servers/ec2.rb, line 51
def filter_auto_scaling_roles(filtered)
  options.auto_scaling_roles.each do |value|
    filtered = filtered.filter('tag:aws:autoscaling:role', value)
  end
  filtered
end
filter_tags(filtered) click to toggle source
# File lib/skipper/servers/ec2.rb, line 37
def filter_tags(filtered)
  options.tags.each do |tag, value|
    filtered = filtered.filter("tag:#{tag}", value.split(','))
  end
  filtered
end
find_instances() click to toggle source
# File lib/skipper/servers/ec2.rb, line 31
def find_instances
  filtered = filter_tags(ec2.instances)
  filtered = filter_auto_scaling_groups(filtered)
  filter_auto_scaling_roles(filtered)
end