facter 2.1.0-x86-mingw32 → 2.2.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (139) hide show
  1. data/COMMITTERS.md +25 -34
  2. data/CONTRIBUTING.md +27 -5
  3. data/README.md +32 -0
  4. data/ext/build_defaults.yaml +1 -1
  5. data/ext/debian/control +3 -2
  6. data/ext/osx/file_mapping.yaml +5 -0
  7. data/ext/redhat/facter.spec.erb +4 -1
  8. data/lib/facter/Cfkey.rb +2 -2
  9. data/lib/facter/architecture.rb +2 -2
  10. data/lib/facter/augeasversion.rb +2 -2
  11. data/lib/facter/blockdevices.rb +12 -12
  12. data/lib/facter/dhcp_servers.rb +4 -4
  13. data/lib/facter/domain.rb +4 -4
  14. data/lib/facter/ec2.rb +17 -0
  15. data/lib/facter/ec2/rest.rb +2 -2
  16. data/lib/facter/facterversion.rb +2 -2
  17. data/lib/facter/filesystems.rb +10 -3
  18. data/lib/facter/fqdn.rb +1 -1
  19. data/lib/facter/gid.rb +16 -0
  20. data/lib/facter/hardwareisa.rb +3 -3
  21. data/lib/facter/hardwaremodel.rb +3 -3
  22. data/lib/facter/hostname.rb +1 -1
  23. data/lib/facter/id.rb +4 -4
  24. data/lib/facter/interfaces.rb +3 -0
  25. data/lib/facter/ipaddress6.rb +9 -9
  26. data/lib/facter/kernel.rb +2 -2
  27. data/lib/facter/kernelmajversion.rb +2 -2
  28. data/lib/facter/kernelrelease.rb +4 -4
  29. data/lib/facter/kernelversion.rb +3 -3
  30. data/lib/facter/ldom.rb +11 -0
  31. data/lib/facter/lsbdistcodename.rb +8 -4
  32. data/lib/facter/lsbdistdescription.rb +6 -10
  33. data/lib/facter/lsbdistid.rb +8 -4
  34. data/lib/facter/lsbdistrelease.rb +8 -4
  35. data/lib/facter/lsbmajdistrelease.rb +7 -12
  36. data/lib/facter/lsbminordistrelease.rb +22 -0
  37. data/lib/facter/lsbrelease.rb +8 -4
  38. data/lib/facter/macaddress.rb +1 -0
  39. data/lib/facter/macosx.rb +1 -1
  40. data/lib/facter/manufacturer.rb +3 -3
  41. data/lib/facter/memory.rb +8 -8
  42. data/lib/facter/netmask.rb +2 -1
  43. data/lib/facter/network.rb +3 -3
  44. data/lib/facter/operatingsystem.rb +9 -126
  45. data/lib/facter/operatingsystem/base.rb +61 -0
  46. data/lib/facter/operatingsystem/cumuluslinux.rb +27 -0
  47. data/lib/facter/operatingsystem/implementation.rb +30 -0
  48. data/lib/facter/operatingsystem/linux.rb +467 -0
  49. data/lib/facter/operatingsystem/sunos.rb +54 -0
  50. data/lib/facter/operatingsystem/vmkernel.rb +11 -0
  51. data/lib/facter/operatingsystem/windows.rb +37 -0
  52. data/lib/facter/operatingsystemmajrelease.rb +14 -33
  53. data/lib/facter/operatingsystemrelease.rb +14 -235
  54. data/lib/facter/os.rb +69 -0
  55. data/lib/facter/osfamily.rb +4 -23
  56. data/lib/facter/partitions.rb +4 -3
  57. data/lib/facter/path.rb +2 -2
  58. data/lib/facter/physicalprocessorcount.rb +10 -74
  59. data/lib/facter/processor.rb +13 -129
  60. data/lib/facter/processors.rb +60 -0
  61. data/lib/facter/processors/os.rb +234 -0
  62. data/lib/facter/ps.rb +5 -4
  63. data/lib/facter/puppetversion.rb +1 -1
  64. data/lib/facter/rackspace.rb +34 -0
  65. data/lib/facter/rubysitedir.rb +3 -0
  66. data/lib/facter/rubyversion.rb +2 -2
  67. data/lib/facter/selinux.rb +57 -2
  68. data/lib/facter/ssh.rb +1 -0
  69. data/lib/facter/system_uptime.rb +42 -0
  70. data/lib/facter/timezone.rb +1 -1
  71. data/lib/facter/uptime.rb +5 -23
  72. data/lib/facter/uptime_days.rb +4 -6
  73. data/lib/facter/uptime_hours.rb +4 -6
  74. data/lib/facter/uptime_seconds.rb +5 -9
  75. data/lib/facter/util/formatter.rb +1 -1
  76. data/lib/facter/util/manufacturer.rb +1 -1
  77. data/lib/facter/util/partitions.rb +3 -1
  78. data/lib/facter/util/partitions/linux.rb +1 -1
  79. data/lib/facter/util/partitions/openbsd.rb +35 -0
  80. data/lib/facter/util/uptime.rb +4 -3
  81. data/lib/facter/util/virtual.rb +3 -1
  82. data/lib/facter/util/xendomains.rb +12 -3
  83. data/lib/facter/version.rb +1 -1
  84. data/lib/facter/virtual.rb +24 -23
  85. data/lib/facter/vlans.rb +1 -1
  86. data/lib/facter/xendomains.rb +1 -1
  87. data/lib/facter/zfs_version.rb +6 -2
  88. data/lib/facter/zones.rb +6 -5
  89. data/lib/facter/zpool_version.rb +1 -1
  90. data/spec/fixtures/cpuinfo/amd64dual-grep +2 -0
  91. data/spec/fixtures/cpuinfo/amd64twentyfour-grep +24 -0
  92. data/spec/fixtures/cpuinfo/two_multicore-grep +4 -0
  93. data/spec/fixtures/cpuinfo/two_singlecore-grep +2 -0
  94. data/spec/fixtures/unit/processors/os/darwin-system-profiler +287 -0
  95. data/spec/fixtures/unit/zfs_version/zfs_new +61 -0
  96. data/spec/fixtures/unit/zfs_version/zfs_old +43 -0
  97. data/spec/fixtures/unit/zfs_version/zfsonlinux_0.6.1 +13 -0
  98. data/spec/fixtures/unit/zpool_version/zfsonlinux_0.6.1 +48 -0
  99. data/spec/unit/ec2/rest_spec.rb +6 -6
  100. data/spec/unit/gid_spec.rb +22 -0
  101. data/spec/unit/hardwaremodel_spec.rb +2 -0
  102. data/spec/unit/lsbdistcodename_spec.rb +22 -17
  103. data/spec/unit/lsbdistdescription_spec.rb +22 -17
  104. data/spec/unit/lsbdistid_spec.rb +23 -18
  105. data/spec/unit/lsbdistrelease_spec.rb +22 -17
  106. data/spec/unit/lsbmajdistrelease_spec.rb +23 -6
  107. data/spec/unit/lsbminordistrelease_spec.rb +31 -0
  108. data/spec/unit/lsbrelease_spec.rb +22 -17
  109. data/spec/unit/macaddress_spec.rb +3 -0
  110. data/spec/unit/operatingsystem/base_spec.rb +76 -0
  111. data/spec/unit/operatingsystem/cumuluslinux_spec.rb +40 -0
  112. data/spec/unit/operatingsystem/implementation_spec.rb +49 -0
  113. data/spec/unit/operatingsystem/linux_spec.rb +538 -0
  114. data/spec/unit/operatingsystem/sunos_spec.rb +144 -0
  115. data/spec/unit/operatingsystem/vmkernel_spec.rb +13 -0
  116. data/spec/unit/operatingsystem/windows_spec.rb +68 -0
  117. data/spec/unit/operatingsystem_spec.rb +10 -153
  118. data/spec/unit/operatingsystemmajrelease_spec.rb +14 -31
  119. data/spec/unit/operatingsystemrelease_spec.rb +13 -229
  120. data/spec/unit/os_spec.rb +131 -0
  121. data/spec/unit/osfamily_spec.rb +9 -54
  122. data/spec/unit/partitions_spec.rb +41 -3
  123. data/spec/unit/physicalprocessorcount_spec.rb +6 -78
  124. data/spec/unit/processor_spec.rb +18 -381
  125. data/spec/unit/processors/os_spec.rb +446 -0
  126. data/spec/unit/processors_spec.rb +203 -0
  127. data/spec/unit/rackspace_spec.rb +40 -0
  128. data/spec/unit/system_uptime_spec.rb +80 -0
  129. data/spec/unit/util/formatter_spec.rb +5 -0
  130. data/spec/unit/util/macaddress_spec.rb +2 -0
  131. data/spec/unit/util/processor_spec.rb +120 -0
  132. data/spec/unit/util/uptime_spec.rb +3 -4
  133. data/spec/unit/util/virtual_spec.rb +8 -0
  134. data/spec/unit/util/xendomains_spec.rb +54 -9
  135. data/spec/unit/virtual_spec.rb +8 -1
  136. data/spec/unit/zfs_version_spec.rb +20 -8
  137. data/spec/unit/zpool_version_spec.rb +5 -0
  138. metadata +660 -589
  139. checksums.yaml +0 -7
