F #7671: CLI formatter and --pf option for nic-attach (#4620)

This commit is contained in:
Daniel Clavijo Coca authored and GitHub committed 2026-10-20 16:27:44 +02:00
1 parent e005161150
commit 751dad67ff
2 files changed
+49 -3

No files matched your search

+35 -1
View File
@@ -693,6 +693,33 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
end
def print_pcis(pcis)
total_vfs = Hash.new(0)
available_vfs = Hash.new(0)
pcis.each do |pci|
next unless pci['SRIOV'] == 'vf' && pci['PF_ADDRESS']
total_vfs[pci['PF_ADDRESS']] += 1
available_vfs[pci['PF_ADDRESS']] += 1 if pci['VMID'] == '-1'
end
pcis = pcis.map do |pci|
next pci unless pci['SRIOV'] == 'pf'
total = total_vfs[pci['ADDRESS']]
available = available_vfs[pci['ADDRESS']]
pci.merge('VFS' => "#{available}/#{total}")
end
extra_columns = {
:IFNAME => 'Network interface',
:SRIOV => 'SR-IOV role',
:PF_IFNAME => 'Parent PF interface',
:VFS => 'Available/total virtual functions',
:ESWITCH_MODE => 'Embedded switch mode'
}.select {|name, _| pcis.any? {|pci| pci.key?(name.to_s) } }
puts
CLIHelper.print_header('PCI DEVICES', false)
puts
@@ -726,7 +753,14 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
d['VENDOR_NAME']
end
default :VM, :ADDR, :TYPE, :NAME
extra_columns.each do |name, description|
column name, description, :size => name.to_s.length,
:left => true, :adjust => true do |d|
d[name.to_s] || '-'
end
end
default :VM, :ADDR, :TYPE, :NAME, *extra_columns.keys
end
table.show(pcis)
+14 -2
View File
@@ -237,6 +237,13 @@ CommandParser::CmdParser.new(ARGV) do
:description => 'Select PCI device by its class ID'
}
PF = {
:name => 'pf',
:large => '--pf interface',
:format => String,
:description => 'Select a virtual function by its parent PF interface name'
}
RESET_BACKUP = {
:name => 'reset',
:large => '--reset',
@@ -867,6 +874,8 @@ CommandParser::CmdParser.new(ARGV) do
To hotplug a PCI device and use it as a NIC interface in the VM select
it with --pci (short_address) or --pci_device (device ID),
--pci_class (class ID) and/or --pci_vendor (vendor ID).
Use --pf (interface name) to select a virtual function from a physical
function. Specify the virtual network with --network.
States: RUNNING, POWEROFF
EOT
@@ -881,7 +890,8 @@ CommandParser::CmdParser.new(ARGV) do
PCI,
PCI_CLASS,
PCI_VENDOR,
PCI_DEVICE
PCI_DEVICE,
PF
] do
if options[:file]
template = File.read(options[:file])
@@ -893,7 +903,7 @@ CommandParser::CmdParser.new(ARGV) do
nic_alias = options[:alias]
nic_name = options[:nic_name]
is_pci = [:pci, :pci_device, :pci_vendor, :pci_class].any? do |o|
is_pci = [:pci, :pci_device, :pci_vendor, :pci_class, :pf].any? do |o|
!options[o].nil?
end
@@ -902,6 +912,7 @@ CommandParser::CmdParser.new(ARGV) do
pcid = options[:pci_device]
pcic = options[:pci_class]
pciv = options[:pci_vendor]
pf = options[:pf]
template = 'PCI = [ TYPE = NIC'
template << ", NETWORK_ID = #{network_id}"
@@ -909,6 +920,7 @@ CommandParser::CmdParser.new(ARGV) do
template << ", DEVICE = \"#{pcid}\"" if pcid
template << ", CLASS = \"#{pcic}\"" if pcic
template << ", VENDOR = \"#{pciv}\"" if pciv
template << ", PF_IFNAME = \"#{pf}\"" if pf
elsif nic_alias
template = "NIC_ALIAS = [ PARENT = #{nic_alias}"
template << ", NETWORK_ID = #{network_id}"