Module: OmfRc::Util::Sysfs

Extended by:
ResourceProxyDSL::ClassMethods
Includes:
ResourceProxyDSL
Included in:
ResourceProxy::Net, ResourceProxy::Node, ResourceProxy::Wlan
Defined in:
omf_rc/lib/omf_rc/util/sysfs.rb

Overview

Getting available hardware by browsing sysfs directories

Constant Summary

Constant Summary

Constants included from ResourceProxyDSL

ResourceProxyDSL::DEFAULT_PROP_ACCESS, ResourceProxyDSL::PROXY_DIR, ResourceProxyDSL::UTIL_DIR

FRCP Request Methods (collapse)

Methods included from ResourceProxyDSL::ClassMethods

call_hook, configure, configure_all, extend_configure, extend_hook, extend_request, extend_work, hook, namespace, property, register_proxy, request, utility, work

Methods included from ResourceProxyDSL

#call_hook, #hook_defined?, included

Instance Method Details

- (Object) request_devices

Note:

Method 'request_devices' generated by DSL method 'request'

Examples:

Sample return value

[
  { name: 'eth0', driver: 'e1000e', category: 'net', proxy: 'net' },
  { name: 'phy0', driver: 'iwlwifi', category: 'net', subcategory: 'wlan', proxy: 'wlan' } ]


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'omf_rc/lib/omf_rc/util/sysfs.rb', line 19

request :devices do |resource|
  devices = []
  # Support net devices for now
  category = "net"

  Dir.glob("/sys/class/net/eth*").each do |v|
    File.exist?("#{v}/uevent") && File.open("#{v}/uevent") do |f|
      subcategory = f.read.match(/DEVTYPE=(.+)/) && $1
      proxy = "net"
      File.exist?("#{v}/device/uevent") && File.open("#{v}/device/uevent") do |f|
        driver = f.read.match(/DRIVER=(.+)/) && $1
        device = { name: File.basename(v), driver: driver, category: category }
        device[:subcategory] = subcategory if subcategory
        device[:proxy] = proxy if OmfRc::ResourceFactory.proxy_list.include?(proxy.to_sym)
        File.exist?("#{v}/operstate") && File.open("#{v}/operstate") do |fo|
          device[:op_state] = (fo.read || '').chomp
        end
        # Let's see if the interface is already up
        ip = Facter.value("ipaddress_#{File.basename(v)}")
        ip_v6 = Facter.value("ipaddress6_#{File.basename(v)}")
        device[:ip4] = ip if ip
        device[:ip6] = ip_v6 if ip_v6
        devices << device
      end
    end
  end

  Dir.glob("/sys/class/ieee80211/*").each do |v|
    subcategory = "wlan"
    proxy = "wlan"
    File.exist?("#{v}/device/uevent") && File.open("#{v}/device/uevent") do |f|
      driver = f.read.match(/DRIVER=(.+)/) && $1
      device = { name: File.basename(v), driver: driver, category: category, subcategory: subcategory }
      device[:proxy] = proxy if OmfRc::ResourceFactory.proxy_list.include?(proxy.to_sym)
      devices << device
    end
  end
  devices
end

- (Object) request_wlan_devices

Note:

Method 'request_wlan_devices' generated by DSL method 'request'

Examples:

Sample return value

[ { name: 'phy0', driver: 'iwlwifi', category: 'net', subcategory: 'wlan', proxy: 'wlan' } ]


64
65
66
# File 'omf_rc/lib/omf_rc/util/sysfs.rb', line 64

request :wlan_devices do |resource|
  resource.request_devices.find_all { |v| v[:proxy] == 'wlan' }
end