Class: Vagrant::Serial::Middleware::ConfigurePorts

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-serial/middleware/configure_ports.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ConfigurePorts

Returns a new instance of ConfigurePorts.



5
6
7
# File 'lib/vagrant-serial/middleware/configure_ports.rb', line 5

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-serial/middleware/configure_ports.rb', line 9

def call(env)
  if env[:vm].config.serial.set?
    FileUtils.mkdir_p(env[:vm].config.serial.sockets_path) if !File.directory?(env[:vm].config.serial.sockets_path)

    env[:ui].info "Setting up serial ports..."
    if env[:vm].config.serial.forward_com1
      command = ["modifyvm", env[:vm].uuid, "--uart1", "0x3F8", "4", "--uartmode1", "server", "#{env[:vm].config.serial.sockets_path}/#{env[:vm].uuid}-com1"]
      env[:vm].driver.execute_command(command)
    end

    if env[:vm].config.serial.forward_com2
      command = ["modifyvm", env[:vm].uuid, "--uart2", "0x2F8", "3", "--uartmode2", "server", "#{env[:vm].config.serial.sockets_path}/#{env[:vm].uuid}-com2"]
      env[:vm].driver.execute_command(command)
    end
  end

  @app.call(env)
end