@@ -2,10 +2,11 @@
2
2
  #
3
3
  # Purpose: Returns the netmask for the main interfaces.
4
4
  #
5
- # Resolution: Uses the facter/util/netmask library routines.
5
+ # Resolution: Uses the `facter/util/netmask` library routines.
6
6
  #
7
7
  # Caveats:
8
8
  #
9
+
9
10
  # netmask.rb
10
11
  # Find the netmask of the primary ipaddress
11
12
  # Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
@@ -1,11 +1,11 @@
1
1
  # Fact: network
2
2
  #
3
3
  # Purpose:
4
- # Get IP, network and netmask information for available network
5
- # interfacs.
4
+ # Get IP, network, and netmask information for available network
5
+ # interfaces.
6
6
  #
7
7
  # Resolution:
8
- # Uses 'facter/util/ip' to enumerate interfaces and return their information.
8
+ # Uses `facter/util/ip` to enumerate interfaces and return their information.
9
9
  #
10
10
  # Caveats:
11
11
  #
@@ -3,139 +3,22 @@
3
3
  # Purpose: Return the name of the operating system.
4
4
  #
5
5
  # Resolution:
6
+ # Uses the name key of the os structured fact, which itself
7
+ # operates on the following conditions:
8
+ #
9
+ #
6
10
  # If the kernel is a Linux kernel, check for the existence of a selection of
