Module: Dcmgr::Helpers::NicHelper

Instance Method Summary collapse

Instance Method Details

#clean_mac(mac, delim = ':') ⇒ Object

This method cleans up ugly mac addressed stored in the dcmgr database. Mac addresses in the database are stored as alphanumeric strings without the : inbetween them. This method properly puts those in there.



27
28
29
# File 'lib/dcmgr/helpers/nic_helper.rb', line 27

def clean_mac(mac,delim = ':')
  mac.unpack('A2'*6).join(delim)
end

#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

#is_natted?(vnic_map) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dcmgr/helpers/nic_helper.rb', line 31

def is_natted?(vnic_map)
  not vnic_map[:ipv4][:nat_address].nil?
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

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'lib/dcmgr/helpers/nic_helper.rb', line 35

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