Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for nic_settings customization #927

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ def collect_nic_settings
nics = Array.wrap(options[:nic_settings])
nic = nics[0]
nic = {} if nic.blank?
[:dns_domain, :dns_servers, :sysprep_netbios_mode, :wins_servers, :addr_mode,
:gateway, :subnet_mask, :ip_addr].each { |key| nic[key] = options[key] }
Copy link
Member Author

@agrare agrare Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE setting nic[key] = options[key] without checking if nic[key] is set already was causing the first entry in the nic_settings array to be overwritten with all nils so you had to duplicate the first nic's values like:

:nic_settings = [{:ip_addr => "1.2.3.4"}],
:ip_addr => "1.2.3.4"


%i[dns_domain dns_servers sysprep_netbios_mode wins_servers addr_mode gateway subnet_mask ip_addr].each do |key|
nic[key] ||= options[key] if options.key?(key)
end

nics[0] = nic

options[:nic_settings] = nics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
vh['nicSettingMap'] = []
vh
end
let(:nic_settings_map) { [] }
let(:new_spec) do
{
"identity" => {
Expand All @@ -86,7 +87,7 @@
}
},
"globalIPSettings" => {},
"nicSettingMap" => [],
"nicSettingMap" => nic_settings_map,
"options" => {}
}
end
Expand Down Expand Up @@ -129,5 +130,42 @@
expect(prov_vm).not_to receive(:load_customization_spec)
expect(prov_vm.build_customization_spec).to(eq(new_spec))
end

context "with network options" do
context "set at the top level of options" do
let(:ip_addr) { "192.168.1.10" }
let(:gateway) { "192.168.1.1" }
let(:dns_domain) { "localdomain" }
let(:nic_settings_map) { [{"adapter" => {"dnsDomain" => dns_domain, "gateway" => [gateway], "ip" => {"ipAddress" => ip_addr}}}] }

it 'sets the nicSettingMap on the new spec' do
options[:sysprep_custom_spec] = ''
options[:sysprep_full_name] = 'sysprep_full_name_value'
options[:sysprep_organization] = 'sysprep_organization_value'
options[:requested_network_adapter_count] = 1
options[:ip_addr] = ip_addr
options[:gateway] = gateway
options[:dns_domain] = dns_domain

expect(prov_vm).not_to receive(:load_customization_spec)
expect(prov_vm.build_customization_spec).to(eq(new_spec))
end
end

context "with a nic_settings array in options" do
let(:nic_settings_map) { [{"adapter" => {"ip" => {"ipAddress" => "192.168.1.10"}}}, {"adapter" => {"ip" => {"ipAddress" => "192.168.2.10"}}}] }

it 'sets network settings for multiple nics' do
options[:sysprep_custom_spec] = ''
options[:sysprep_full_name] = 'sysprep_full_name_value'
options[:sysprep_organization] = 'sysprep_organization_value'
options[:requested_network_adapter_count] = 2
options[:nic_settings] = [{:ip_addr => "192.168.1.10"}, {:ip_addr => "192.168.2.10"}]

expect(prov_vm).not_to receive(:load_customization_spec)
expect(prov_vm.build_customization_spec).to(eq(new_spec))
end
end
end
end
end