Class: Facter::Util::Infiniband

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/util/infiniband.rb

Overview

Infiniband fact util class

Constant Summary collapse

LSPCI_IB_REGEX =
%r{\s(1077|15b3|1678|1867|18b8|1fc1):}

Class Method Summary collapse

Class Method Details

.count_ib_devicesInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the number of InfiniBand interfaces found in lspci output

Returns:

  • (Integer)


21
22
23
24
25
26
27
28
29
# File 'lib/facter/util/infiniband.rb', line 21

def self.count_ib_devices
  count = 0
  if Facter::Util::Resolution.which('lspci')
    output = lspci
    matches = output.scan(LSPCI_IB_REGEX)
    count = matches.flatten.reject { |s| s.nil? }.length
  end
  count
end

.get_hca_board_id(hca) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns HCA board ID

Returns:

  • (String)


149
150
151
152
153
# File 'lib/facter/util/infiniband.rb', line 149

def self.get_hca_board_id(hca)
  sysfs_path = File.join('/sys/class/infiniband', hca, 'board_id')
  board_id = read_sysfs(sysfs_path)
  board_id
end

.get_hca_port_guids(hca) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns hash of HCA ports and their GUIDs

Returns:

  • (Hash)


130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/facter/util/infiniband.rb', line 130

def self.get_hca_port_guids(hca)
  port_guids = {}
  unless Facter::Util::Resolution.which('ibstat')
    return {}
  end
  output = Facter::Util::Resolution.exec("ibstat -p #{hca}")
  output.each_line.with_index do |line, index|
    guid = line.strip
    port = index + 1
    port_guids[port.to_s] = guid
  end
  port_guids
end

.get_port_board_id(port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns board_id of an InfiniBand port

Returns:

  • (String)


79
80
81
82
83
# File 'lib/facter/util/infiniband.rb', line 79

def self.get_port_board_id(port)
  sysfs_path = File.join('/sys/class/infiniband', port, 'board_id')
  board_id = read_sysfs(sysfs_path)
  board_id
end

.get_port_fw_version(port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns firmware version of an InfiniBand port

Returns:

  • (String)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/facter/util/infiniband.rb', line 58

def self.get_port_fw_version(port)
  sysfs_base_path = File.join('/sys/class/infiniband/', port)

  case port
  when %r{^mlx}
    sysfs_fw_file = File.join(sysfs_base_path, 'fw_ver')
  when %r{^qib}
    sysfs_fw_file = File.join(sysfs_base_path, 'version')
  else
    return nil
  end

  fw_version = read_sysfs(sysfs_fw_file)
  fw_version
end

.get_port_rate(port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns rate of InifniBand port

Returns:

  • (String)


100
101
102
103
104
105
106
107
# File 'lib/facter/util/infiniband.rb', line 100

def self.get_port_rate(port)
  port_sysfs_path = Dir.glob(File.join('/sys/class/infiniband', port, 'ports', '*')).first
  return nil if port_sysfs_path.nil?

  rate_sysfs_path = File.join(port_sysfs_path, 'rate')
  rate = read_sysfs(rate_sysfs_path)
  rate
end

.get_real_port_linklayer(hca, port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns link layer of Infiniband port (Ethernet or InfiniBand)

Returns:

  • (String)


190
191
192
193
194
195
196
197
# File 'lib/facter/util/infiniband.rb', line 190

def self.get_real_port_linklayer(hca, port)
  port_sysfs_path = self.port_sysfs_path(hca, port)
  return nil if port_sysfs_path.nil?

  linklayer_sysfs_path = File.join(port_sysfs_path, 'link_layer')
  linklayer = read_sysfs(linklayer_sysfs_path)
  linklayer
end

.get_real_port_rate(hca, port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns rate of InifniBand port

Returns:

  • (String)


160
161
162
163
164
165
166
167
168
# File 'lib/facter/util/infiniband.rb', line 160

def self.get_real_port_rate(hca, port)
  port_sysfs_path = self.port_sysfs_path(hca, port)
  return nil if port_sysfs_path.nil?

  rate_sysfs_path = File.join(port_sysfs_path, 'rate')
  rate = read_sysfs(rate_sysfs_path)
  return nil if rate.nil?
  rate[%r{^(\d+)\s}, 1]
end

.get_real_port_state(hca, port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns state of InifniBand port

Returns:

  • (String)


175
176
177
178
179
180
181
182
183
# File 'lib/facter/util/infiniband.rb', line 175

def self.get_real_port_state(hca, port)
  port_sysfs_path = self.port_sysfs_path(hca, port)
  return nil if port_sysfs_path.nil?

  state_sysfs_path = File.join(port_sysfs_path, 'state')
  state = read_sysfs(state_sysfs_path)
  return nil if state.nil?
  state[%r{: (.*)}, 1]
end

.hcasArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns array of HCAs on the system

Returns:

  • (Array)


114
115
116
117
118
119
120
121
122
123
# File 'lib/facter/util/infiniband.rb', line 114

def self.hcas
  hcas = []
  if File.directory?('/sys/class/infiniband')
    Dir.glob('/sys/class/infiniband/*').each do |dir|
      hca = File.basename(dir)
      hcas << hca
    end
  end
  hcas
end

.lspci(command = 'lspci -n 2>/dev/null') ⇒ Object

lspci is a delegating helper method intended to make it easier to stub the system call without affecting other calls to Facter::Core::Execution.exec



8
9
10
11
12
13
# File 'lib/facter/util/infiniband.rb', line 8

def self.lspci(command = 'lspci -n 2>/dev/null')
  # TODO: Deprecated in facter-2.0
  Facter::Util::Resolution.exec command
  # TODO: Not supported in facter < 2.0
  # Facter::Core::Execution.exec command
end

.netdev_to_hcaportHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns hash of net device names (ib0, p1p1) and data about each

Returns:

  • (Hash)


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/facter/util/infiniband.rb', line 204

def self.netdev_to_hcaport
  netdevs = {}
  unless Facter::Util::Resolution.which('ibdev2netdev')
    return {}
  end
  output = Facter::Util::Resolution.exec('ibdev2netdev')
  return {} if output.nil?
  return {} if output.strip.empty?
  output.each_line do |line|
    split = line.split(' ')
    netdevs[split[4]] = {
      'hca' => split[0],
      'port' => split[2],
      'state' => get_real_port_state(split[0], split[2]),
      'rate' => get_real_port_rate(split[0], split[2]),
      'link_layer' => get_real_port_linklayer(split[0], split[2]),
    }
  end
  netdevs
end

.port_sysfs_path(hca, port) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get path to port sysfs

Returns:

  • (String)


47
48
49
50
51
# File 'lib/facter/util/infiniband.rb', line 47

def self.port_sysfs_path(hca, port)
  port_sysfs_path = File.join('/sys/class/infiniband', hca, 'ports', port)
  return nil unless File.exist?(port_sysfs_path)
  port_sysfs_path
end

.portsArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Array of InfiniBand ports

Returns:

  • (Array)


90
91
92
93
# File 'lib/facter/util/infiniband.rb', line 90

def self.ports
  ports = Dir.glob('/sys/class/infiniband/*').map { |d| File.basename(d) }
  ports
end

.read_sysfs(path) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads the contents of path in sysfs

Returns:

  • (String)


36
37
38
39
40
# File 'lib/facter/util/infiniband.rb', line 36

def self.read_sysfs(path)
  output = Facter::Util::Resolution.exec(['cat ', path].join) if File.exist?(path)
  return nil if output.nil?
  output.strip
end