7
- # files in /etc/ to find the specific flavour.
11
+ # files in `/etc/` to find the specific flavour.
8
12
  # On SunOS based kernels, attempt to determine the flavour, otherwise return Solaris.
9
- # On systems other than Linux, use the kernel value.
13
+ # On systems other than Linux, use the kernel fact's value.
10
14
  #
11
15
  # Caveats:
12
16
  #
13
17
 
14
- require 'facter/util/operatingsystem'
15
-
16
- Facter.add(:operatingsystem) do
17
- confine :kernel => :sunos
18
- setcode do
19
- # Use uname -v because /etc/release can change in zones under SmartOS.
20
- # It's apparently not trustworthy enough to rely on for this fact.
21
- output = Facter::Core::Execution.exec('uname -v')
22
- if output =~ /^joyent_/
23
- "SmartOS"
24
- elsif output =~ /^oi_/
25
- "OpenIndiana"
26
- elsif output =~ /^omnios-/
27
- "OmniOS"
28
- elsif FileTest.exists?("/etc/debian_version")
29
- "Nexenta"
30
- else
31
- "Solaris"
32
- end
33
- end
34
- end
35
-
36
- Facter.add(:operatingsystem) do
37
- # Cumulus Linux is a variant of Debian so this resolution needs to come
38
- # before the Debian resolution.
39
- has_weight(10)
40
- confine :kernel => :linux
41
-
42
- setcode do
43
- release_info = Facter::Util::Operatingsystem.os_release
44
- if release_info['NAME'] == "Cumulus Linux"
45
- 'CumulusLinux'
46
- end
47
- end
48
- end
49
-
50
18
  Facter.add(:operatingsystem) do
