diff --git a/src/cli/onevm b/src/cli/onevm index 8bea0c4556..13246dc1cd 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -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| diff --git a/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb b/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb index 740adf681d..45bd46fd3f 100755 --- a/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb +++ b/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb @@ -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) diff --git a/src/vmm_mad/remotes/kvm/attach_nic b/src/vmm_mad/remotes/kvm/attach_nic index 0ba8ff32a7..436ca78dd7 100755 --- a/src/vmm_mad/remotes/kvm/attach_nic +++ b/src/vmm_mad/remotes/kvm/attach_nic @@ -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 < 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}" diff --git a/src/vmm_mad/remotes/kvm/detach_nic b/src/vmm_mad/remotes/kvm/detach_nic index d79643f7e5..48fd2c83ed 100755 --- a/src/vmm_mad/remotes/kvm/detach_nic +++ b/src/vmm_mad/remotes/kvm/detach_nic @@ -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 < 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] diff --git a/src/vmm_mad/remotes/lib/kvm/opennebula_vm.rb b/src/vmm_mad/remotes/lib/kvm/opennebula_vm.rb index 68f1313f03..c1144feeb7 100644 --- a/src/vmm_mad/remotes/lib/kvm/opennebula_vm.rb +++ b/src/vmm_mad/remotes/lib/kvm/opennebula_vm.rb @@ -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 << '' end - dev << xputs("", 'BRIDGE') + dev << xputs('', 'BRIDGE') else dev = '' end @@ -132,45 +132,46 @@ module VirtualMachineManagerKVM dev << "" unless model.empty? if model == 'virtio' - dev << xputs('', 'VIRTIO_QUEUES') + dev << xputs('', + 'VIRTIO_QUEUES') end if exist?('IP') && !filter.empty? dev << "" dev << xputs('', 'IP') dev << xputs('', 'VROUTER_IP') - dev << "" + dev << '' 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 << "" + dev << '' if inbound - dev << "" + dev << '' end if outbound - dev << "" + dev << '' end - dev << "" + dev << '' end - dev << "" + dev << '' @xpath_prefix = prefix_old @@ -197,17 +198,18 @@ module VirtualMachineManagerKVM # Example: # # - # - #
- # - #
+ # + #
+ # + #
# # # NOTE: Libvirt/QEMU seems to have a race condition accesing vfio device # and the permission check/set that makes not work for VF. # - # NOTE: On detach (as we are manging MAC/VLAN through ip link vf) devices - # needs to use format + # NOTE: On detach (as we are managing MAC/VLAN through ip link vf) + # devices needs to use format #----------------------------------------------------------------------- def hostdev_xml(force_hostdev = false) prefix_old = @xpath_prefix @@ -216,7 +218,7 @@ module VirtualMachineManagerKVM if exist? 'UUID' dev = '' dev << xputs('
', 'UUID') - dev << "" + dev << '' 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 << '/>' -=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 << '
' - 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 diff --git a/src/vnm_mad/remotes/lib/vf.rb b/src/vnm_mad/remotes/lib/vf.rb index fe25499e17..e5d0f636b3 100644 --- a/src/vnm_mad/remotes/lib/vf.rb +++ b/src/vnm_mad/remotes/lib/vf.rb @@ -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