Class: Vagrant::LXC::Action::PrivateNetworks

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-lxc/action/private_networks.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrivateNetworks

Returns a new instance of PrivateNetworks.



5
6
7
# File 'lib/vagrant-lxc/action/private_networks.rb', line 5

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

Instance Method Details

#build_bridge_ip(ip) ⇒ Object



38
39
40
41
42
# File 'lib/vagrant-lxc/action/private_networks.rb', line 38

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

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/vagrant-lxc/action/private_networks.rb', line 9

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

#configure_private_networks(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant-lxc/action/private_networks.rb', line 24

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

#private_network_configured?(config) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/vagrant-lxc/action/private_networks.rb', line 18

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