Class: Servitor::ServiceLinker
- Inherits:
-
Object
- Object
- Servitor::ServiceLinker
- Defined in:
- lib/service/service_linker.rb
Instance Attribute Summary collapse
-
#service_box_names ⇒ Object
readonly
Returns the value of attribute service_box_names.
-
#service_nodes ⇒ Object
readonly
Returns the value of attribute service_nodes.
Instance Method Summary collapse
-
#initialize(service_nodes, service_box_names) ⇒ ServiceLinker
constructor
A new instance of ServiceLinker.
-
#link(options = {}) ⇒ Object
Transforms the list of service nodes to a list of services.
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_names ⇒ Object (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_nodes ⇒ Object (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
#link(options = {}) ⇒ Object
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(={}) next_ip = ([:first_ip] || 2).to_i next_port = ([: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, ) begin next_ip += 1 end while ip_address(next_ip, ) == host_ip() 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 = [:vm_root] || '/mnt/app/current' service end end |