diff --git a/example/Vagrantfile b/example/Vagrantfile index b880fe3..47cf9ab 100644 --- a/example/Vagrantfile +++ b/example/Vagrantfile @@ -7,6 +7,8 @@ Vagrant.configure("2") do |config| config.vm.box = "ubuntu-cloud" config.vm.hostname = 'ubuntu-cloud-box' + config.vm.network :private_network, ip: "192.168.33.10" + config.vm.synced_folder "/tmp", "/vagrant_data" config.vm.provider :lxc do |lxc| diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 0e89082..103bd97 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -9,6 +9,7 @@ require 'vagrant-lxc/action/created' require 'vagrant-lxc/action/destroy' require 'vagrant-lxc/action/handle_box_metadata' require 'vagrant-lxc/action/is_running' +require 'vagrant-lxc/action/network' require 'vagrant-lxc/action/share_folders' module Vagrant @@ -192,10 +193,6 @@ module Vagrant # TODO: Check if our requirements are met. class CheckLXC < BaseAction; end - # TODO: Sets up all networking for the container instance. This includes - # host only networks, bridged networking, forwarded ports, etc. - class Network < BaseAction; end - # TODO: Implement port forwarding with rinetd class ForwardPorts < BaseAction; end diff --git a/lib/vagrant-lxc/action/network.rb b/lib/vagrant-lxc/action/network.rb new file mode 100644 index 0000000..1c34651 --- /dev/null +++ b/lib/vagrant-lxc/action/network.rb @@ -0,0 +1,21 @@ +module Vagrant + module LXC + module Action + class Network < BaseAction + def call(env) + # TODO: Validate network configuration prior to anything below + @env = env + + env[:machine].config.vm.networks.each do |type, options| + # We only handle private networks + next if type != :private_network + env[:machine].provider_config.start_opts << "lxc.network.ipv4=#{options[:ip]}/24" + end + + # Continue the middleware chain. + @app.call(env) + end + end + end + end +end