Skip to content

Commit

Permalink
Merge pull request #927 from agrare/add_specs_customization_nic_settings
Browse files Browse the repository at this point in the history
Add specs for nic_settings customization
  • Loading branch information
Fryguy authored Nov 12, 2024
2 parents 28af5dc + 5754ea2 commit a802321
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
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] }

%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

0 comments on commit a802321

Please sign in to comment.