mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
L #-: Fix linting issues
This commit is contained in:
parent
a06b82293f
commit
2f21cd1383
@ -917,9 +917,9 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
nic_alias = options[:alias]
|
||||
nic_name = options[:nic_name]
|
||||
|
||||
is_pci = [:pci, :pci_device, :pci_vendor, :pci_class].any? { |o|
|
||||
is_pci = [:pci, :pci_device, :pci_vendor, :pci_class].any? do |o|
|
||||
!options[o].nil?
|
||||
}
|
||||
end
|
||||
|
||||
if is_pci
|
||||
pcia = options[:pci]
|
||||
@ -927,7 +927,7 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
pcic = options[:pci_class]
|
||||
pciv = options[:pci_vendor]
|
||||
|
||||
template = "PCI = [ TYPE = NIC"
|
||||
template = 'PCI = [ TYPE = NIC'
|
||||
template << ", NETWORK_ID = #{network_id}"
|
||||
template << ", SHORT_ADDRESS = \"#{pcia}\"" if pcia
|
||||
template << ", DEVICE = \"#{pcid}\"" if pcid
|
||||
@ -942,7 +942,7 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
template << ", IP = #{ip}" if ip
|
||||
template << ", NAME = #{nic_name}" if nic_name
|
||||
template << "]"
|
||||
template << ']'
|
||||
end
|
||||
|
||||
helper.perform_action(args[0], options, 'Attaching NIC') do |vm|
|
||||
|
@ -107,7 +107,8 @@ begin
|
||||
domcap_xml = REXML::Document.new(domcapabilities)
|
||||
domcap_xml = domcap_xml.root
|
||||
|
||||
cpu_mode_custom_elem = domcap_xml.elements["cpu/mode[@name='custom',@supported='yes']"]
|
||||
cpu_mode_xpath = "cpu/mode[@name='custom',@supported='yes']"
|
||||
cpu_mode_custom_elem = domcap_xml.elements[cpu_mode_xpath]
|
||||
|
||||
cpu_mode_custom_elem.elements.each("model[@usable='no']") do |m|
|
||||
models.delete(m.text)
|
||||
|
@ -58,7 +58,6 @@ include VirtualMachineManagerKVM
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
#load_env("#{__dir__}/../../etc/vmm/kvm/kvmrc")
|
||||
load_local_env
|
||||
|
||||
domain = ARGV[0]
|
||||
@ -72,14 +71,14 @@ else
|
||||
end
|
||||
|
||||
script =<<~EOS
|
||||
#{virsh} attach-device #{domain} <(
|
||||
cat <<EOT
|
||||
#{dev_xml}
|
||||
EOT
|
||||
)
|
||||
#{virsh} attach-device #{domain} <(
|
||||
cat <<EOT
|
||||
#{dev_xml}
|
||||
EOT
|
||||
)
|
||||
EOS
|
||||
|
||||
rc, _out, err = Command.execute("bash -s", false, 0, :stdin_data => script)
|
||||
rc, _out, err = Command.execute('bash -s', false, 0, :stdin_data => script)
|
||||
|
||||
if rc != 0
|
||||
STDERR.puts "Could not attach NIC to #{domain}: #{err}"
|
||||
|
@ -61,14 +61,14 @@ include VirtualMachineManagerKVM
|
||||
# ------------------------------------------------------------------------------
|
||||
def attached?(dom, mac)
|
||||
cmd = "#{virsh} domiflist #{dom} | grep #{mac} > /dev/null 2>&1"
|
||||
rc, _o, _e = Command.execute("bash -s", false, 0, :stdin_data => cmd)
|
||||
rc, _o, _e = Command.execute('bash -s', false, 0, :stdin_data => cmd)
|
||||
|
||||
rc == 0
|
||||
end
|
||||
|
||||
def detach_interface(dom, mac)
|
||||
cmd = "#{virsh} detach-interface --domain #{dom} --type bridge --mac #{mac}"
|
||||
rc, _o, e = Command.execute("bash -s", false, 0, :stdin_data => cmd)
|
||||
rc, _o, e = Command.execute('bash -s', false, 0, :stdin_data => cmd)
|
||||
|
||||
STDERR.puts "Error detaching interface (#{mac}): #{e}" if rc != 0
|
||||
|
||||
@ -79,27 +79,25 @@ def detach_nic(dom, mac)
|
||||
tries = ENV['VIRSH_RETRIES']
|
||||
tries ||= 3
|
||||
|
||||
rc = tries.to_i.times do
|
||||
tries.to_i.times do
|
||||
detach_interface(dom, mac)
|
||||
|
||||
break 0 unless attached?(dom, mac)
|
||||
end
|
||||
|
||||
rc
|
||||
end
|
||||
|
||||
def detach_pci(dom, vm)
|
||||
dev_xml = vm.hostdev_xml(true)
|
||||
|
||||
cmd =<<~EOS
|
||||
#{virsh} detach-device #{dom} <(
|
||||
cat <<EOT
|
||||
#{dev_xml}
|
||||
EOT
|
||||
)
|
||||
#{virsh} detach-device #{dom} <(
|
||||
cat <<EOT
|
||||
#{dev_xml}
|
||||
EOT
|
||||
)
|
||||
EOS
|
||||
|
||||
rc, _o, e = Command.execute("bash -s", false, 0, :stdin_data => cmd)
|
||||
rc, _o, e = Command.execute('bash -s', false, 0, :stdin_data => cmd)
|
||||
|
||||
if rc != 0
|
||||
STDERR.puts "Could not attach NIC to #{dom}: #{e}"
|
||||
@ -110,7 +108,6 @@ end
|
||||
# ------------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#load_env("#{__dir__}/../../etc/vmm/kvm/kvmrc")
|
||||
load_local_env
|
||||
|
||||
domain = ARGV[0]
|
||||
|
@ -28,8 +28,8 @@ module VirtualMachineManagerKVM
|
||||
|
||||
# Default locations for kvmrc file on the front-end (local) or
|
||||
# hypervisor (remote)
|
||||
KVMRC_LOCAL = "/var/lib/one/remotes/etc/vmm/kvm/kvmrc"
|
||||
KVMRC_REMOTE = "/var/tmp/one/etc/vmm/kvm/kvmrc"
|
||||
KVMRC_LOCAL = '/var/lib/one/remotes/etc/vmm/kvm/kvmrc'
|
||||
KVMRC_REMOTE = '/var/tmp/one/etc/vmm/kvm/kvmrc'
|
||||
|
||||
# Loads env from the default local (front-end) path
|
||||
def load_local_env
|
||||
@ -74,7 +74,7 @@ module VirtualMachineManagerKVM
|
||||
def initialize(xml_action)
|
||||
super(xml_action, {})
|
||||
|
||||
#if set, it will scope VM element access
|
||||
# if set, it will scope VM element access
|
||||
@xpath_prefix = ''
|
||||
end
|
||||
|
||||
@ -119,7 +119,7 @@ module VirtualMachineManagerKVM
|
||||
dev << '<virtualport type="openvswitch"/>'
|
||||
end
|
||||
|
||||
dev << xputs("<source bridge=%s/>", 'BRIDGE')
|
||||
dev << xputs('<source bridge=%s/>', 'BRIDGE')
|
||||
else
|
||||
dev = '<interface type="ethernet">'
|
||||
end
|
||||
@ -132,45 +132,46 @@ module VirtualMachineManagerKVM
|
||||
dev << "<model type=#{model}/>" unless model.empty?
|
||||
|
||||
if model == 'virtio'
|
||||
dev << xputs('<driver name="vhost" queues=%s/>', 'VIRTIO_QUEUES')
|
||||
dev << xputs('<driver name="vhost" queues=%s/>',
|
||||
'VIRTIO_QUEUES')
|
||||
end
|
||||
|
||||
if exist?('IP') && !filter.empty?
|
||||
dev << "<filterref filter=#{filter}>"
|
||||
dev << xputs('<parameter name="IP" value=%s/>', 'IP')
|
||||
dev << xputs('<parameter name="IP" value=%s/>', 'VROUTER_IP')
|
||||
dev << "</filterref>"
|
||||
dev << '</filterref>'
|
||||
end
|
||||
|
||||
inb_keys = %w[ INBOUND_AVG_BW INBOUND_PEAK_BW INBOUND_PEAK_KB ]
|
||||
inbound = inb_keys.any? { |e| exist? e }
|
||||
inb_keys = %w[INBOUND_AVG_BW INBOUND_PEAK_BW INBOUND_PEAK_KB]
|
||||
inbound = inb_keys.any? {|e| exist? e }
|
||||
|
||||
outb_keys = %w[ OUTBOUND_AVG_BW OUTBOUND_PEAK_BW OUTBOUND_PEAK_KB ]
|
||||
outbound = outb_keys.any? { |e| exist? e }
|
||||
outb_keys = %w[OUTBOUND_AVG_BW OUTBOUND_PEAK_BW OUTBOUND_PEAK_KB]
|
||||
outbound = outb_keys.any? {|e| exist? e }
|
||||
|
||||
if inbound || outbound
|
||||
dev << "<bandwidth>"
|
||||
dev << '<bandwidth>'
|
||||
|
||||
if inbound
|
||||
dev << "<inbound"
|
||||
dev << xputs(" average=%s", 'INBOUND_AVG_BW')
|
||||
dev << xputs(" peak=%s", 'INBOUND_PEAK_BW')
|
||||
dev << xputs(" burst=%s", 'INBOUND_PEAK_KB')
|
||||
dev << "/>"
|
||||
dev << '<inbound'
|
||||
dev << xputs(' average=%s', 'INBOUND_AVG_BW')
|
||||
dev << xputs(' peak=%s', 'INBOUND_PEAK_BW')
|
||||
dev << xputs(' burst=%s', 'INBOUND_PEAK_KB')
|
||||
dev << '/>'
|
||||
end
|
||||
|
||||
if outbound
|
||||
dev << "<outbound"
|
||||
dev << xputs(" average=%s", 'OUTBOUND_AVG_BW')
|
||||
dev << xputs(" peak=%s", 'OUTBOUND_PEAK_BW')
|
||||
dev << xputs(" burst=%s", 'OUTBOUND_PEAK_KB')
|
||||
dev << "/>"
|
||||
dev << '<outbound'
|
||||
dev << xputs(' average=%s', 'OUTBOUND_AVG_BW')
|
||||
dev << xputs(' peak=%s', 'OUTBOUND_PEAK_BW')
|
||||
dev << xputs(' burst=%s', 'OUTBOUND_PEAK_KB')
|
||||
dev << '/>'
|
||||
end
|
||||
|
||||
dev << "</bandwidth>"
|
||||
dev << '</bandwidth>'
|
||||
end
|
||||
|
||||
dev << "</interface>"
|
||||
dev << '</interface>'
|
||||
|
||||
@xpath_prefix = prefix_old
|
||||
|
||||
@ -197,17 +198,18 @@ module VirtualMachineManagerKVM
|
||||
# Example:
|
||||
#
|
||||
# <hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
# <source>
|
||||
# <address domain='0x0000' bus='0x05' slot='0x02' function='0x0'/>
|
||||
# </source>
|
||||
# <address type='pci' domain='0x0' bus='0x01' slot='0x01' function='0'/>
|
||||
# <source>
|
||||
# <address domain='0x0000' bus='0x05' slot='0x02' function='0x0'/>
|
||||
# </source>
|
||||
# <address type='pci' domain='0x0' bus='0x01'
|
||||
# slot='0x01' function='0'/>
|
||||
# </hostdev>
|
||||
#
|
||||
# NOTE: Libvirt/QEMU seems to have a race condition accesing vfio device
|
||||
# and the permission check/set that makes <hostdev> not work for VF.
|
||||
#
|
||||
# NOTE: On detach (as we are manging MAC/VLAN through ip link vf) devices
|
||||
# needs to use <hostdev> format
|
||||
# NOTE: On detach (as we are managing MAC/VLAN through ip link vf)
|
||||
# devices needs to use <hostdev> format
|
||||
#-----------------------------------------------------------------------
|
||||
def hostdev_xml(force_hostdev = false)
|
||||
prefix_old = @xpath_prefix
|
||||
@ -216,7 +218,7 @@ module VirtualMachineManagerKVM
|
||||
if exist? 'UUID'
|
||||
dev = '<hostdev mode="subsystem" type="mdev" model="vfio-pci">'
|
||||
dev << xputs('<source><address uuid=%s/></source>', 'UUID')
|
||||
dev << "</hostdev>"
|
||||
dev << '</hostdev>'
|
||||
else
|
||||
if force_hostdev
|
||||
is_vf = false
|
||||
@ -239,22 +241,6 @@ module VirtualMachineManagerKVM
|
||||
dev << xputs(' slot=%s', 'SLOT', :hex => true)
|
||||
dev << xputs(' function=%s', 'FUNCTION', :hex => true)
|
||||
dev << '/></source>'
|
||||
=begin
|
||||
#Setting Bus address needs to check that a PCI contoller is
|
||||
#present for Bus 1
|
||||
vm_addr = %w[VM_DOMAIN VM_BUS VM_SLOT VM_FUNCTION].all? {|e|
|
||||
exist? e
|
||||
}
|
||||
|
||||
if vm_addr
|
||||
dev << '<address type="pci"'
|
||||
dev << xputs(' domain=%s', 'VM_DOMAIN')
|
||||
dev << xputs(' bus=%s', 'VM_BUS')
|
||||
dev << xputs(' slot=%s', 'VM_SLOT')
|
||||
dev << xputs(' function=%s', 'VM_FUNCTION')
|
||||
dev << '/>'
|
||||
end
|
||||
=end
|
||||
dev << dev_end
|
||||
end
|
||||
|
||||
@ -276,7 +262,7 @@ module VirtualMachineManagerKVM
|
||||
|
||||
value = "0x#{value}" if opts[:hex]
|
||||
|
||||
sprintf(format, value.encode(:xml => :attr))
|
||||
format(format, value.encode(:xml => :attr))
|
||||
end
|
||||
|
||||
# @return true if the given VM element exists (considers xpath_prefix)
|
||||
@ -287,9 +273,13 @@ module VirtualMachineManagerKVM
|
||||
# @return a copy of an env variable or '' if not defined
|
||||
def env(name)
|
||||
return '' if ENV[name].nil?
|
||||
|
||||
ENV[name].dup
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# rubocop:enable Style/ClassAndModuleChildren
|
||||
# rubocop:enable Style/ClassVars
|
||||
|
@ -62,11 +62,12 @@ module VNMMAD::VirtualFunction
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Style/CombinableLoops
|
||||
vm.each_pci do |pci|
|
||||
next if pci[:short_address].nil?
|
||||
next if is_attach && pci[:attach] != 'YES'
|
||||
|
||||
#Look for the associated PF
|
||||
# Look for the associated PF
|
||||
cmd = "find /sys/devices -type l -name 'virtfn*' -printf '%p#'"\
|
||||
" -exec readlink -f '{}' \\;"
|
||||
|
||||
@ -81,9 +82,12 @@ module VNMMAD::VirtualFunction
|
||||
|
||||
virtfn, _vf = line.split('#')
|
||||
|
||||
#Matched line is in the form:
|
||||
#virtfn /sys/devices/pci0000:80/0000:80:03.2/0000:85:00.0/virtfn3
|
||||
#_vf /sys/devices/pci0000:80/0000:80:03.2/0000:85:02.3
|
||||
# rubocop:disable Layout/LineLength
|
||||
# Matched line is in the form:
|
||||
# virtfn /sys/devices/pci0000:80/0000:80:03.2/0000:85:00.0/virtfn3
|
||||
# _vf /sys/devices/pci0000:80/0000:80:03.2/0000:85:02.3
|
||||
# rubocop:enable Layout/LineLength
|
||||
|
||||
m = virtfn.match(/virtfn([0-9]+)/)
|
||||
|
||||
next if m.nil?
|
||||
@ -102,6 +106,8 @@ module VNMMAD::VirtualFunction
|
||||
OpenNebula.exec_and_log(cmd)
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/CombinableLoops
|
||||
end
|
||||
|
||||
end
|
||||
# rubocop:enable Style/ClassAndModuleChildren
|
||||
|
Loading…
x
Reference in New Issue
Block a user