Sha256: d3d0e4c1d0a6c2b3e89f3e3162326585fe5e310f05439518ac2276dd5bcb28a2

Contents?: true

Size: 1.31 KB

Versions: 12

Compression:

Stored size: 1.31 KB

Contents

module Vagrant
  module LXC
    module Action
      class PrivateNetworks
        def initialize(app, env)
          @app = app
        end

        def call(env)
          @app.call(env)

          if private_network_configured?(env[:machine].config)
            env[:ui].output(I18n.t("vagrant_lxc.messages.setup_private_network"))
            configure_private_networks(env)
          end
        end

        def private_network_configured?(config)
          config.vm.networks.find do |type, _|
            type.to_sym == :private_network
          end
        end

        def configure_private_networks(env)
          env[:machine].config.vm.networks.find do |type, config|
            next if type.to_sym != :private_network

            container_name = env[:machine].provider.driver.container_name
            address_type   = config[:type]
            ip             = config[:ip]
            bridge_ip      = config.fetch(:lxc__bridge_ip) { build_bridge_ip(ip) }
            bridge         = config.fetch(:lxc__bridge_name)

            env[:machine].provider.driver.configure_private_network(bridge, bridge_ip, container_name, address_type, ip)
          end
        end

        def build_bridge_ip(ip)
          if ip
            ip.sub(/^(\d+\.\d+\.\d+)\.\d+/, '\1.254')
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
vagrant-lxc-1.4.3 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.4.2 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.4.1 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-2.1-patch-1.4.0 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.4.0 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.3.1 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.3.0 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.2.4 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.2.3 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.2.2 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.2.1 lib/vagrant-lxc/action/private_networks.rb
vagrant-lxc-1.2.0 lib/vagrant-lxc/action/private_networks.rb