diff --git a/README.md b/README.md index b71fe1c..f48007a 100644 --- a/README.md +++ b/README.md @@ -167,12 +167,12 @@ An examples of network interface definitions: ```ruby # Private network config.vm.define :test_vm1 do |test_vm1| - test_vm1.vm.network :private_network, :ip => "10.20.30.40", + test_vm1.vm.network :private_network, :ip => "10.20.30.40" end # Public Network config.vm.define :test_vm1 do |test_vm1| - test_vm1.vm.network :public_network, :dev => "eth0", :mode => 'bridge', :mac => '92-c6-8f-94-b5-8d' + test_vm1.vm.network :public_network, :dev => "eth0", :mode => 'bridge' end ``` @@ -191,7 +191,7 @@ The second interface is created and bridged into the physical device 'eth0'. This mechanism uses the macvtap Kernel driver and therefore does not require an existing bridge device. This configuration assumes that DHCP and DNS services are being provided by the public network. This public interface should be reachable -by anyone with access to the public network. If `:mac` is not defined it will be generated. +by anyone with access to the public network. ### Private Network Options @@ -217,12 +217,14 @@ starts with 'libvirt__' string. Here is a list of those options: * `:libvirt__forward_device` - Name of interface/device, where network should be forwarded (NATed or routed). Used only when creating new network. By default, all physical interfaces are used. +* `:mac` - MAC address for the interface. ### Public Network Options * `:dev` - Physical device that the public interface should use. Default is 'eth0' * `:mode` - The mode in which the public interface should operate in. Supported modes are available from the [libvirt documentation](http://www.libvirt.org/formatdomain.html#elementsNICSDirect). Default mode is 'bridge'. +* `:mac` - MAC address for the interface. ## Obtaining Domain IP Address diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index 87eb6b8..1f69f51 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -65,6 +65,7 @@ module VagrantPlugins adapters.each_with_index do |iface_configuration, slot_number| @iface_number = slot_number @network_name = iface_configuration[:network_name] + @mac = iface_configuration.fetch(:mac, false) template_name = 'interface' # Configuration for public interfaces which use the macvtap driver @@ -72,12 +73,14 @@ module VagrantPlugins template_name = 'public_interface' @device = iface_configuration.fetch(:dev, 'eth0') @mode = iface_configuration.fetch(:mode, 'bridge') - @mac = iface_configuration.fetch(:mac, false) @logger.info("Setting up public interface using device #{@device} in mode #{@mode}") end message = "Creating network interface eth#{@iface_number}" message << " connected to network #{@network_name}." + if @mac + message << "Using MAC address: #{@mac}" + end @logger.info(message) begin diff --git a/lib/vagrant-libvirt/templates/interface.xml.erb b/lib/vagrant-libvirt/templates/interface.xml.erb index 4e203b0..616c9a4 100644 --- a/lib/vagrant-libvirt/templates/interface.xml.erb +++ b/lib/vagrant-libvirt/templates/interface.xml.erb @@ -1,8 +1,8 @@ - <% if @mac %> + <% if @mac %> - <% end %> + <% end %> diff --git a/lib/vagrant-libvirt/templates/public_interface.xml.erb b/lib/vagrant-libvirt/templates/public_interface.xml.erb index fe5d65e..d4a7fbf 100644 --- a/lib/vagrant-libvirt/templates/public_interface.xml.erb +++ b/lib/vagrant-libvirt/templates/public_interface.xml.erb @@ -1,4 +1,7 @@ + <% if @mac %> + + <% end %>