Class: Facter::Operatingsystem::Linux

Inherits:
Base
  • Object
show all
Defined in:
lib/facter/operatingsystem/linux.rb

Direct Known Subclasses

CumulusLinux

Instance Method Summary collapse

Methods inherited from Base

#get_operatingsystemrelease_hash

Instance Method Details

#collect_lsb_informationObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/facter/operatingsystem/linux.rb', line 221

def collect_lsb_information
  @lsb_data ||= Facter::Core::Execution.exec("lsb_release -cidvr 2>/dev/null")
  @data_hash = {}

  if @lsb_data && @data_hash.empty?
    @lsb_data.split("\n").each do |element|
      lsbvar, value = element.split("\t")
      lsbvar.gsub!(":", "")
      @data_hash["#{lsbvar}"] = value
    end
  end

  @data_hash unless @data_hash.empty?
end

#get_lsb_facts_hashObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/facter/operatingsystem/linux.rb', line 189

def get_lsb_facts_hash
  lsb_hash = {}
  if lsbdistcodename = get_lsbdistcodename
    lsb_hash["distcodename"] = lsbdistcodename
  end

  if lsbdistid = get_lsbdistid
    lsb_hash["distid"] = lsbdistid
  end

  if lsbdistdescription = get_lsbdistdescription
    lsb_hash["distdescription"] = lsbdistdescription
  end

  if lsbrelease = get_lsbrelease
    lsb_hash["release"] = lsbrelease
  end

  if lsbdistrelease = get_lsbdistrelease
    lsb_hash["distrelease"] = lsbdistrelease
  end

  if lsbmajdistrelease = get_lsbmajdistrelease
    lsb_hash["majdistrelease"]  = lsbmajdistrelease
  end

  if lsbminordistrelease = get_lsbminordistrelease
    lsb_hash["minordistrelease"]  = lsbminordistrelease
  end
  lsb_hash
end

#get_lsbdistcodenameObject



119
120
121
122
123
# File 'lib/facter/operatingsystem/linux.rb', line 119

def get_lsbdistcodename
  if (lsb_data = collect_lsb_information)
    lsb_data["Codename"]
  end
end

#get_lsbdistdescriptionObject



131
132
133
134
135
# File 'lib/facter/operatingsystem/linux.rb', line 131

def get_lsbdistdescription
  if (lsb_data = collect_lsb_information)
    lsb_data["Description"].sub(/^"(.*)"$/,'\1')
  end
end

#get_lsbdistidObject



125
126
127
128
129
# File 'lib/facter/operatingsystem/linux.rb', line 125

def get_lsbdistid
  if (lsb_data = collect_lsb_information)
    lsb_data["Distributor ID"]
  end
end

#get_lsbdistreleaseObject



143
144
145
146
147
# File 'lib/facter/operatingsystem/linux.rb', line 143

def get_lsbdistrelease
  if (lsb_data = collect_lsb_information)
    lsb_data["Release"]
  end
end

#get_lsbmajdistreleaseObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/facter/operatingsystem/linux.rb', line 149

def get_lsbmajdistrelease
  lsbdistrelease = get_lsbdistrelease
  if get_operatingsystem == "Ubuntu"
    if (lsbreleasemajor = lsbdistrelease.split("."))
      if lsbreleasemajor.length >= 2
        result = "#{lsbreleasemajor[0]}.#{lsbreleasemajor[1]}"
      else
        result = lsbreleasemajor
      end
    end
  else
    if /(\d*)\./i =~ lsbdistrelease
      result = $1
    else
      result = lsbdistrelease
    end
  end
  result
end

#get_lsbminordistreleaseObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/facter/operatingsystem/linux.rb', line 169

def get_lsbminordistrelease
  lsbdistrelease = get_lsbdistrelease
  if get_operatingsystem == "Ubuntu"
    mdata = /(\d+).(\d+).(\d+)/i.match(lsbdistrelease)
    if mdata == nil
      result = nil
    else
      result = mdata[3]
    end
  else
    mdata = /(\d+).(\d+)/i.match(lsbdistrelease)
    if mdata == nil
      result = nil
    else
      result = mdata[2]
    end
  end
  result
