Module: Eclair::EC2Provider

Extended by:
EC2Provider, Provider
Included in:
EC2Provider
Defined in:
lib/eclair/providers/ec2/ec2_provider.rb

Instance Attribute Summary

Attributes included from Provider

#items

Instance Method Summary collapse

Methods included from Provider

filter_items, require_prepare

Instance Method Details

#find_image_by_id(id) ⇒ Object



55
56
57
58
# 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) ⇒ Object



69
70
71
72
# 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) ⇒ Object



83
84
85
86
# 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_classObject



12
13
14
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 12

def group_class
  EC2GroupItem
end

#image_loaded?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 46

def image_loaded?
  !@sg_thread.alive?
end

#imagesObject



50
51
52
53
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 50

def images
  @image_thread.join if @image_thread.alive?
  @images
end

#item_classObject



16
17
18
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 16

def item_class
  EC2Item
end

#prepare(keyword) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 60

def security_group_loaded?
  !@sg_thread.alive?
end

#security_groupsObject



64
65
66
67
# 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?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 74

def vpc_loaded?
  !@vpc_thread.alive?
end

#vpcsObject



78
79
80
81
# File 'lib/eclair/providers/ec2/ec2_provider.rb', line 78

def vpcs
  @vpc_thread.join if @vpc_thread.alive?
  @vpcs
end