51
- confine :kernel => :linux
52
- setcode do
53
- if Facter.value(:lsbdistid) == "Ubuntu"
54
- "Ubuntu"
55
- elsif Facter.value(:lsbdistid) == "LinuxMint"
56
- "LinuxMint"
57
- elsif FileTest.exists?("/etc/debian_version")
58
- "Debian"
59
- elsif FileTest.exists?("/etc/openwrt_release")
60
- "OpenWrt"
61
- elsif FileTest.exists?("/etc/gentoo-release")
62
- "Gentoo"
63
- elsif FileTest.exists?("/etc/fedora-release")
64
- "Fedora"
65
- elsif FileTest.exists?("/etc/mageia-release")
66
- "Mageia"
67
- elsif FileTest.exists?("/etc/mandriva-release")
68
- "Mandriva"
69
- elsif FileTest.exists?("/etc/mandrake-release")
70
- "Mandrake"
71
- elsif FileTest.exists?("/etc/meego-release")
72
- "MeeGo"
73
- elsif FileTest.exists?("/etc/arch-release")
74
- "Archlinux"
75
- elsif FileTest.exists?("/etc/oracle-release")
76
- "OracleLinux"
77
- elsif FileTest.exists?("/etc/enterprise-release")
78
- if FileTest.exists?("/etc/ovs-release")
79
- "OVS"
80
- else
81
- "OEL"
82
- end
83
- elsif FileTest.exists?("/etc/vmware-release")
84
- "VMWareESX"
85
- elsif FileTest.exists?("/etc/redhat-release")
86
- txt = File.read("/etc/redhat-release")
87
- if txt =~ /centos/i
88
- "CentOS"
89
- elsif txt =~ /CERN/
90
- "SLC"
91
- elsif txt =~ /scientific/i
92
- "Scientific"
93
- elsif txt =~ /^cloudlinux/i
94
- "CloudLinux"
95
- elsif txt =~ /^Parallels Server Bare Metal/i
96
- "PSBM"
97
- elsif txt =~ /Ascendos/i
98
- "Ascendos"
99
- elsif txt =~ /^XenServer/i
100
- "XenServer"
101
- else
102
- "RedHat"
103
- end
104
- elsif FileTest.exists?("/etc/SuSE-release")
105
- txt = File.read("/etc/SuSE-release")
106
- if txt =~ /^SUSE LINUX Enterprise Server/i
107
- "SLES"
108
- elsif txt =~ /^SUSE LINUX Enterprise Desktop/i
109
- "SLED"
110
- elsif txt =~ /^openSUSE/i
111
- "OpenSuSE"
112
- else
113
- "SuSE"
114
- end
115
- elsif FileTest.exists?("/etc/bluewhite64-version")
116
- "Bluewhite64"
117
- elsif FileTest.exists?("/etc/slamd64-version")
118
- "Slamd64"
119
- elsif FileTest.exists?("/etc/slackware-version")
120
- "Slackware"
121
- elsif FileTest.exists?("/etc/alpine-release")
122
- "Alpine"
123
- elsif FileTest.exists?("/etc/mageia-release")
124
- "Mageia"
125
- elsif FileTest.exists?("/etc/system-release")
126
- "Amazon"
127
- end
19
+ confine do
20
+ !Facter.value("os")["name"].nil?
128
21
  end
129
- end
130
22
 
131
- Facter.add(:operatingsystem) do
132
- confine :kernel => "VMkernel"
133
- setcode do
134
- "ESXi"
135
- end
136
- end
137
-
138
- Facter.add(:operatingsystem) do
139
- # Default to just returning the kernel as the operating system
140
- setcode do Facter[:kernel].value end
23
+ setcode { Facter.value("os")["name"] }
141
24
  end
