Class: Buildserver::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/buildserver/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, role, ip_address) ⇒ Instance

Returns a new instance of Instance.



8
9
10
11
12
13
# File 'lib/buildserver/instance.rb', line 8

def initialize(hostname, role, ip_address)
  @hostname     = hostname
  @role         = role.to_s
  @ip_address   = ip_address
  @build_blocks = []
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



6
7
8
# File 'lib/buildserver/instance.rb', line 6

def hostname
  @hostname
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



6
7
8
# File 'lib/buildserver/instance.rb', line 6

def ip_address
  @ip_address
end

#roleObject (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/buildserver/instance.rb', line 6

def role
  @role
end

Instance Method Details

#add_build_block(block) ⇒ Object



15
16
17
# File 'lib/buildserver/instance.rb', line 15

def add_build_block(block)
  @build_blocks << block
end

#build(config, instances) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/buildserver/instance.rb', line 39

def build(config, instances)
  @commands       = []
  @after_commands = []

  # Safe bash:
  @commands << "set -eux"
  @commands << "set -o pipefail"

  @build_blocks.each do |build_block|
    @commands << "# ! #{build_block.to_s} -------------------------------------"

    commands, after_commands = build_block.build!(config, self, instances)

    @commands << commands
    @commands << "# / #{build_block.to_s} -------------------------------------"

    @after_commands << after_commands
  end

  @commands << @after_commands

  @commands << "if [ ! -f /root/system_setup_complete ]; then"
  @commands << "echo $(date \"+%Y.%m.%d-%H:%M:%S\") > /root/system_setup_complete"
  @commands << "fi"

  @commands.flatten
end

#external_portsObject



27
28
29
# File 'lib/buildserver/instance.rb', line 27

def external_ports
  @build_blocks.map{|bb| bb.external_ports}.flatten
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/buildserver/instance.rb', line 35

def has_role?(role)
  @role == role.to_s
end

#internal_portsObject



31
32
33
# File 'lib/buildserver/instance.rb', line 31

def internal_ports
  @build_blocks.map{|bb| bb.internal_ports}.flatten
end

#servicesObject



23
24
25
# File 'lib/buildserver/instance.rb', line 23

def services
  @build_blocks.map{|bb| bb.exposes_services}.flatten
end

#to_sObject



19
20
21
# File 'lib/buildserver/instance.rb', line 19

def to_s
  "#{@hostname}/#{@ip_address} - #{@role}"
end