class VagrantPlugins::DockerProvider::Action::ForwardPorts

Public Class Methods

new(app, env) click to toggle source
# File lib/docker-provider/action/forward_ports.rb, line 5
def initialize(app, env)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/docker-provider/action/forward_ports.rb, line 9
def call(env)
  @env = env

  env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config)

  if env[:forwarded_ports].any?
    env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
    inform_forwarded_ports(env[:forwarded_ports])
  end

  # FIXME: Check whether the container has already been created with
  #        different exposed ports and let the user know about it

  @app.call env
end
inform_forwarded_ports(ports) click to toggle source
# File lib/docker-provider/action/forward_ports.rb, line 25
def inform_forwarded_ports(ports)
  ports.each do |fp|
    message_attributes = {
      :adapter    => 'eth0',
      :guest_port => fp[:guest],
      :host_port  => fp[:host]
    }

    @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
                          message_attributes))
  end
end

Private Instance Methods

compile_forwarded_ports(config) click to toggle source
# File lib/docker-provider/action/forward_ports.rb, line 40
def compile_forwarded_ports(config)
  mappings = {}

  config.vm.networks.each do |type, options|
    if type == :forwarded_port && options[:id] != 'ssh'
      mappings[options[:host]] = options
    end
  end

  mappings.values
end