end

#get_lsbreleaseObject



137
138
139
140
141
# File 'lib/facter/operatingsystem/linux.rb', line 137

def get_lsbrelease
  if (lsb_data = collect_lsb_information)
    lsb_data["LSB Version"]
  end
end

#get_operatingsystemObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/facter/operatingsystem/linux.rb', line 8

def get_operatingsystem
  if Facter.value(:kernel) == "GNU/kFreeBSD"
    "GNU/kFreeBSD"
  elsif lsbdistid = get_lsbdistid
    if lsbdistid == "Ubuntu"
      @operatingsystem ||= "Ubuntu"
    elsif lsbdistid == "LinuxMint"
      @operatingsystem ||= "LinuxMint"
    else
      @operatingsystem ||= get_operatingsystem_with_release_files
    end
  else
    @operatingsystem ||= get_operatingsystem_with_release_files
  end
end

#get_operatingsystemmajorreleaseObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/facter/operatingsystem/linux.rb', line 79

def get_operatingsystemmajorrelease
  if operatingsystemrelease = get_operatingsystemrelease
    if get_operatingsystem == "Ubuntu"
      if (releasemajor = operatingsystemrelease.split("."))
        if releasemajor.length >= 2
          "#{releasemajor[0]}.#{releasemajor[1]}"
        else
          releasemajor[0]
        end
      end
    else
      if (releasemajor = operatingsystemrelease.split(".")[0])
        releasemajor
      end
    end
  end
end

#get_operatingsystemminorreleaseObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/facter/operatingsystem/linux.rb', line 97

def get_operatingsystemminorrelease
  if operatingsystemrelease = get_operatingsystemrelease
    if get_operatingsystem == "Ubuntu"
      if (releaseminor = operatingsystemrelease.split(".")[2])
        releaseminor
      end
    else
      if (releaseminor = operatingsystemrelease.split(".")[1])
        if releaseminor.include? "-"
          releaseminor.split("-")[0]
        else
          releaseminor
        end
      end
    end
  end
end

#get_operatingsystemreleaseObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/facter/operatingsystem/linux.rb', line 43

def get_operatingsystemrelease
  case get_operatingsystem
  when "Alpine"
    get_alpine_release_with_release_file
  when "Amazon"
    get_amazon_release_with_lsb
  when "AristaEOS"
    get_arista_release_with_release_file
  when "BlueWhite64"
    get_bluewhite_release_with_release_file
  when "CentOS", "RedHat", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM",
       "XenServer", "Fedora", "MeeGo", "OracleLinux", "OEL", "oel", "OVS", "ovs"
    get_redhatish_release_with_release_file
  when "Debian"
    get_debian_release_with_release_file
  when "LinuxMint"
    get_linux_mint_release_with_release_file
  when "Mageia"
    get_mageia_release_with_release_file
  when "OpenWrt"
    get_openwrt_release_with_release_file
  when "Slackware"
    get_slackware_release_with_release_file
  when "Slamd64"
    get_slamd64_release_with_release_file
 when "SLES", "SLED", "OpenSuSE"
    get_suse_release_with_release_file
  when "Ubuntu"
    get_ubuntu_release_with_release_file
  when "VMwareESX"
    get_vmwareESX_release_with_release_file
  else
    Facter.value(:kernelrelease)
  end
end

#get_osfamilyObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/facter/operatingsystem/linux.rb', line 24

def get_osfamily
  case get_operatingsystem
  when "RedHat", "Fedora", "CentOS", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM", "OracleLinux", "OVS", "OEL", "Amazon", "XenServer"
    "RedHat"
  when "LinuxMint", "Ubuntu", "Debian"
    "Debian"
  when "SLES", "SLED", "OpenSuSE", "SuSE"
    "Suse"
  when "Gentoo"
    "Gentoo"
  when "Archlinux", "Manjarolinux"
    "Archlinux"
  when "Mageia", "Mandriva", "Mandrake"
    "Mandrake"
  else
    Facter.value("kernel")
  end
end

#has_lsb?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/facter/operatingsystem/linux.rb', line 115

def has_lsb?
  true
end