Sha256: 4c7c6be9d117dc62bdad1bc294a5675942a53aa19a86c7b47eae5a977ceb050d

Contents?: true

Size: 1.6 KB

Versions: 17

Compression:

Stored size: 1.6 KB

Contents

require 'log4r'

module VagrantPlugins
  module DockerProvider
    module Action
      class DestroyNetwork

        @@lock = Mutex.new

        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant::plugins::docker::network')
        end

        def call(env)
          # If we are using a host VM, then don't worry about it
          machine = env[:machine]
          if machine.provider.host_vm?
            @logger.debug("Not setting up networks because docker host_vm is in use")
            return @app.call(env)
          end

          @@lock.synchronize do
            machine.env.lock("docker-network-destroy", retry: true) do
              machine.config.vm.networks.each do |type, options|
                next if type != :private_network && type != :public_network

                vagrant_networks = machine.provider.driver.list_network_names.find_all do |n|
                  n.start_with?("vagrant_network")
                end

                vagrant_networks.each do |network_name|
                  if machine.provider.driver.existing_named_network?(network_name) &&
                      !machine.provider.driver.network_used?(network_name)
                    env[:ui].info(I18n.t("docker_provider.network_destroy", network_name: network_name))
                    machine.provider.driver.rm_network(network_name)
                  else
                    @logger.debug("Network #{network_name} not found or in use")
                  end
                end
              end
            end
          end

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/providers/docker/action/destroy_network.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.3.3.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.3.2.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.19.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.18.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.16.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.14.0 plugins/providers/docker/action/destroy_network.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.10.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.9.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.8.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.7.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.6.2 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.6.1 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.6.0 plugins/providers/docker/action/destroy_network.rb
vagrant-unbundled-2.2.5.0 plugins/providers/docker/action/destroy_network.rb