Class: Servitor::ServiceLinker

Inherits:
Object
  • Object
show all
Defined in:
lib/service/service_linker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_nodes, service_box_names) ⇒ ServiceLinker

Returns a new instance of ServiceLinker.



6
7
8
9
# File 'lib/service/service_linker.rb', line 6

def initialize(service_nodes, service_box_names)
  @service_nodes = service_nodes
  @service_box_names = service_box_names
end

Instance Attribute Details

#service_box_namesObject (readonly)

Returns the value of attribute service_box_names.



4
5
6
# File 'lib/service/service_linker.rb', line 4

def service_box_names
  @service_box_names
end

#service_nodesObject (readonly)

Returns the value of attribute service_nodes.



4
5
6
# File 'lib/service/service_linker.rb', line 4

def service_nodes
  @service_nodes
end

Instance Method Details

Transforms the list of service nodes to a list of services. Service nodes describe the requirements and dependencies of each app, while services describe the VMs that satisfy those requirements and dependencies.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/service/service_linker.rb', line 14

def link(options={})
  next_ip = (options[:first_ip] || 2).to_i
  next_port = (options[:first_port] || 3000).to_i
  @service_nodes.map do |service_node|
    service = Service.new
    service.service_node = service_node
    service.name = service_node.service_definition.name
    service.box = @service_box_names[service_node]
    service.ip_address = ip_address(next_ip, options)
    begin
      next_ip += 1
    end while ip_address(next_ip, options) == host_ip(options)
    service.forwarded_ports = { 80 => next_port }.merge(ports_for(service_node))
    next_port += 1
    service.root = service_node.service_definition.service_root
    service.vm_root = options[:vm_root] || '/mnt/app/current'
    service
  end
end