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

Display port group for VM instances #3992

Merged
merged 4 commits into from
May 30, 2018
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
18 changes: 17 additions & 1 deletion app/helpers/textual_mixins/textual_devices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def disks_attributes
disks.compact
end

def network_name(port)
network = nil
if port.lan&.switch
network = _("Network:") + port.lan.name + lan_attribute(port)
end
network
end

def network_attributes
networks = []
return networks if @record.hardware.ports.empty?
Expand All @@ -95,11 +103,19 @@ def network_attributes
address = port.address
filename = port.filename
autodetect = port.auto_detect ? "" : _("Default Adapter")
desc = [location, address, filename, autodetect].compact.join(', ')
desc = [location, address, filename, autodetect, network_name(port)].compact.join(', ')
Device.new(name, desc, nil, port.device_type)
end
end

def lan_prefix(nic)
nic.lan&.switch&.shared? ? _("Distributed ") : ''
end

def lan_attribute(nic)
nic.lan&.switch&.name ? "(" + lan_prefix(nic) + _("Switch: ") + nic.lan.switch.name + ")" : ''
end

def devices_details
devices = []
return devices unless @record.try(:hardware)
Expand Down
19 changes: 19 additions & 0 deletions spec/helpers/textual_mixins/textual_devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,24 @@
end
it { is_expected.not_to be_empty }
end

context "without vswitch and portgroup" do
let(:hw) { FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic)]) }
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("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("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