Module: Dcmgr::Helpers::NicHelper
- Included in:
- Drivers::Kvm, NodeModules::Bandwidth, NodeModules::Nat, NodeModules::ServiceNetfilter, Rpc::HvaHandler
- Defined in:
- lib/dcmgr/helpers/nic_helper.rb
Instance Method Summary collapse
Instance Method Details
#find_nic(ifindex = 2) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dcmgr/helpers/nic_helper.rb', line 6 def find_nic(ifindex = 2) ifindex_map = {} Dir.glob("/sys/class/net/*/ifindex").each do |ifindex_path| device_name = File.split(File.split(ifindex_path).first)[1] ifindex_num = File.readlines(ifindex_path).first.strip ifindex_map[ifindex_num] = device_name end #p ifindex_map ifindex_map[ifindex.to_s] end |
#nic_state(if_name = 'eth0') ⇒ Object
17 18 19 20 21 22 |
# File 'lib/dcmgr/helpers/nic_helper.rb', line 17 def nic_state(if_name = 'eth0') operstate_path = "/sys/class/net/#{if_name}/operstate" if File.exists?(operstate_path) File.readlines(operstate_path).first.strip end end |
#valid_nic?(nic) ⇒ Boolean
24 25 26 27 28 29 30 31 32 |
# File 'lib/dcmgr/helpers/nic_helper.rb', line 24 def valid_nic?(nic) ifindex_path = "/sys/class/net/#{nic}/ifindex" if FileTest.exist?(ifindex_path) true else logger.warn("#{nic}: error fetching interface information: Device not found") false end end |