Class: Kelbim::DSL::EC2::LoadBalancer

Inherits:
Object
  • Object
show all
Includes:
Checker, TemplateHelper
Defined in:
lib/kelbim/dsl/listener.rb,
lib/kelbim/dsl/listeners.rb,
lib/kelbim/dsl/attributes.rb,
lib/kelbim/dsl/health-check.rb,
lib/kelbim/dsl/load-balancer.rb

Defined Under Namespace

Classes: Attributes, HealthCheck, Listeners

Instance Method Summary collapse

Methods included from TemplateHelper

#context, #include_template

Constructor Details

#initialize(context, name, vpc, internal, &block) ⇒ LoadBalancer

Returns a new instance of LoadBalancer.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kelbim/dsl/load-balancer.rb', line 8

def initialize(context, name, vpc, internal, &block)
  @name = name
  @vpc = vpc
  @error_identifier = "LoadBalancer `#{name}`"
  @context = context.merge(:load_balancer_name => name)

  @result = OpenStruct.new({
    :name      => name,
    :instances => [],
    :internal  => internal,
    :scheme    => internal ? 'internal' : 'internet-facing',
  })

  instance_eval(&block)
end

Instance Method Details

#any_instancesObject



54
55
56
57
# File 'lib/kelbim/dsl/load-balancer.rb', line 54

def any_instances
  call_once(:instances)
  @result.any_instances = true
end

#attributes(&block) ⇒ Object



69
70
71
72
# File 'lib/kelbim/dsl/load-balancer.rb', line 69

def attributes(&block)
  call_once(:attributes)
  @result.attributes = Attributes.new(@context, @name, &block).result
end

#availability_zones(*values) ⇒ Object



86
87
88
89
90
# File 'lib/kelbim/dsl/load-balancer.rb', line 86

def availability_zones(*values)
  call_once(:availability_zone)
  raise "#{@error_identifier}: SecurityGroup cannot be specified in EC2-VPC" if @vpc
  @result.availability_zones = values
end

#health_check(&block) ⇒ Object



64
65
66
67
# File 'lib/kelbim/dsl/load-balancer.rb', line 64

def health_check(&block)
  call_once(:health_check)
  @result.health_check = HealthCheck.new(@context, @name, &block).result
end

#instances(*values) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/kelbim/dsl/load-balancer.rb', line 44

def instances(*values)
  call_once(:instances)

  values.each do |instance_id_or_name|
    instance_id = instance_id_or_name
    not_include(instance_id_or_name, @result.instances)
    @result.instances << instance_id
  end
end

#listeners(&block) ⇒ Object



59
60
61
62
# File 'lib/kelbim/dsl/load-balancer.rb', line 59

def listeners(&block)
  call_once(:listeners)
  @result.listeners = Listeners.new(@context, @name, &block).result
end

#resultObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kelbim/dsl/load-balancer.rb', line 24

def result
  required(:listeners, @result.listeners)
  required(:health_check, @result.health_check)
  #required(:attributes, @result.attributes)

  if @vpc
    required(:subnets, @result.subnets)
    required(:security_groups, @result.security_groups)
  else
    required(:availability_zones, @result.availability_zones)
  end

  @result
end

#security_groups(*values) ⇒ Object



80
81
82
83
84
# File 'lib/kelbim/dsl/load-balancer.rb', line 80

def security_groups(*values)
  call_once(:security_groups)
  raise "#{@error_identifier}: SecurityGroup cannot be specified in EC2-Classic" unless @vpc
  @result.security_groups = values
end

#spec(&block) ⇒ Object



39
40
41
42
# File 'lib/kelbim/dsl/load-balancer.rb', line 39

def spec(&block)
  call_once(:spec)
  @result.spec = block
end

#subnets(*values) ⇒ Object



74
75
76
77
78
# File 'lib/kelbim/dsl/load-balancer.rb', line 74

def subnets(*values)
  call_once(:subnets)
  raise "#{@error_identifier}: Subnet cannot be specified in EC2-Classic" unless @vpc
  @result.subnets = values
end