kmod_ixgbevf_url = node['basic']['kmod_ixgbevf_url']
kmod_ixgbevf_pkg_path = "#{Chef::Config[:file_cache_path]}/#{node['basic']['kmod_ixgbevf_pkg_name']}"

# TODO: test new only_if
execute 'yum-update' do
  command 'yum -y update'
  only_if { node['yum']['yum_update'] }
  # only_if { File.readlines("/etc/redhat-release").grep(/6.5/).size > 0 }
  # only_if { File.readlines("/etc/redhat-release").grep(/6.6 (Final)/).size == 0 }
end

remote_file kmod_ixgbevf_pkg_path do
  source kmod_ixgbevf_url
end

rpm_package kmod_ixgbevf_pkg_path do
  action :install
end

execute 'fix-grub-config-for-enhanced-networking' do
  command "sed -i '/^GRUB\_CMDLINE\_LINUX/s/\"$/\ net\.ifnames\=0\"/' /etc/default/grub"
  not_if 'cat /etc/default/grub | grep InterruptThrottleRate'
  notifies :run, 'execute[update-grub-config]', :immediately
end

# Update Grub configuration
execute 'update-grub-config' do
  command 'grub2-mkconfig -o /boot/grub2/grub.cfg'
  action :nothing
end

# Enables dynamic interrupt throttling to improve network performances
execute 'enable-interrupt-throttling' do
  command "echo 'options ixgbevf InterruptThrottleRate=1,1,1,1,1,1,1,1' > /etc/modprobe.d/ixgbevf.conf"
  not_if 'cat /etc/modprobe.d/ixgbevf.conf | grep InterruptThrottleRate'
end
