Class: Vagrant::Action::VM::DestroyUnusedNetworkInterfaces

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/vm/destroy_unused_network_interfaces.rb

Overview

Destroys the unused host only interfaces. This middleware cleans up any created host only networks.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DestroyUnusedNetworkInterfaces

Returns a new instance of DestroyUnusedNetworkInterfaces.



7
8
9
# File 'lib/vagrant/action/vm/destroy_unused_network_interfaces.rb', line 7

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

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant/action/vm/destroy_unused_network_interfaces.rb', line 11

def call(env)
  # Destroy all the host only network adapters which are empty.
  VirtualBox::Global.global(true).host.network_interfaces.each do |iface|
    # We only care about host only interfaces
    next if iface.interface_type != :host_only

    # Destroy it if there is nothing attached
    if iface.attached_vms.empty?
      env.ui.info I18n.t("vagrant.actions.vm.destroy_network.destroying")
      iface.destroy
    end
  end

  # Continue along
  @app.call(env)
end