module Eclair::EC2Provider
Public Instance Methods
find_image_by_id(id)
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 55 def find_image_by_id id @image_thread.join if @image_thread.alive? @id_to_image[id] end
find_security_group_by_id(id)
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 69 def find_security_group_by_id id @sg_thread.join if @sg_thread.alive? @id_to_sg[id] end
find_vpc_by_id(id)
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 83 def find_vpc_by_id id @vpc_thread.join if @vpc_thread.alive? @id_to_vpc[id] end
group_class()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 12 def group_class EC2GroupItem end
image_loaded?()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 46 def image_loaded? !@sg_thread.alive? end
images()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 50 def images @image_thread.join if @image_thread.alive? @images end
item_class()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 16 def item_class EC2Item end
prepare(keyword)
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 20 def prepare keyword Thread.abort_on_exception = true @instances ||= fetch_instances keyword image_ids = @instances.map(&:image_id).uniq @image_thread = Thread.new do @images = fetch_images(image_ids) @id_to_image = @images.map{|i| [i.image_id, i]}.to_h end @sg_thread = Thread.new do @security_groups = fetch_security_groups @id_to_sg = @security_groups.map{|i| [i.group_id, i]}.to_h end @vpc_thread = Thread.new do @vpcs = fetch_vpcs @id_to_vpc = @vpcs.map{|i| [i.vpc_id, i]}.to_h end @items = @instances.map{|i| EC2Item.new(i)} @prepared = true end
security_group_loaded?()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 60 def security_group_loaded? !@sg_thread.alive? end
security_groups()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 64 def security_groups @sg_thread.join if @sg_thread.alive? @security_groups end
vpc_loaded?()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 74 def vpc_loaded? !@vpc_thread.alive? end
vpcs()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 78 def vpcs @vpc_thread.join if @vpc_thread.alive? @vpcs end
Private Instance Methods
ec2_client()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 90 def ec2_client @ec2_client ||= Aws::EC2::Client.new end
fetch_images(image_ids)
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 117 def fetch_images image_ids ec2_client.describe_images(image_ids: image_ids).images.flatten end
fetch_instances(keyword)
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 94 def fetch_instances keyword filter = if keyword.empty? then {} else { filters: [{name: "tag:Name", values: ["*#{keyword}*"]}] } end if config.use_vpc_id_env then if filter.empty? then filter = { filters: [{name: "vpc-id", values: [ENV['VPC_ID']]}] } else filter[:filters].push({name: "vpc-id", values: [ENV['VPC_ID']]}) end end ec2_client.describe_instances(filter).map{ |resp| resp.data.reservations.map do |rsv| rsv.instances end }.flatten end
fetch_security_groups()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 111 def fetch_security_groups ec2_client.describe_security_groups.map{ |resp| resp.security_groups }.flatten end
fetch_vpcs()
click to toggle source
# File lib/eclair/providers/ec2/ec2_provider.rb, line 121 def fetch_vpcs ec2_client.describe_vpcs.map{|resp| resp.vpcs}.flatten end