Sha256: 2854aac6838d1aa55e648ac0b03142e81008b1690766de1c3322406199d42908

Contents?: true

Size: 1.67 KB

Versions: 63

Compression:

Stored size: 1.67 KB

Contents

module VagrantPlugins
  module DockerProvider
    module Action
      class PrepareNFSSettings
        include Vagrant::Util::Retryable

        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::action::vm::nfs")
        end

        def call(env)
          @machine = env[:machine]

          @app.call(env)

          if using_nfs? && !privileged_container?
            raise Errors::NfsWithoutPrivilegedError
          end

          if using_nfs?
            @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
            add_ips_to_env!(env)
          end
        end

        # We're using NFS if we have any synced folder with NFS configured. If
        # we are not using NFS we don't need to do the extra work to
        # populate these fields in the environment.
        def using_nfs?
          @machine.config.vm.synced_folders.any? { |_, opts| opts[:type] == :nfs }
        end

        def privileged_container?
          @machine.provider.driver.privileged?(@machine.id)
        end

        # Extracts the proper host and guest IPs for NFS mounts and stores them
        # in the environment for the SyncedFolder action to use them in
        # mounting.
        #
        # The ! indicates that this method modifies its argument.
        def add_ips_to_env!(env)
          provider = env[:machine].provider

          host_ip    = provider.driver.docker_bridge_ip
          machine_ip = provider.ssh_info[:host]

          raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip

          env[:nfs_host_ip]    = host_ip
          env[:nfs_machine_ip] = machine_ip
        end
      end
    end
  end
end

Version data entries

63 entries across 56 versions & 8 rubygems

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