mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-06-08 16:26:25 -04:00
Use interface name for hostonly network configuration
When provided a name for the hostonly network in the VirtualBox provider, always use the interface name in the final configuration.
This commit is contained in:
parent
e62d18bc1d
commit
7e283bd185
2 changed files with 56 additions and 0 deletions
|
|
@ -356,6 +356,16 @@ module VagrantPlugins
|
|||
dhcp_options[:dhcp_upper] = options[:dhcp_upper] || (ip_range.last(2).first).to_s
|
||||
end
|
||||
|
||||
# Find the hostonly interface name if display name was
|
||||
# provided
|
||||
if options[:name]
|
||||
hostif = @env[:machine].provider.driver.read_host_only_networks.detect { |interface|
|
||||
interface[:name] == options[:name] ||
|
||||
interface[:vboxnetworkname] == options[:name]
|
||||
}
|
||||
options[:name] = hostif[:name] if hostif
|
||||
end
|
||||
|
||||
return {
|
||||
adapter_ip: options[:adapter_ip],
|
||||
auto_config: options[:auto_config],
|
||||
|
|
|
|||
|
|
@ -84,6 +84,52 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when name is provided as interface name" do
|
||||
let(:options) {
|
||||
{
|
||||
type: type,
|
||||
ip: address,
|
||||
name: name
|
||||
}
|
||||
}
|
||||
let(:name) { "hostonly_ifname" }
|
||||
let(:display_name) { "HostInterfaceNetworking-hostonly_ifname" }
|
||||
let(:hostonly_networks) do
|
||||
[
|
||||
{
|
||||
name: name,
|
||||
vboxnetworkname: display_name
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
before { allow(driver).to receive(:read_host_only_networks).and_return(hostonly_networks) }
|
||||
|
||||
it "should lookup host only networks" do
|
||||
expect(driver).to receive(:read_host_only_networks).and_return(hostonly_networks)
|
||||
|
||||
subject.hostonly_config(options)
|
||||
end
|
||||
|
||||
it "should not change the name" do
|
||||
expect(subject.hostonly_config(options)[:name]) == name
|
||||
end
|
||||
|
||||
context "when display name is provided in options" do
|
||||
let(:options) {
|
||||
{
|
||||
type: type,
|
||||
ip: address,
|
||||
name: display_name
|
||||
}
|
||||
}
|
||||
|
||||
it "should change the name to the interface name" do
|
||||
expect(subject.hostonly_config(options)[:name]) == name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#validate_hostonly_ip!" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue