Sha256: f3c7c6e8172fcd54d0db5d59f15b3937d6eda3a5ec0d64071c33b86cc201acc1

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Vagrant
  class Action
    module VM
      # Destroys the unused host only interfaces. This middleware cleans
      # up any created host only networks.
      class DestroyUnusedNetworkInterfaces
        def initialize(app, env)
          @app = app
        end

        def call(env)
          # We need to check if the host only network specified by any
          # of the adapters would not have any more clients if it was
          # destroyed. And if so, then destroy the host only network
          # itself.
          interfaces = env["vm"].vm.network_adapters.collect do |adapter|
            adapter.host_interface_object
          end

          interfaces.compact.uniq.each do |interface|
            # Destroy the network interface if there is only one
            # attached VM (which must be this VM)
            if interface.attached_vms.length == 1
              env.logger.info "Destroying unused network interface..."
              interface.destroy
            end
          end

          # Continue along
          @app.call(env)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
vagrantup-0.5.4 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrantup-0.5.3 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrantup-0.5.2 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrantup-0.5.1 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrantup-0.5.0 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrant-0.5.4 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrant-0.5.3 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrant-0.5.2 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrant-0.5.1 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb
vagrant-0.5.0 lib/vagrant/action/vm/destroy_unused_network_interfaces.rb