@@ -0,0 +1,61 @@
1
+ require 'facter/util/operatingsystem'
2
+
3
+ module Facter
4
+ module Operatingsystem
5
+ class Base
6
+ def get_operatingsystem
7
+ @operatingsystem ||= Facter.value(:kernel)
8
+ @operatingsystem
9
+ end
10
+
11
+ def get_osfamily
12
+ Facter.value(:kernel)
13
+ end
14
+
15
+ def get_operatingsystemrelease
16
+ @operatingsystemrelease = Facter.value(:kernelrelease)
17
+ @operatingsystemrelease
18
+ end
19
+
20
+ def get_operatingsystemmajorrelease
21
+ if operatingsystemrelease = get_operatingsystemrelease
22
+ if (releasemajor = operatingsystemrelease.split(".")[0])
23
+ releasemajor
24
+ end
25
+ end
26
+ end
27
+
28
+ def get_operatingsystemminorrelease
29
+ if operatingsystemrelease = get_operatingsystemrelease
30
+ if (releaseminor = operatingsystemrelease.split(".")[1])
31
+ if releaseminor.include? "-"
32
+ releaseminor.split("-")[0]
33
+ else
34
+ releaseminor
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def get_operatingsystemrelease_hash
41
+ release_hash = {}
42
+ if releasemajor = get_operatingsystemmajorrelease
43
+ release_hash["major"] = releasemajor
44
+ end
45
+
46
+ if releaseminor = get_operatingsystemminorrelease
47
+ release_hash["minor"] = releaseminor
48
+ end
49
+
50
+ if release = get_operatingsystemrelease
51
+ release_hash["full"] = release
52
+ end
53
+ release_hash
54
+ end
55
+
56
+ def has_lsb?
57
+ false
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ require 'facter/util/operatingsystem'
2
+ require 'facter/operatingsystem/linux'
3
+
4
+ module Facter
5
+ module Operatingsystem
6
+ class CumulusLinux < Linux
7
+ def get_operatingsystem
8
+ "CumulusLinux"
9
+ end
10
+
11
+ def get_osfamily
12
+ "Debian"
13
+ end
14
+
15
+ def get_operatingsystemrelease
16
+ @operatingsystemrelease ||= Facter::Util::Operatingsystem.os_release['VERSION_ID']
17
+ @operatingsystemrelease
18
+ end
19
+
20
+ def get_operatingsystemmajrelease
21
+ if operatingsystemrelease = get_operatingsystemrelease
22
+ operatingsystemrelease.split(".").first
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ require 'facter/operatingsystem/base'
2
+ require 'facter/operatingsystem/cumuluslinux'
3
+ require 'facter/operatingsystem/linux'
4
+ require 'facter/operatingsystem/sunos'
5
+ require 'facter/operatingsystem/vmkernel'
6
+ require 'facter/operatingsystem/windows'
7
+
8
+ module Facter
9
+ module Operatingsystem
10
+ def self.implementation(kernel = Facter.value(:kernel))
11
+ case kernel
12
+ when "Linux", "GNU/kFreeBSD"
13
+ release_info = Facter::Util::Operatingsystem.os_release
14
+ if release_info['NAME'] == "Cumulus Linux"
15
+ Facter::Operatingsystem::CumulusLinux.new
16
+ else
17
+ Facter::Operatingsystem::Linux.new
18
+ end
19
+ when "SunOS"
20
+ Facter::Operatingsystem::SunOS.new
21
+ when "VMkernel"
22
+ Facter::Operatingsystem::VMkernel.new
23
+ when "windows"
24
+ Facter::Operatingsystem::Windows.new
25
+ else
26
+ Facter::Operatingsystem::Base.new
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,467 @@
1
+ require 'facter/util/file_read'
2
+ require 'facter/util/operatingsystem'
3
+ require 'facter/operatingsystem/base'
4
+
5
+ module Facter
6
+ module Operatingsystem
7
+ class Linux < Base
8
+ def get_operatingsystem
9
+ if Facter.value(:kernel) == "GNU/kFreeBSD"
10
+ "GNU/kFreeBSD"
11
+ elsif lsbdistid = get_lsbdistid
12
+ if lsbdistid == "Ubuntu"
13
+ @operatingsystem ||= "Ubuntu"
14
+ elsif lsbdistid == "LinuxMint"
15
+ @operatingsystem ||= "LinuxMint"
16
+ else
17
+ @operatingsystem ||= get_operatingsystem_with_release_files
18
+ end
19
+ else
20
+ @operatingsystem ||= get_operatingsystem_with_release_files
21
+ end
22
+ end
23
+
24
+ def get_osfamily
25
+ case get_operatingsystem
26
+ when "RedHat", "Fedora", "CentOS", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM", "OracleLinux", "OVS", "OEL", "Amazon", "XenServer"
27
+ "RedHat"
28
+ when "LinuxMint", "Ubuntu", "Debian"
29
+ "Debian"
30
+ when "SLES", "SLED", "OpenSuSE", "SuSE"
31
+ "Suse"
32
+ when "Gentoo"
33
+ "Gentoo"
34
+ when "Archlinux"
35
+ "Archlinux"
36
+ when "Mageia", "Mandriva", "Mandrake"
37
+ "Mandrake"
38
+ else
39
+ Facter.value("kernel")
40
+ end
41
+ end
42
+
43
+ def get_operatingsystemrelease
44
+ case get_operatingsystem
45
+ when "Alpine"
46
+ get_alpine_release_with_release_file
47
+ when "Amazon"
48
+ get_amazon_release_with_lsb
49
+ when "BlueWhite64"
50
+ get_bluewhite_release_with_release_file
51
+ when "CentOS", "RedHat", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM",
52
+ "XenServer", "Fedora", "MeeGo", "OracleLinux", "OEL", "oel", "OVS", "ovs"
53
+ get_redhatish_release_with_release_file
54
+ when "Debian"
55
+ get_debian_release_with_release_file
56
+ when "LinuxMint"
57
+ get_linux_mint_release_with_release_file
58
+ when "Mageia"
59
+ get_mageia_release_with_release_file
60
+ when "OpenWrt"
61
+ get_openwrt_release_with_release_file
62
+ when "Slackware"
63
+ get_slackware_release_with_release_file
64
+ when "Slamd64"
65
+ get_slamd64_release_with_release_file
66
+ when "SLES", "SLED", "OpenSuSE"
67
+ get_suse_release_with_release_file
68
+ when "Ubuntu"
69
+ get_ubuntu_release_with_release_file
70
+ when "VMwareESX"
71
+ get_vmwareESX_release_with_release_file
72
+ else
73
+ Facter.value(:kernelrelease)
74
+ end
75
+ end
76
+
77
+ def get_operatingsystemmajorrelease
78
+ if operatingsystemrelease = get_operatingsystemrelease
79
+ if get_operatingsystem == "Ubuntu"
80
+ if (releasemajor = operatingsystemrelease.split("."))
81
+ if releasemajor.length >= 2
82
+ "#{releasemajor[0]}.#{releasemajor[1]}"
83
+ else
84
+ releasemajor[0]
85
+ end
86
+ end
87
+ else
88
+ if (releasemajor = operatingsystemrelease.split(".")[0])
89
+ releasemajor
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ def get_operatingsystemminorrelease
96
+ if operatingsystemrelease = get_operatingsystemrelease
97
+ if get_operatingsystem == "Ubuntu"
98
+ if (releaseminor = operatingsystemrelease.split(".")[2])
99
+ releaseminor
100
+ end
101
+ else
102
+ if (releaseminor = operatingsystemrelease.split(".")[1])
103
+ if releaseminor.include? "-"
104
+ releaseminor.split("-")[0]
105
+ else
106
+ releaseminor
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ def has_lsb?
114
+ true
115
+ end
116
+
117
+ def get_lsbdistcodename
118
+ if (lsb_data = collect_lsb_information)
119
+ lsb_data["Codename"]
120
+ end
121
+ end
122
+
123
+ def get_lsbdistid
124
+ if (lsb_data = collect_lsb_information)
125
+ lsb_data["Distributor ID"]
126
+ end
127
+ end
128
+
129
+ def get_lsbdistdescription
130
+ if (lsb_data = collect_lsb_information)
131
+ lsb_data["Description"].sub(/^"(.*)"$/,'\1')
132
+ end
133
+ end
134
+
135
+ def get_lsbrelease
136
+ if (lsb_data = collect_lsb_information)
137
+ lsb_data["LSB Version"]
138
+ end
139
+ end
140
+
141
+ def get_lsbdistrelease
142
+ if (lsb_data = collect_lsb_information)
143
+ lsb_data["Release"]
144
+ end
145
+ end
146
+
147
+ def get_lsbmajdistrelease
148
+ lsbdistrelease = get_lsbdistrelease
149
+ if get_operatingsystem == "Ubuntu"
150
+ if (lsbreleasemajor = lsbdistrelease.split("."))
151
+ if lsbreleasemajor.length >= 2
152
+ result = "#{lsbreleasemajor[0]}.#{lsbreleasemajor[1]}"
153
+ else
154
+ result = lsbreleasemajor
155
+ end
156
+ end
157
+ else
158
+ if /(\d*)\./i =~ lsbdistrelease
159
+ result = $1
160
+ else
161
+ result = lsbdistrelease
162
+ end
163
+ end
164
+ result
165
+ end
166
+
167
+ def get_lsbminordistrelease
168
+ lsbdistrelease = get_lsbdistrelease
169
+ if get_operatingsystem == "Ubuntu"
170
+ mdata = /(\d+).(\d+).(\d+)/i.match(lsbdistrelease)
171
+ if mdata == nil
172
+ result = nil
173
+ else
174
+ result = mdata[3]
175
+ end
176
+ else
177
+ mdata = /(\d+).(\d+)/i.match(lsbdistrelease)
178
+ if mdata == nil
179
+ result = nil
180
+ else
181
+ result = mdata[2]
182
+ end
183
+ end
184
+ result
185
+ end
186
+
187
+ def get_lsb_facts_hash
188
+ lsb_hash = {}
189
+ if lsbdistcodename = get_lsbdistcodename
190
+ lsb_hash["distcodename"] = lsbdistcodename
191
+ end
192
+
193
+ if lsbdistid = get_lsbdistid
194
+ lsb_hash["distid"] = lsbdistid
195
+ end
196
+
197
+ if lsbdistdescription = get_lsbdistdescription
198
+ lsb_hash["distdescription"] = lsbdistdescription
199
+ end
200
+
201
+ if lsbrelease = get_lsbrelease
202
+ lsb_hash["release"] = lsbrelease
203
+ end
204
+
205
+ if lsbdistrelease = get_lsbdistrelease
206
+ lsb_hash["distrelease"] = lsbdistrelease
207
+ end
208
+
209
+ if lsbmajdistrelease = get_lsbmajdistrelease
210
+ lsb_hash["majdistrelease"] = lsbmajdistrelease
211
+ end
212
+
213
+ if lsbminordistrelease = get_lsbminordistrelease
214
+ lsb_hash["minordistrelease"] = lsbminordistrelease
215
+ end
216
+ lsb_hash
217
+ end
218
+
219
+ def collect_lsb_information
220
+ @lsb_data ||= Facter::Core::Execution.exec("lsb_release -cidvr 2>/dev/null")
221
+ @data_hash = {}
222
+
223
+ if @lsb_data && @data_hash.empty?
224
+ @lsb_data.split("\n").each do |element|
225
+ lsbvar, value = element.split("\t")
226
+ lsbvar.gsub!(":", "")
227
+ @data_hash["#{lsbvar}"] = value
228
+ end
229
+ end
230
+
231
+ @data_hash unless @data_hash.empty?
232
+ end
233
+
234
+ private
235
+
236
+ # Sequentially searches the filesystem for the existence of a release file
237
+ #
238
+ # @return [String, NilClass]
239
+ def get_operatingsystem_with_release_files
240
+ operatingsystem = nil
241
+ release_files = {
242
+ "Debian" => "/etc/debian_version",
243
+ "Gentoo" => "/etc/gentoo-release",
244
+ "Fedora" => "/etc/fedora-release",
245
+ "Mageia" => "/etc/mageia-release",
246
+ "Mandriva" => "/etc/mandriva-release",
247
+ "Mandrake" => "/etc/mandrake-release",
248
+ "MeeGo" => "/etc/meego-release",
249
+ "Archlinux" => "/etc/arch-release",
250
+ "OracleLinux" => "/etc/oracle-release",
251
+ "OpenWrt" => "/etc/openwrt_release",
252
+ "Alpine" => "/etc/alpine-release",
253
+ "VMWareESX" => "/etc/vmware-release",
254
+ "Bluewhite64" => "/etc/bluewhite64-version",
255
+ "Slamd64" => "/etc/slamd64-version",
256
+ "Slackware" => "/etc/slackware-version"
257
+ }
258
+
259
+ release_files.each do |os, releasefile|
260
+ if FileTest.exists?(releasefile)
261
+ operatingsystem = os
262
+ end
263
+ end
264
+
265
+ unless operatingsystem
266
+ if FileTest.exists?("/etc/enterprise-release")
267
+ if FileTest.exists?("/etc/ovs-release")
268
+ operatingsystem = "OVS"
269
+ else
270
+ operatingsystem = "OEL"
271
+ end
272
+ elsif FileTest.exists?("/etc/redhat-release")
273
+ operatingsystem = get_redhat_operatingsystem_name
274
+ elsif FileTest.exists?("/etc/SuSE-release")
275
+ operatingsystem = get_suse_operatingsystem_name
276
+ elsif FileTest.exists?("/etc/system-release")
277
+ operatingsystem = "Amazon"
278
+ end
279
+ end
280
+
281
+ operatingsystem
282
+ end
283
+
284
+ # Uses a regex search on /etc/redhat-release to determine OS
285
+ #
286
+ # @return [String]
287
+ def get_redhat_operatingsystem_name
288
+ txt = File.read("/etc/redhat-release")
289
+ matches = {
290
+ "CentOS" => "centos",
291
+ "Scientific" => "Scientific",
292
+ "CloudLinux" => "^cloudlinux",
293
+ "PSBM" => "^Parallels Server Bare Metal",
294
+ "Ascendos" => "Ascendos",
295
+ "XenServer" => "^XenServer",
296
+ "XCP" => "XCP"
297
+ }
298
+
299
+ if txt =~ /CERN/
300
+ "SLC"
301
+ else
302
+ match = regex_search_release_file_for_operatingsystem(matches, txt)
303
+ match = "RedHat" if match == nil
304
+
305
+ match
306
+ end
307
+ end
308
+
309
+ # Uses a regex search on /etc/SuSE-release to determine OS
310
+ #
311
+ # @return [String]
312
+ def get_suse_operatingsystem_name
313
+ txt = File.read("/etc/SuSE-release")
314
+ matches = {
315
+ "SLES" => "^SUSE LINUX Enterprise Server",
316
+ "SLED" => "^SUSE LINUX Enterprise Desktop",
317
+ "OpenSuSE" => "^openSUSE"
318
+ }
319
+ match = regex_search_release_file_for_operatingsystem(matches, txt)
320
+ match = "SuSE" if match == nil
321
+
322
+ match
323
+ end
324
+
325
+ # Iterates over potential matches from a hash argument and returns
326
+ # result of search
327
+ #
328
+ # @return [String, NilClass]
329
+ def regex_search_release_file_for_operatingsystem(regex_os_hash, filecontent)
330
+ match = nil
331
+ regex_os_hash.each do |os, regex|
332
+ match = os if filecontent =~ /#{regex}/i
333
+ end
334
+
335
+ match
336
+ end
337
+
338
+ # Read release files to determine operatingsystemrelease
339
+ #
340
+ # @return [String]
341
+ def get_alpine_release_with_release_file
342
+ if release = Facter::Util::FileRead.read('/etc/alpine-release')
343
+ release.sub!(/\s*$/, '')
344
+ release
345
+ end
346
+ end
347
+
348
+ def get_amazon_release_with_lsb
349
+ if lsbdistrelease = get_lsbdistrelease
350
+ lsbdistrelease
351
+ else
352
+ if release = Facter::Util::FileRead.read('/etc/system-release')
353
+ if match = /\d+\.\d+/.match(release)
354
+ match[0]
355
+ end
356
+ end
357
+ end
358
+ end
359
+
360
+ def get_bluewhite_release_with_release_file
361
+ if release = Facter::Util::FileRead.read('/etc/bluewhite64-version')
362
+ if match = /^\s*\w+\s+(\d+)\.(\d+)/.match(release)
363
+ match[1] + "." + match[2]
364
+ else
365
+ "unknown"
366
+ end
367
+ end
368
+ end
369
+
370
+ def get_redhatish_release_with_release_file
371
+ case get_operatingsystem
372
+ when "CentOS", "RedHat", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM", "XenServer"
373
+ releasefile = "/etc/redhat-release"
374
+ when "Fedora"
375
+ releasefile = "/etc/fedora-release"
376
+ when "MeeGo"
377
+ releasefile = "/etc/meego-release"
378
+ when "OracleLinux"
379
+ releasefile = "/etc/oracle-release"
380
+ when "OEL", "oel"
381
+ releasefile = "/etc/enterprise-release"
382
+ when "OVS", "ovs"
383
+ releasefile = "/etc/ovs-release"
384
+ end
385
+
386
+ if release = Facter::Util::FileRead.read(releasefile)
387
+ line = release.split("\n").first.chomp
388
+ if match = /\(Rawhide\)$/.match(line)
389
+ "Rawhide"
390
+ elsif match = /release (\d[\d.]*)/.match(line)
391
+ match[1]
392
+ end
393
+ end
394
+ end
395
+
396
+ def get_debian_release_with_release_file
397
+ if release = Facter::Util::FileRead.read('/etc/debian_version')
398
+ release.sub!(/\s*$/, '')
399
+ release
400
+ end
401
+ end
402
+
403
+ def get_linux_mint_release_with_release_file
404
+ regex_search_releasefile_for_release(/RELEASE\=(\d+)/, "/etc/linuxmint/info")
405
+ end
406
+
407
+ def get_mageia_release_with_release_file
408
+ regex_search_releasefile_for_release(/Mageia release ([0-9.]+)/, "/etc/mageia-release")
409
+ end
410
+
411
+ def get_openwrt_release_with_release_file
412
+ regex_search_releasefile_for_release(/^(\d+\.\d+.*)/, "/etc/openwrt_version")
413
+ end
414
+
415
+ def get_slackware_release_with_release_file
416
+ regex_search_releasefile_for_release(/Slackware ([0-9.]+)/, "/etc/slackware-version")
417
+ end
418
+
419
+ def get_slamd64_release_with_release_file
420
+ regex_search_releasefile_for_release(/^\s*\w+\s+(\d+)\.(\d+)/, "/etc/slamd64-version")
421
+ end
422
+
423
+ def get_ubuntu_release_with_release_file
424
+ if release = Facter::Util::FileRead.read('/etc/lsb-release')
425
+ if match = release.match(/DISTRIB_RELEASE=((\d+.\d+)(\.(\d+))?)/)
426
+ # Return only the major and minor version numbers. This behavior must
427
+ # be preserved for compatibility reasons.
428
+ match[2]
429
+ end
430
+ end
431
+ end
432
+
433
+ def get_vmwareESX_release_with_release_file
434
+ release = Facter::Core::Execution.exec('vmware -v')
435
+ if match = /VMware ESX .*?(\d.*)/.match(release)
436
+ match[1]
437
+ end
438
+ end
439
+
440
+ def get_suse_release_with_release_file
441
+ if release = Facter::Util::FileRead.read('/etc/SuSE-release')
442
+ if match = /^VERSION\s*=\s*(\d+)/.match(release)
443
+ releasemajor = match[1]
444
+ if match = /^PATCHLEVEL\s*=\s*(\d+)/.match(release)
445
+ releaseminor = match[1]
446
+ elsif match = /^VERSION\s=.*.(\d+)/.match(release)
447
+ releaseminor = match[1]
448
+ else
449
+ releaseminor = "0"
450
+ end
451
+ releasemajor + "." + releaseminor
452
+ else
453
+ "unknown"
454
+ end
455
+ end
456
+ end
457
+
458
+ def regex_search_releasefile_for_release(regex, releasefile)
459
+ if release = Facter::Util::FileRead.read(releasefile)
460
+ if match = release.match(regex)
461
+ match[1]
462
+ end
463
+ end
464
+ end
465
+ end
466
+ end
467
+ end