[DRE-commits] [vagrant-libvirt] 65/104: Initial implementation of public_network support.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Apr 24 13:55:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag 0.0.11
in repository vagrant-libvirt.

commit 89338425176ed4b637bbdb69ec7fcceec7d71342
Author: Nick Downs <nickryand at gmail.com>
Date:   Tue Sep 10 00:12:24 2013 -0700

    Initial implementation of public_network support.
---
 README.md                                          | 23 ++++++++++++++++--
 .../action/create_network_interfaces.rb            | 28 ++++++++++------------
 .../templates/public_interface.xml.erb             |  4 ++++
 3 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/README.md b/README.md
index bff80a9..3450c47 100644
--- a/README.md
+++ b/README.md
@@ -152,15 +152,26 @@ Vagrant goes through steps below when creating new project:
 ## Networks
 
 Networking features in the form of `config.vm.network` support private networks
-concept. No public network or port forwarding are supported in current version
-of provider.
+concept. Port Forwarding is currently not supported.
+
+Public Network interfaces are currently implemented using the macvtap driver. The macvtap
+driver is only available with the Linux Kernel version >= 2.6.24. See the following libvirt
+documentation for the details of the macvtap usage.
+
+http://www.libvirt.org/formatdomain.html#elementsNICSDirect
 
 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",
   end
+
+  # Public Network
+  config.vm.define :test_vm1 do |test_vm1|
+    test_vm1.vm.network :public_network, :dev => "eth0", :mode => 'bridge'
+  end
 ```
 
 In example below, one network interface is configured for VM test_vm1. After
@@ -174,8 +185,16 @@ created networks are NATed to outside world, so your VM will be able to connect
 to the internet (if hypervisor can). And by default, DHCP is offering addresses
 on newly created networks.
 
+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.
+
 ### Private Network Options
 
+*Note: These options are not applicable to public network interfaces.*
+
 There is a way to pass specific options for libvirt provider when using
 `config.vm.network` to configure new network interface. Each parameter name
 starts with 'libvirt__' string. Here is a list of those options:
diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb
index 9cf27d0..3fbdebe 100644
--- a/lib/vagrant-libvirt/action/create_network_interfaces.rb
+++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb
@@ -32,28 +32,16 @@ module VagrantPlugins
           # Setup list of interfaces before creating them.
           adapters = []
 
-          # Assign main interface for provisioning to first slot.
-          # Use network 'default' as network for ssh connecting and
-          # machine provisioning.
-          #
-          # TODO Network name with DHCP for first interface should be
-          # configurable.
-          adapters[0] = {
-            :network_name => 'default'
-          }
+          # Vagrant gives you adapter 0 by default
 
           # Assign interfaces to slots.
           env[:machine].config.vm.networks.each do |type, options|
-            # Only private network is supported now. Port forwarding and public
-            # network are not supported via libvirt API, so they are not
-            # implemented in this provider.
-            next if type != :private_network
 
             # Get options for this interface. Options can be specified in
             # Vagrantfile in short format (:ip => ...), or provider format
             # (:libvirt__network_name => ...).
             options = scoped_hash_override(options, :libvirt)
-            options = { :netmask => '255.255.255.0' }.merge(options)
+            options = { :netmask => '255.255.255.0', :iface_type => type }.merge(options)
 
             # TODO fill first ifaces with adapter option specified.
             if options[:adapter]
@@ -63,7 +51,7 @@ module VagrantPlugins
 
               free_slot = options[:adapter].to_i
             else
-              free_slot = find_empty(adapters, start=1)
+              free_slot = find_empty(adapters)
               raise Errors::InterfaceSlotNotAvailable if free_slot == nil
             end
 
@@ -77,13 +65,21 @@ module VagrantPlugins
           adapters.each_with_index do |iface_configuration, slot_number|
             @iface_number = slot_number
             @network_name = iface_configuration[:network_name]
+            template_name = 'interface'
+
+            # Configuration for public interfaces which use the macvtap driver
+            if iface_configuration[:iface_type] == :public_network
+              template_name = 'public_interface'
+              @device = iface_configuration[:dev]
+              @mode = iface_configuration[:mode]
+            end
 
             message = "Creating network interface eth#{@iface_number}"
             message << " connected to network #{@network_name}."
             @logger.info(message)
 
             begin
-              domain.attach_device(to_xml('interface'))
+              domain.attach_device(to_xml(template_name))
             rescue => e
               raise Errors::AttachDeviceError,
                 :error_message => e.message
diff --git a/lib/vagrant-libvirt/templates/public_interface.xml.erb b/lib/vagrant-libvirt/templates/public_interface.xml.erb
new file mode 100644
index 0000000..fe5d65e
--- /dev/null
+++ b/lib/vagrant-libvirt/templates/public_interface.xml.erb
@@ -0,0 +1,4 @@
+<interface type='direct'>
+  <source dev='<%= @device %>' mode='<%= @mode %>'/>
+</interface>
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git



More information about the Pkg-ruby-extras-commits mailing list