From 527e06c6906d8353617b39267d94e1f2be47d5d4 Mon Sep 17 00:00:00 2001 From: Marcus Young Date: Tue, 21 Jan 2014 11:04:28 -0600 Subject: [PATCH 1/3] Adding support for gateway in RHEL/CentOS ifcfg script --- templates/guests/redhat/network_static.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/guests/redhat/network_static.erb b/templates/guests/redhat/network_static.erb index c28dd74cb..3f2a8b60a 100644 --- a/templates/guests/redhat/network_static.erb +++ b/templates/guests/redhat/network_static.erb @@ -6,5 +6,6 @@ ONBOOT=yes IPADDR=<%= options[:ip] %> NETMASK=<%= options[:netmask] %> DEVICE=eth<%= options[:interface] %> +<%= options[:gateway] ? "GATEWAY=#{options[:gateway]}" : '' %> PEERDNS=no #VAGRANT-END From 55e4308e226bf3bb2995e4c2b35becfd383333b6 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Fri, 15 May 2015 12:54:57 -0400 Subject: [PATCH 2/3] Add gateway to networks + template tests --- templates/guests/arch/network_static.erb | 3 + templates/guests/debian/network_static.erb | 3 + templates/guests/fedora/network_static.erb | 8 +- templates/guests/freebsd/network_static.erb | 3 + templates/guests/funtoo/network_static.erb | 6 +- templates/guests/gentoo/network_static.erb | 3 + templates/guests/redhat/network_static.erb | 4 +- templates/guests/suse/network_static.erb | 5 +- .../guests/arch/network_dhcp_test.rb | 19 +++ .../guests/arch/network_static_test.rb | 37 +++++ .../guests/debian/network_dhcp_test.rb | 41 +++++ .../guests/debian/network_static_test.rb | 43 ++++++ .../guests/fedora/network_dhcp_test.rb | 21 +++ .../guests/fedora/network_static_test.rb | 71 +++++++++ .../guests/freebsd/network_dhcp_test.rb | 16 ++ .../guests/freebsd/network_static_test.rb | 39 +++++ .../guests/funtoo/network_dhcp_test.rb | 19 +++ .../guests/funtoo/network_static_test.rb | 141 ++++++++++++++++++ .../guests/gentoo/network_dhcp_test.rb | 19 +++ .../guests/gentoo/network_static_test.rb | 37 +++++ .../guests/netbsd/network_dhcp_test.rb | 18 +++ .../guests/netbsd/network_static_test.rb | 20 +++ .../guests/redhat/network_dhcp_test.rb | 21 +++ .../guests/redhat/network_static_test.rb | 49 ++++++ .../guests/suse/network_dhcp_test.rb | 21 +++ .../guests/suse/network_static_test.rb | 49 ++++++ .../v2/networking/private_network.html.md | 3 + 27 files changed, 714 insertions(+), 5 deletions(-) create mode 100644 test/unit/templates/guests/arch/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/arch/network_static_test.rb create mode 100644 test/unit/templates/guests/debian/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/debian/network_static_test.rb create mode 100644 test/unit/templates/guests/fedora/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/fedora/network_static_test.rb create mode 100644 test/unit/templates/guests/freebsd/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/freebsd/network_static_test.rb create mode 100644 test/unit/templates/guests/funtoo/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/funtoo/network_static_test.rb create mode 100644 test/unit/templates/guests/gentoo/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/gentoo/network_static_test.rb create mode 100644 test/unit/templates/guests/netbsd/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/netbsd/network_static_test.rb create mode 100644 test/unit/templates/guests/redhat/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/redhat/network_static_test.rb create mode 100644 test/unit/templates/guests/suse/network_dhcp_test.rb create mode 100644 test/unit/templates/guests/suse/network_static_test.rb diff --git a/templates/guests/arch/network_static.erb b/templates/guests/arch/network_static.erb index ee58ee75a..f8cb06f1b 100644 --- a/templates/guests/arch/network_static.erb +++ b/templates/guests/arch/network_static.erb @@ -3,3 +3,6 @@ Description='A basic static ethernet connection' Interface=<%= options[:device] %> IP=static Address=('<%= options[:ip]%>/24') +<% if options[:gateway] %> +Gateway='<%= options[:gateway] %>' +<% end %> diff --git a/templates/guests/debian/network_static.erb b/templates/guests/debian/network_static.erb index fa505afa9..91f0cd62e 100644 --- a/templates/guests/debian/network_static.erb +++ b/templates/guests/debian/network_static.erb @@ -4,4 +4,7 @@ auto eth<%= options[:interface] %> iface eth<%= options[:interface] %> inet static address <%= options[:ip] %> netmask <%= options[:netmask] %> +<% if options[:gateway] %> + gateway <%= options[:gateway] %> +<% end %> #VAGRANT-END diff --git a/templates/guests/fedora/network_static.erb b/templates/guests/fedora/network_static.erb index dc8e85c1e..000ea6150 100644 --- a/templates/guests/fedora/network_static.erb +++ b/templates/guests/fedora/network_static.erb @@ -6,7 +6,11 @@ ONBOOT=yes IPADDR=<%= options[:ip] %> NETMASK=<%= options[:netmask] %> DEVICE=<%= options[:device] %> -<%= options[:gateway] ? "GATEWAY=#{options[:gateway]}" : '' %> -<%= options[:mac_address] ? "HWADDR=#{options[:mac_address]}" : '' %> +<% if options[:gateway] %> +GATEWAY=<%= options[:gateway] %> +<% end %> +<% if options[:mac_address] %> +HWADDR=<%= options[:mac_address] %> +<% end %> PEERDNS=no #VAGRANT-END diff --git a/templates/guests/freebsd/network_static.erb b/templates/guests/freebsd/network_static.erb index 0edc518cb..e73c7c124 100644 --- a/templates/guests/freebsd/network_static.erb +++ b/templates/guests/freebsd/network_static.erb @@ -1,3 +1,6 @@ #VAGRANT-BEGIN ifconfig_<%= ifname %>="inet <%= options[:ip] %> netmask <%= options[:netmask] %>" +<% if options[:gateway] %> +default_router="<%= options[:gateway] %>" +<% end %> #VAGRANT-END diff --git a/templates/guests/funtoo/network_static.erb b/templates/guests/funtoo/network_static.erb index ab6a09d10..001df7419 100644 --- a/templates/guests/funtoo/network_static.erb +++ b/templates/guests/funtoo/network_static.erb @@ -2,5 +2,9 @@ # The contents below are automatically generated by Vagrant. Do not modify. template='interface' ipaddr='<%= options[:ip] %>/<%= options[:netmask] %>' -<%= [:gateway, :nameservers, :domain, :route, :gateway6, :route6, :mtu].reduce([]) { |a,i| a.push("#{i}=#{options[i]}") if options[i]; a }.join("\n") %> +<% [:gateway, :nameservers, :domain, :route, :gateway6, :route6, :mtu].each do |key| %> +<% if options[key] %> +<%= key %>='<%= options[key] %>' +<% end %> +<% end %> #VAGRANT-END diff --git a/templates/guests/gentoo/network_static.erb b/templates/guests/gentoo/network_static.erb index 0df432cb0..fe6c77194 100644 --- a/templates/guests/gentoo/network_static.erb +++ b/templates/guests/gentoo/network_static.erb @@ -1,4 +1,7 @@ #VAGRANT-BEGIN # The contents below are automatically generated by Vagrant. Do not modify. config_eth<%= options[:interface] %>=("<%= options[:ip] %> netmask <%= options[:netmask] %>") +<% if options[:gateway] %> +gateways_eth<%= options[:interface] %>="<%= options[:gateway] %>" +<% end %> #VAGRANT-END diff --git a/templates/guests/redhat/network_static.erb b/templates/guests/redhat/network_static.erb index 3f2a8b60a..53ef59571 100644 --- a/templates/guests/redhat/network_static.erb +++ b/templates/guests/redhat/network_static.erb @@ -6,6 +6,8 @@ ONBOOT=yes IPADDR=<%= options[:ip] %> NETMASK=<%= options[:netmask] %> DEVICE=eth<%= options[:interface] %> -<%= options[:gateway] ? "GATEWAY=#{options[:gateway]}" : '' %> +<% if options[:gateway] %> +GATEWAY=<%= options[:gateway] %> +<% end %> PEERDNS=no #VAGRANT-END diff --git a/templates/guests/suse/network_static.erb b/templates/guests/suse/network_static.erb index 7388fc355..c9270d7cd 100644 --- a/templates/guests/suse/network_static.erb +++ b/templates/guests/suse/network_static.erb @@ -4,7 +4,10 @@ BOOTPROTO='static' IPADDR='<%= options[:ip] %>' NETMASK='<%= options[:netmask] %>' DEVICE='eth<%= options[:interface] %>' -PEERDNS=no +<% if options[:gateway] %> +GATEWAY='<%= options[:gateway] %>' +<% end %> +PEERDNS='no' STARTMODE='auto' USERCONTROL='no' #VAGRANT-END diff --git a/test/unit/templates/guests/arch/network_dhcp_test.rb b/test/unit/templates/guests/arch/network_dhcp_test.rb new file mode 100644 index 000000000..10a3f2c7d --- /dev/null +++ b/test/unit/templates/guests/arch/network_dhcp_test.rb @@ -0,0 +1,19 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/arch/network_dhcp" do + let(:template) { "guests/arch/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + Description='A basic dhcp ethernet connection' + Interface=en0 + Connection=ethernet + IP=dhcp + EOH + end +end diff --git a/test/unit/templates/guests/arch/network_static_test.rb b/test/unit/templates/guests/arch/network_static_test.rb new file mode 100644 index 000000000..375ec67c5 --- /dev/null +++ b/test/unit/templates/guests/arch/network_static_test.rb @@ -0,0 +1,37 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/arch/network_static" do + let(:template) { "guests/arch/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + Connection=ethernet + Description='A basic static ethernet connection' + Interface=en0 + IP=static + Address=('1.1.1.1/24') + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + gateway: "1.2.3.4", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + Connection=ethernet + Description='A basic static ethernet connection' + Interface=en0 + IP=static + Address=('1.1.1.1/24') + Gateway='1.2.3.4' + EOH + end +end diff --git a/test/unit/templates/guests/debian/network_dhcp_test.rb b/test/unit/templates/guests/debian/network_dhcp_test.rb new file mode 100644 index 000000000..766227461 --- /dev/null +++ b/test/unit/templates/guests/debian/network_dhcp_test.rb @@ -0,0 +1,41 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/debian/network_dhcp" do + let(:template) { "guests/debian/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + auto eth + iface eth inet dhcp + post-up route del default dev $IFACE || true + #VAGRANT-END + EOH + end + + context "when use_dhcp_assigned_default_route is set" do + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + use_dhcp_assigned_default_route: true, + }) + expect(result).to eq <<-EOH.gsub(/^ {8}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + auto eth + iface eth inet dhcp + # We need to disable eth0, see GH-2648 + post-up route del default dev eth0 + post-up dhclient $IFACE + pre-down route add default dev eth0 + #VAGRANT-END + EOH + end + end +end diff --git a/test/unit/templates/guests/debian/network_static_test.rb b/test/unit/templates/guests/debian/network_static_test.rb new file mode 100644 index 000000000..936a6a806 --- /dev/null +++ b/test/unit/templates/guests/debian/network_static_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/debian/network_static" do + let(:template) { "guests/debian/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + auto eth + iface eth inet static + address 1.1.1.1 + netmask 255.255.0.0 + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + gateway: "1.2.3.4", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + auto eth + iface eth inet static + address 1.1.1.1 + netmask 255.255.0.0 + gateway 1.2.3.4 + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/fedora/network_dhcp_test.rb b/test/unit/templates/guests/fedora/network_dhcp_test.rb new file mode 100644 index 000000000..b257aa76e --- /dev/null +++ b/test/unit/templates/guests/fedora/network_dhcp_test.rb @@ -0,0 +1,21 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/fedora/network_dhcp" do + let(:template) { "guests/fedora/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + BOOTPROTO=dhcp + ONBOOT=yes + DEVICE=en0 + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/fedora/network_static_test.rb b/test/unit/templates/guests/fedora/network_static_test.rb new file mode 100644 index 000000000..f6e879fa2 --- /dev/null +++ b/test/unit/templates/guests/fedora/network_static_test.rb @@ -0,0 +1,71 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/fedora/network_static" do + let(:template) { "guests/fedora/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + NM_CONTROLLED=no + BOOTPROTO=none + ONBOOT=yes + IPADDR=1.1.1.1 + NETMASK=255.255.0.0 + DEVICE=en0 + PEERDNS=no + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + gateway: "1.2.3.4", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + NM_CONTROLLED=no + BOOTPROTO=none + ONBOOT=yes + IPADDR=1.1.1.1 + NETMASK=255.255.0.0 + DEVICE=en0 + GATEWAY=1.2.3.4 + PEERDNS=no + #VAGRANT-END + EOH + end + + it "includes the mac_address" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + mac_address: "abcd1234", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + NM_CONTROLLED=no + BOOTPROTO=none + ONBOOT=yes + IPADDR=1.1.1.1 + NETMASK=255.255.0.0 + DEVICE=en0 + HWADDR=abcd1234 + PEERDNS=no + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/freebsd/network_dhcp_test.rb b/test/unit/templates/guests/freebsd/network_dhcp_test.rb new file mode 100644 index 000000000..322de3746 --- /dev/null +++ b/test/unit/templates/guests/freebsd/network_dhcp_test.rb @@ -0,0 +1,16 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/freebsd/network_dhcp" do + let(:template) { "guests/freebsd/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, ifname: "vtneten0") + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + ifconfig_vtneten0="DHCP" + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/freebsd/network_static_test.rb b/test/unit/templates/guests/freebsd/network_static_test.rb new file mode 100644 index 000000000..ca9eb0153 --- /dev/null +++ b/test/unit/templates/guests/freebsd/network_static_test.rb @@ -0,0 +1,39 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/freebsd/network_static" do + let(:template) { "guests/freebsd/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, + ifname: "vtneten0", + options: { + ip: "1.1.1.1", + netmask: "255.255.0.0", + }, + ) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + ifconfig_vtneten0="inet 1.1.1.1 netmask 255.255.0.0" + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, + ifname: "vtneten0", + options: { + ip: "1.1.1.1", + netmask: "255.255.0.0", + gateway: "1.2.3.4", + }, + ) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + ifconfig_vtneten0="inet 1.1.1.1 netmask 255.255.0.0" + default_router="1.2.3.4" + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/funtoo/network_dhcp_test.rb b/test/unit/templates/guests/funtoo/network_dhcp_test.rb new file mode 100644 index 000000000..0e3cafb1c --- /dev/null +++ b/test/unit/templates/guests/funtoo/network_dhcp_test.rb @@ -0,0 +1,19 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/funtoo/network_dhcp" do + let(:template) { "guests/funtoo/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='dhcp' + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/funtoo/network_static_test.rb b/test/unit/templates/guests/funtoo/network_static_test.rb new file mode 100644 index 000000000..5a14312d2 --- /dev/null +++ b/test/unit/templates/guests/funtoo/network_static_test.rb @@ -0,0 +1,141 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/funtoo/network_static" do + let(:template) { "guests/funtoo/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + gateway: "1.2.3.4", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + gateway='1.2.3.4' + #VAGRANT-END + EOH + end + + it "includes the nameservers" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + nameservers: "ns1.company.com", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + nameservers='ns1.company.com' + #VAGRANT-END + EOH + end + + it "includes the domain" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + domain: "company.com", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + domain='company.com' + #VAGRANT-END + EOH + end + + it "includes the route" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + route: "5.6.7.8", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + route='5.6.7.8' + #VAGRANT-END + EOH + end + + it "includes the gateway6" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + gateway6: "aaaa:0000", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + gateway6='aaaa:0000' + #VAGRANT-END + EOH + end + + it "includes the route6" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + route6: "bbbb:1111", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + route6='bbbb:1111' + #VAGRANT-END + EOH + end + + it "includes the mtu" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + device: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + mtu: "1", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + template='interface' + ipaddr='1.1.1.1/255.255.0.0' + mtu='1' + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/gentoo/network_dhcp_test.rb b/test/unit/templates/guests/gentoo/network_dhcp_test.rb new file mode 100644 index 000000000..7885c2acc --- /dev/null +++ b/test/unit/templates/guests/gentoo/network_dhcp_test.rb @@ -0,0 +1,19 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/gentoo/network_dhcp" do + let(:template) { "guests/gentoo/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + config_ethen0="dhcp" + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/gentoo/network_static_test.rb b/test/unit/templates/guests/gentoo/network_static_test.rb new file mode 100644 index 000000000..e1eb8ce1a --- /dev/null +++ b/test/unit/templates/guests/gentoo/network_static_test.rb @@ -0,0 +1,37 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/gentoo/network_static" do + let(:template) { "guests/gentoo/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + config_ethen0=("1.1.1.1 netmask 255.255.0.0") + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + gateway: "1.2.3.4", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + config_ethen0=("1.1.1.1 netmask 255.255.0.0") + gateways_ethen0="1.2.3.4" + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/netbsd/network_dhcp_test.rb b/test/unit/templates/guests/netbsd/network_dhcp_test.rb new file mode 100644 index 000000000..c2f68d7ba --- /dev/null +++ b/test/unit/templates/guests/netbsd/network_dhcp_test.rb @@ -0,0 +1,18 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/netbsd/network_dhcp" do + let(:template) { "guests/netbsd/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + ifconfig_wmen0=dhcp + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/netbsd/network_static_test.rb b/test/unit/templates/guests/netbsd/network_static_test.rb new file mode 100644 index 000000000..210dc4d30 --- /dev/null +++ b/test/unit/templates/guests/netbsd/network_static_test.rb @@ -0,0 +1,20 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/netbsd/network_static" do + let(:template) { "guests/netbsd/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + ifconfig_wmen0="media autoselect up;inet 1.1.1.1 netmask 255.255.0.0" + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/redhat/network_dhcp_test.rb b/test/unit/templates/guests/redhat/network_dhcp_test.rb new file mode 100644 index 000000000..280678a2f --- /dev/null +++ b/test/unit/templates/guests/redhat/network_dhcp_test.rb @@ -0,0 +1,21 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/redhat/network_dhcp" do + let(:template) { "guests/redhat/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + BOOTPROTO=dhcp + ONBOOT=yes + DEVICE=ethen0 + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/redhat/network_static_test.rb b/test/unit/templates/guests/redhat/network_static_test.rb new file mode 100644 index 000000000..443ec2d56 --- /dev/null +++ b/test/unit/templates/guests/redhat/network_static_test.rb @@ -0,0 +1,49 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/redhat/network_static" do + let(:template) { "guests/redhat/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + NM_CONTROLLED=no + BOOTPROTO=none + ONBOOT=yes + IPADDR=1.1.1.1 + NETMASK=255.255.0.0 + DEVICE=ethen0 + PEERDNS=no + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + gateway: "1.2.3.4", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + NM_CONTROLLED=no + BOOTPROTO=none + ONBOOT=yes + IPADDR=1.1.1.1 + NETMASK=255.255.0.0 + DEVICE=ethen0 + GATEWAY=1.2.3.4 + PEERDNS=no + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/suse/network_dhcp_test.rb b/test/unit/templates/guests/suse/network_dhcp_test.rb new file mode 100644 index 000000000..82595db47 --- /dev/null +++ b/test/unit/templates/guests/suse/network_dhcp_test.rb @@ -0,0 +1,21 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/suse/network_dhcp" do + let(:template) { "guests/suse/network_dhcp" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + BOOTPROTO=dhcp + ONBOOT=yes + DEVICE=ethen0 + #VAGRANT-END + EOH + end +end diff --git a/test/unit/templates/guests/suse/network_static_test.rb b/test/unit/templates/guests/suse/network_static_test.rb new file mode 100644 index 000000000..09117268d --- /dev/null +++ b/test/unit/templates/guests/suse/network_static_test.rb @@ -0,0 +1,49 @@ +require_relative "../../../base" + +require "vagrant/util/template_renderer" + +describe "templates/guests/suse/network_static" do + let(:template) { "guests/suse/network_static" } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + BOOTPROTO='static' + IPADDR='1.1.1.1' + NETMASK='255.255.0.0' + DEVICE='ethen0' + PEERDNS='no' + STARTMODE='auto' + USERCONTROL='no' + #VAGRANT-END + EOH + end + + it "includes the gateway" do + result = Vagrant::Util::TemplateRenderer.render(template, options: { + interface: "en0", + ip: "1.1.1.1", + gateway: "1.2.3.4", + netmask: "255.255.0.0", + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + #VAGRANT-BEGIN + # The contents below are automatically generated by Vagrant. Do not modify. + BOOTPROTO='static' + IPADDR='1.1.1.1' + NETMASK='255.255.0.0' + DEVICE='ethen0' + GATEWAY='1.2.3.4' + PEERDNS='no' + STARTMODE='auto' + USERCONTROL='no' + #VAGRANT-END + EOH + end +end diff --git a/website/docs/source/v2/networking/private_network.html.md b/website/docs/source/v2/networking/private_network.html.md index 7f7e77d2a..d32020fa3 100644 --- a/website/docs/source/v2/networking/private_network.html.md +++ b/website/docs/source/v2/networking/private_network.html.md @@ -63,6 +63,9 @@ the [reserved private address space](http://en.wikipedia.org/wiki/Private_networ and most routers actually block traffic from going to them from the outside world. +For some operating systems, additional configuration options for the static +IP address are available such as setting the default gateway for mtu. + ## Disable Auto-Configuration If you want to manually configure the network interface yourself, you From 46cbd91198be5afc5b9752ed344000fc56073e32 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sat, 30 May 2015 12:35:30 -0700 Subject: [PATCH 3/3] Typo --- website/docs/source/v2/networking/private_network.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/source/v2/networking/private_network.html.md b/website/docs/source/v2/networking/private_network.html.md index d32020fa3..bef3c5bf5 100644 --- a/website/docs/source/v2/networking/private_network.html.md +++ b/website/docs/source/v2/networking/private_network.html.md @@ -64,7 +64,7 @@ and most routers actually block traffic from going to them from the outside world. For some operating systems, additional configuration options for the static -IP address are available such as setting the default gateway for mtu. +IP address are available such as setting the default gateway or MTU. ## Disable Auto-Configuration