Class: VagrantPlugins::ProviderLibvirt::Action::ClearForwardedPorts

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-libvirt/action/forward_ports.rb

Overview

Cleans up ssh-forwarded ports on VM halt/destroy.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ClearForwardedPorts

Returns a new instance of ClearForwardedPorts.



122
123
124
125
126
127
# File 'lib/vagrant-libvirt/action/forward_ports.rb', line 122

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new(
    'vagrant_libvirt::action::clear_forward_ports'
  )
end

Instance Method Details

#call(env) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/vagrant-libvirt/action/forward_ports.rb', line 129

def call(env)
  @env = env

  if ssh_pids.any?
    env[:ui].info I18n.t(
      'vagrant.actions.vm.clear_forward_ports.deleting'
    )
    ssh_pids.each do |pid|
      next unless ssh_pid?(pid)
      @logger.debug "Killing pid #{pid}"
      system "kill #{pid}"
    end

    @logger.info 'Removing ssh pid files'
    remove_ssh_pids
  else
    @logger.info 'No ssh pids found'
  end

  @app.call env
end