Skip to content

Commit

Permalink
Display port group details as a part of the network information. Upda…
Browse files Browse the repository at this point in the history
…te specs for that.
  • Loading branch information
lgalis committed May 30, 2018
1 parent db82f4e commit 957b870
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
17 changes: 4 additions & 13 deletions app/helpers/textual_mixins/textual_devices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def disks_attributes
end

def network_name(port)
network = ''
network = nil
if port.lan&.switch
network = _("Network:") + port.lan.name
network = _("Network:") + port.lan.name + lan_attribute(port)
end
network
end
Expand All @@ -112,16 +112,8 @@ def lan_prefix(nic)
nic.lan&.switch&.shared? ? _("Distributed ") : ''
end

def lan_attributes
lan_devices = []
return lan_devices if @record.hardware&.nics&.all? { |nic| nic.lan.nil? }
@record.hardware.nics.map do |nic|
next unless nic.lan&.switch
name = lan_prefix(nic) + 'Port Group'
switch = lan_prefix(nic) + _("Switch: ") + nic.lan.switch.name
desc = [switch].compact.join(', ')
Device.new(name, desc, nil, nic.device_type)
end
def lan_attribute(nic)
nic.lan&.switch&.name ? "(" + lan_prefix(nic) + _("Switch: ") + nic.lan.switch.name + ")" : ''
end

def devices_details
Expand All @@ -131,7 +123,6 @@ def devices_details
devices += cpu_attributes
devices += disks_attributes
devices += network_attributes
devices += lan_attributes
devices
end
end
10 changes: 3 additions & 7 deletions spec/helpers/textual_mixins/textual_devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,24 @@
end
it { is_expected.not_to be_empty }
end
end

describe "#lan_attributes" do
subject { helper.lan_attributes }

context "without vswitch and portgroup" do
let(:hw) { FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic)]) }
it { is_expected.to be_empty }
it { is_expected.to eq([Device.new("Ethernet #{hw.ports.first.name}", [hw.ports.first.address.to_s, "Default Adapter"].compact.join(', '), nil, "ethernet")]) }
end

context "with vswitch and portgroup" do
let(:switch) { FactoryGirl.create(:switch, :name => 'test_switch1', :shared => 'false') }
let(:lan) { FactoryGirl.create(:lan, :name => "VM NFS Network", :switch => switch) }
let(:hw) { FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic, :lan => lan)]) }
it { is_expected.to eq([Device.new("Port Group", "Switch: test_switch1", nil, "ethernet")]) }
it { is_expected.to eq([Device.new("Ethernet #{hw.ports.first.name}", [hw.ports.first.address.to_s, "Default Adapter", "Network:VM NFS Network(Switch: test_switch1)"].compact.join(', '), nil, "ethernet")]) }
end

context "with dvswitch and dvportgroup" do
let(:switch) { FactoryGirl.create(:switch, :name => 'test_switch1', :shared => 'true') }
let(:lan) { FactoryGirl.create(:lan, :name => "VM NFS Network", :switch => switch) }
let(:hw) { FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic, :lan => lan)]) }
it { is_expected.to eq([Device.new("Distributed Port Group", "Distributed Switch: test_switch1", nil, "ethernet")]) }
it { is_expected.to eq([Device.new("Ethernet #{hw.ports.first.name}", [hw.ports.first.address.to_s, "Default Adapter", "Network:VM NFS Network(Distributed Switch: test_switch1)"].compact.join(', '), nil, "ethernet")]) }
end
end
end

0 comments on commit 957b870

Please sign in to comment.