Module: Eclair::Aws

Extended by:
Aws
Included in:
Aws
Defined in:
lib/eclair/helpers/aws_helper.rb

Instance Method Summary collapse

Instance Method Details

#dns_records(**options) ⇒ Object



33
34
35
36
37
38
# File 'lib/eclair/helpers/aws_helper.rb', line 33

def dns_records **options
  if options.delete :force
    @route53_thread.join
  end
  @dns_records || []
end

#dns_records?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/eclair/helpers/aws_helper.rb', line 40

def dns_records?
  !@route53_thread.alive?
end

#ec2Object



5
6
7
# File 'lib/eclair/helpers/aws_helper.rb', line 5

def ec2
  @ec2 ||= ::Aws::EC2::Client.new
end

#images(**options) ⇒ Object



22
23
24
25
26
27
# File 'lib/eclair/helpers/aws_helper.rb', line 22

def images **options
  if options.delete :force
    @images_thread.join
  end
  @images || []
end

#images?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/eclair/helpers/aws_helper.rb', line 29

def images?
  !@images_thread.alive?
end

#instance_mapObject



18
19
20
# File 'lib/eclair/helpers/aws_helper.rb', line 18

def instance_map
  @instance_map
end

#instancesObject



13
14
15
16
# File 'lib/eclair/helpers/aws_helper.rb', line 13

def instances
  fetch_all unless @instances
  @instances
end

#reload_instancesObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/eclair/helpers/aws_helper.rb', line 55

def reload_instances
  return if @reload_thread && @reload_thread.alive?

  if @reload_thread
    @instances = @r_instances
    @instance_map = @r_instances_map
    @images += @new_images
    @dns_records = @r_dns_records
    @security_groups = @r_security_groups
    Grid.assign
    @reload_thread = nil
  end

  return if @last_reloaded && Time.now - @last_reloaded < 5

  @reload_thread = Thread.new do 
    r_instances, r_instances_map = fetch_instances
    @new_instances = r_instances.map(&:instance_id) - @instances.map(&:instance_id)
    if new_instances.empty?
      @new_images = []
    else
      image_ids = @new_instances.map(&:image_id)
      [
        Thread.new do
          @new_images = fetch_images(image_ids)
        end,

        Thread.new do
          @r_security_groups = fetch_security_groups
        end
      ].each(&:join)
    end
    @last_reloaded = Time.now
  end
end

#route53Object



9
10
11
# File 'lib/eclair/helpers/aws_helper.rb', line 9

def route53
  @route53 ||= ::Aws::Route53::Client.new
end

#security_groups(**options) ⇒ Object



44
45
46
47
48
49
# File 'lib/eclair/helpers/aws_helper.rb', line 44

def security_groups **options
  if options.delete :force
    @security_groups_thread.join
  end
  @security_groups || []
end

#security_groups?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/eclair/helpers/aws_helper.rb', line 51

def security_groups?
  !@security_groups_thread.alive?
end