Class: Termy::SystemFacts
- Inherits:
-
Object
- Object
- Termy::SystemFacts
- Defined in:
- lib/termy/system_facts.rb
Instance Attribute Summary collapse
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#domainname ⇒ Object
readonly
Returns the value of attribute domainname.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#kernel ⇒ Object
readonly
Returns the value of attribute kernel.
Instance Method Summary collapse
- #boot_id ⇒ Object
- #date ⇒ Object
- #file_systems ⇒ Object
-
#initialize ⇒ SystemFacts
constructor
A new instance of SystemFacts.
- #machine_id ⇒ Object
- #network ⇒ Object
- #os_release ⇒ Object
Constructor Details
#initialize ⇒ SystemFacts
Returns a new instance of SystemFacts.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/termy/system_facts.rb', line 8 def initialize @kernel = { "name" => uname[:sysname], "release" => uname[:release], "version" => uname[:version] } @arch = uname[:machine] @hostname = uname[:nodename] @domainname = uname[:domainname] end |
Instance Attribute Details
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
6 7 8 |
# File 'lib/termy/system_facts.rb', line 6 def arch @arch end |
#domainname ⇒ Object (readonly)
Returns the value of attribute domainname.
6 7 8 |
# File 'lib/termy/system_facts.rb', line 6 def domainname @domainname end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/termy/system_facts.rb', line 6 def hostname @hostname end |
#kernel ⇒ Object (readonly)
Returns the value of attribute kernel.
6 7 8 |
# File 'lib/termy/system_facts.rb', line 6 def kernel @kernel end |
Instance Method Details
#boot_id ⇒ Object
24 25 26 27 28 29 |
# File 'lib/termy/system_facts.rb', line 24 def boot_id f = File.open("/proc/sys/kernel/random/boot_id") data = f.read.strip f.close data end |
#date ⇒ Object
20 21 22 |
# File 'lib/termy/system_facts.rb', line 20 def date Time.now end |
#file_systems ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/termy/system_facts.rb', line 31 def file_systems file = "/etc/mtab" file_systems = {} return file_systems unless File.file?(file) f = File.open(file) f.read.scan(/.*\n/).each do |line| record = line.strip.split(" ") file_systems[record.first] = { "device" => record[0], "mount_point" => record[1], "type" => record[2], "options" => record[3].split(","), "dump_freq" => record[4], "pass_no" => record[5], } end f.close file_systems end |
#machine_id ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/termy/system_facts.rb', line 66 def machine_id file = "/etc/machine-id" return "" unless File.file?(file) f = File.open(file) machine_id = f.read.strip f.close machine_id end |
#network ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/termy/system_facts.rb', line 76 def network # TODO refactor this in the near future interfaces = {} System.get_all_ifaddrs.each do |info| key = info[:interface] if interfaces.has_key?(key) interfaces[key]["ip_addresses"] << info[:inet_addr].to_s if info[:inet_addr].ipv4? interfaces[key]["ipv4_adresses"] << { "ip" => info[:inet_addr].to_s, "netmask" => info[:netmask].to_s } elsif info[:inet_addr].ipv6? interfaces[key]["ipv6_adresses"] << { "ip" => info[:inet_addr].to_s, "netmask" => info[:netmask].to_s } end else interfaces[key] = { "name" => key, "ip_addresses" => [info[:inet_addr].to_s], "ipv4_adresses" => [], "ipv6_adresses" => [], } if info[:inet_addr].ipv4? interfaces[key]["ipv4_adresses"] << { "ip" => info[:inet_addr].to_s, "netmask" => info[:netmask].to_s } elsif info[:inet_addr].ipv6? interfaces[key]["ipv6_adresses"] << { "ip" => info[:inet_addr].to_s, "netmask" => info[:netmask].to_s } end end end interfaces end |
#os_release ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/termy/system_facts.rb', line 52 def os_release file = "/etc/os-release" os_release = {} return os_release unless File.file?(file) f = File.open(file) f.read.scan(/.*\n/).each do |line| key, val = line.split("=") os_release[key.downcase] = val.strip.gsub("\"","") end f.close os_release end |