rfacter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,591 @@
1
+ Facter.add(:os, :type => :aggregate) do
2
+ chunk(:name) do
3
+ {'name' => Facter.value(:kernel)}
4
+ end
5
+
6
+ chunk(:family) do
7
+ {'family' => Facter.value(:kernel)}
8
+ end
9
+
10
+ chunk(:architecture) do
11
+ arch = Facter::Core::Execution.execute('uname -m')
12
+
13
+ {
14
+ 'architecture' => arch,
15
+ 'hardware' => arch
16
+ }
17
+ end
18
+
19
+ chunk(:release) do
20
+ release_info = {
21
+ 'full' => Facter.value(:kernelrelease),
22
+ 'major' => Facter.value(:kernelrelease).split('.')[0],
23
+ 'minor' => Facter.value(:kernelrelease).split('.')[1]
24
+ }
25
+
26
+ {'release' => release_info.reject{|_, v| v.nil?}}
27
+ end
28
+ end
29
+
30
+ Facter.add(:os, :type => :aggregate) do
31
+ confine :kernel => 'linux'
32
+
33
+ chunk(:name) do
34
+ # TODO: Much of this code was imported from facter/operatingsystem/linux.rb
35
+ # from Facter 2.4.6. Facter 3 uses the same sort of logic, but tests files
36
+ # in a different order. Should cross check this to make sure there haven't
37
+ # been important changes to order or additions.
38
+
39
+ # NOTE: Can assume that the transport layer caches the results of File
40
+ # stats and reads, so multiple file ops only incur a cost once. However,
41
+ # these ops are all going over the network, so we should probably
42
+ # prioritize RedHat and SuSE detection over less common Linuxen in order to
43
+ # cut down on network chatter that will be useless in most cases. Also,
44
+ # might be worth adding /etc/os-release detection at the front of the list
45
+ # since that's the new hotness from systemd standardization.
46
+ operatingsystem = nil
47
+
48
+ operatingsystem = if Facter.value(:kernel) == "GNU/kFreeBSD"
49
+ "GNU/kFreeBSD"
50
+ elsif Facter::Util::FileRead.exists?('/etc/debian_version')
51
+ case Facter::Core::Execution.exec('lsb_release -i')
52
+ when /Ubuntu/i
53
+ 'Ubuntu'
54
+ when /LinuxMint/i
55
+ 'LinuxMint'
56
+ else
57
+ 'Debian'
58
+ end
59
+ end
60
+
61
+ release_files = {
62
+ "AristaEOS" => "/etc/Eos-release",
63
+ "Debian" => "/etc/debian_version",
64
+ "Gentoo" => "/etc/gentoo-release",
65
+ "Fedora" => "/etc/fedora-release",
66
+ "Mageia" => "/etc/mageia-release",
67
+ "Mandriva" => "/etc/mandriva-release",
68
+ "Mandrake" => "/etc/mandrake-release",
69
+ "MeeGo" => "/etc/meego-release",
70
+ "Archlinux" => "/etc/arch-release",
71
+ "Manjarolinux"=> "/etc/manjaro-release",
72
+ "OracleLinux" => "/etc/oracle-release",
73
+ "OpenWrt" => "/etc/openwrt_release",
74
+ "Alpine" => "/etc/alpine-release",
75
+ "VMWareESX" => "/etc/vmware-release",
76
+ "Bluewhite64" => "/etc/bluewhite64-version",
77
+ "Slamd64" => "/etc/slamd64-version",
78
+ "Slackware" => "/etc/slackware-version"
79
+ }
80
+
81
+ if operatingsystem.nil?
82
+ release_files.each do |os, releasefile|
83
+ if Facter::Util::FileRead.exists?(releasefile)
84
+ operatingsystem = os
85
+ break # Stop sending commands over the network.
86
+ end
87
+ end
88
+ end
89
+
90
+ if operatingsystem.nil?
91
+ if Facter::Util::FileRead.exists?('/etc/enterprise-release')
92
+ if Facter::Util::FileRead.exists?('/etc/ovs-release')
93
+ operatingsystem = "OVS"
94
+ else
95
+ operatingsystem = "OEL"
96
+ end
97
+ elsif Facter::Util::FileRead.exists?('/etc/redhat-release')
98
+ operatingsystem = case Facter::Util::FileRead.read('/etc/redhat-release')
99
+ when /CERN/i
100
+ 'SLC'
101
+ when /centos/i
102
+ 'CentOS'
103
+ when /Scientific/i
104
+ 'Scientific'
105
+ when /^cloudlinux/i
106
+ 'CloudLinux'
107
+ when /^Parallels Server Bare Metal/
108
+ 'PSBM'
109
+ when /Ascendos/i
110
+ 'Ascendos'
111
+ when /^XenServer/i
112
+ 'XenServer'
113
+ when /XCP/i
114
+ 'XCP'
115
+ when /^VirtuozzoLinux/i
116
+ 'VirtuozzoLinux'
117
+ else
118
+ 'RedHat'
119
+ end
120
+ elsif Facter::Util::FileRead.exists?('/etc/SuSE-release')
121
+ operatingsystem = case Facter::Util::FileRead.read('/etc/SuSE-release')
122
+ when /^SUSE LINUX Enterprise Server/i
123
+ 'SLES'
124
+ when /^SUSE LINUX Enterprise Desktop/i
125
+ 'SLED'
126
+ when /^openSUSE/
127
+ 'OpenSuSE'
128
+ else
129
+ 'SuSE'
130
+ end
131
+ elsif Facter::Util::FileRead.exists?('/etc/system-release')
132
+ operatingsystem = 'Amazon'
133
+ end
134
+ end
135
+
136
+ operatingsystem = 'unknown' if operatingsystem.nil?
137
+
138
+ {'name' => operatingsystem}
139
+ end
140
+
141
+ chunk(:family, require: [:name]) do |os_name|
142
+ family = case os_name['name']
143
+ when "RedHat", "Fedora", "CentOS", "Scientific", "SLC", "Ascendos",
144
+ "CloudLinux", "PSBM", "OracleLinux", "OVS", "OEL", "Amazon",
145
+ "XenServer", "VirtuozzoLinux"
146
+ "RedHat"
147
+ when "LinuxMint", "Ubuntu", "Debian"
148
+ "Debian"
149
+ when "SLES", "SLED", "OpenSuSE", "SuSE"
150
+ "Suse"
151
+ when "Gentoo"
152
+ "Gentoo"
153
+ when "Archlinux", "Manjarolinux"
154
+ "Archlinux"
155
+ when "Mageia", "Mandriva", "Mandrake"
156
+ "Mandrake"
157
+ else
158
+ Facter.value("kernel")
159
+ end
160
+
161
+ {'family' => family}
162
+ end
163
+
164
+ chunk(:architecture, require: [:name]) do |os_name|
165
+ model = Facter::Core::Execution.execute('uname -m')
166
+
167
+ arch = case model
168
+ when "x86_64"
169
+ case os_name['name']
170
+ when "Debian", "Gentoo", "GNU/kFreeBSD", "Ubuntu"
171
+ "amd64"
172
+ else
173
+ model
174
+ end
175
+ when /(i[3456]86|pentium)/
176
+ case os_name['name']
177
+ when "Gentoo"
178
+ "x86"
179
+ else
180
+ "i386"
181
+ end
182
+ else
183
+ model
184
+ end
185
+
186
+ {
187
+ 'architecture' => arch,
188
+ 'hardware' => model
189
+ }
190
+ end
191
+
192
+ chunk(:release, require: [:name]) do |os_name|
193
+ full = nil
194
+ major = nil
195
+ minor = nil
196
+
197
+ case os_name['name']
198
+ when "Alpine"
199
+ if release = Facter::Util::FileRead.read('/etc/alpine-release')
200
+ full = release.sub(/\s*$/, '')
201
+ end
202
+ when "Amazon"
203
+ if (lsb_release = Facter::Core::Execution.exec('lsb_release -r')) && (! lsb_release.empty?)
204
+ full = release.split(':').last.strip
205
+ else
206
+ if release = Facter::Util::FileRead.read('/etc/system-release')
207
+ if match = /\d+\.\d+/.match(release)
208
+ full = match[0]
209
+ end
210
+ end
211
+ end
212
+ when "AristaEOS"
213
+ if release = Facter::Util::FileRead.read('/etc/Eos-release')
214
+ if match = /\d+\.\d+(:?\.\d+)?[A-M]?$/.match(release)
215
+ full = match[0]
216
+ end
217
+ end
218
+ when "BlueWhite64"
219
+ full = if release = Facter::Util::Read.read('/etc/bluewhite64-version')
220
+ if match = /^\s*\w+\s+(\d+)\.(\d+)/.match(release)
221
+ match[1] + "." + match[2]
222
+ else
223
+ "unknown"
224
+ end
225
+ end
226
+ when "CentOS", "RedHat", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM",
227
+ "XenServer", "Fedora", "MeeGo", "OracleLinux", "OEL", "oel", "OVS", "ovs",
228
+ "VirtuozzoLinux"
229
+ case os_name['name']
230
+ when "CentOS", "RedHat", "Scientific", "SLC", "Ascendos", "CloudLinux",
231
+ "PSBM", "XenServer", "VirtuozzoLinux"
232
+ releasefile = "/etc/redhat-release"
233
+ when "Fedora"
234
+ releasefile = "/etc/fedora-release"
235
+ when "MeeGo"
236
+ releasefile = "/etc/meego-release"
237
+ when "OracleLinux"
238
+ releasefile = "/etc/oracle-release"
239
+ when "OEL", "oel"
240
+ releasefile = "/etc/enterprise-release"
241
+ when "OVS", "ovs"
242
+ releasefile = "/etc/ovs-release"
243
+ end
244
+
245
+ full = if (release = Facter::Util::FileRead.read(releasefile))
246
+ line = release.split("\n").first.chomp
247
+ if match = /\(Rawhide\)$/.match(line)
248
+ "Rawhide"
249
+ elsif match = /release (\d[\d.]*)/.match(line)
250
+ match[1]
251
+ end
252
+ end
253
+ when "Debian"
254
+ full = if (release = Facter::Util::FileRead.read('/etc/debian_version'))
255
+ release.sub!(/\s*$/, '')
256
+ release
257
+ end
258
+ when "LinuxMint"
259
+ full = if (release = Facter::Util::FileRead.read('/etc/linuxmint/info'))
260
+ if match = release.match(/RELEASE=(\d+)/)
261
+ match[1]
262
+ end
263
+ end
264
+ when "Mageia"
265
+ full = if (release = Facter::Util::FileRead.read('/etc/mageia-release'))
266
+ if match = release.match(/Mageia release ([0-9.]+)/)
267
+ match[1]
268
+ end
269
+ end
270
+ when "OpenWrt"
271
+ full = if (release = Facter::Util::FileRead.read('/etc/openwrt_version'))
272
+ if match = release.match(/^(\d+\.\d+.*)/)
273
+ match[1]
274
+ end
275
+ end
276
+ when "Slackware"
277
+ full = if (release = Facter::Util::FileRead.read('/etc/slackware-version'))
278
+ if match = release.match(/Slackware ([0-9.]+)/)
279
+ match[1]
280
+ end
281
+ end
282
+ when "Slamd64"
283
+ full = if (release = Facter::Util::FileRead.read('/etc/slamd64-version'))
284
+ if match = release.match(/^\s*\w+\s+(\d+)\.(\d+)/)
285
+ match[1]
286
+ end
287
+ end
288
+ when "SLES", "SLED", "OpenSuSE"
289
+ full = if (release = Facter::Util::FileRead.read('/etc/SuSE-release'))
290
+ if match = /^VERSION\s*=\s*(\d+)/.match(release)
291
+ releasemajor = match[1]
292
+ if match = /^PATCHLEVEL\s*=\s*(\d+)/.match(release)
293
+ releaseminor = match[1]
294
+ elsif match = /^VERSION\s=.*.(\d+)/.match(release)
295
+ releaseminor = match[1]
296
+ else
297
+ releaseminor = "0"
298
+ end
299
+ releasemajor + "." + releaseminor
300
+ else
301
+ "unknown"
302
+ end
303
+ end
304
+ when "Ubuntu"
305
+ full = if (release = Facter::Util::FileRead.read('/etc/lsb-release'))
306
+ if match = release.match(/DISTRIB_RELEASE=((\d+.\d+)(\.(\d+))?)/)
307
+ # Return only the major and minor version numbers. This behavior must
308
+ # be preserved for compatibility reasons.
309
+ match[2]
310
+ end
311
+ end
312
+ when "VMwareESX"
313
+ release = Facter::Core::Execution.exec('vmware -v')
314
+ full = if (match = /VMware ESX .*?(\d.*)/.match(release))
315
+ match[1]
316
+ end
317
+ else
318
+ Facter.value(:kernelrelease)
319
+ end
320
+
321
+ case os_name['name']
322
+ when 'Ubuntu'
323
+ major = if (releasemajor = full.split("."))
324
+ if releasemajor.length >= 2
325
+ "#{releasemajor[0]}.#{releasemajor[1]}"
326
+ else
327
+ releasemajor[0]
328
+ end
329
+ end
330
+
331
+ minor = if (releaseminor = full.split(".")[2])
332
+ releaseminor
333
+ end
334
+ else
335
+ major = if (releasemajor = full.split(".")[0])
336
+ releasemajor
337
+ end
338
+
339
+ minor = if (releaseminor = full.split(".")[1])
340
+ if releaseminor.include? "-"
341
+ releaseminor.split("-")[0]
342
+ else
343
+ releaseminor
344
+ end
345
+ end
346
+ end
347
+
348
+ release_info = {
349
+ 'full' => full,
350
+ 'major' => major,
351
+ 'minor' => minor
352
+ }
353
+
354
+ {'release' => release_info.reject{|_, v| v.nil?}}
355
+ end
356
+ end
357
+
358
+ Facter.add(:os, :type => :aggregate) do
359
+ confine :kernel => 'windows'
360
+
361
+ chunk(:name) do
362
+ {'name' => 'windows'}
363
+ end
364
+
365
+ chunk(:family) do
366
+ {'family' => 'windows'}
367
+ end
368
+
369
+ chunk(:architecture) do
370
+ # NOTE: Restricting the WMI query using -Property really makes a
371
+ # performance difference for Win32_Processor
372
+ processor_info = Facter::Core::Execution.execute(<<-PS1)
373
+ (Get-WmiObject -Class Win32_Processor -Property Architecture,Level,AddressWidth |
374
+ Select-Object -First 1 -Property Architecture,Level,AddressWidth |
375
+ Format-List|Out-String).Trim()
376
+ PS1
377
+
378
+ arch, level, width = processor_info.lines.map do |l|
379
+ # TODO: Log a message at debug level when one of these returns
380
+ # a non-integer value.
381
+ Integer(l.split(':').last.strip) rescue nil
382
+ end
383
+ level = (level > 5) ? 6 : level
384
+
385
+ model = case arch
386
+ when 11
387
+ 'neutral' # PROCESSOR_ARCHITECTURE_NEUTRAL
388
+ when 10
389
+ 'i686' # PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
390
+ when 9
391
+ # PROCESSOR_ARCHITECTURE_AMD64
392
+ width == 32 ? "i#{level}86" : 'x86_64' # 32 bit OS on 64 bit CPU
393
+ when 8
394
+ 'msil' # PROCESSOR_ARCHITECTURE_MSIL
395
+ when 7
396
+ 'alpha64' # PROCESSOR_ARCHITECTURE_ALPHA64
397
+ when 6
398
+ 'ia64' # PROCESSOR_ARCHITECTURE_IA64
399
+ when 5
400
+ 'arm' # PROCESSOR_ARCHITECTURE_ARM
401
+ when 4
402
+ 'shx' # PROCESSOR_ARCHITECTURE_SHX
403
+ when 3
404
+ 'powerpc' # PROCESSOR_ARCHITECTURE_PPC
405
+ when 2
406
+ 'alpha' # PROCESSOR_ARCHITECTURE_ALPHA
407
+ when 1
408
+ 'mips' # PROCESSOR_ARCHITECTURE_MIPS
409
+ when 0
410
+ "i#{level}86" # PROCESSOR_ARCHITECTURE_INTEL
411
+ else
412
+ 'unknown' # PROCESSOR_ARCHITECTURE_UNKNOWN
413
+ end
414
+
415
+ architecture = case model
416
+ when /(i[3456]86|pentium)/
417
+ 'x86'
418
+ when 'x86_64'
419
+ 'x64'
420
+ else
421
+ model
422
+ end
423
+
424
+ {
425
+ 'architecture' => architecture,
426
+ 'hardware' => model
427
+ }
428
+ end
429
+
430
+ chunk(:release) do
431
+ version_info = Facter::Core::Execution.execute(<<-PS1)
432
+ (Get-WmiObject -Class Win32_OperatingSystem -Property BuildNumber,ProductType,ServicePackMajorVersion |
433
+ Select-Object -First 1 -Property BuildNumber,ProductType,ServicePackMajorVersion |
434
+ Format-List|Out-String).Trim()
435
+ PS1
436
+
437
+ build, type, pack = version_info.lines.map do |l|
438
+ # TODO: Log a message at debug level when one of these returns
439
+ # a non-integer value.
440
+ Integer(l.split(':').last.strip) rescue nil
441
+ end
442
+
443
+ release = case Facter.value(:kernelmajversion)
444
+ when '10.0'
445
+ type == 1 ? '10' : '2016'
446
+ when '6.3'
447
+ type == 1 ? "8.1" : "2012 R2"
448
+ when '6.2'
449
+ type == 1 ? "8" : "2012"
450
+ when '6.1'
451
+ type == 1 ? "7" : "2008 R2"
452
+ when '6.0'
453
+ type == 1 ? "Vista" : "2008"
454
+ when '5.2'
455
+ if type == 1
456
+ "XP"
457
+ elsif pack == 2
458
+ "2003 R2"
459
+ else
460
+ "2003"
461
+ end
462
+ else
463
+ Facter.value(:kernelrelease)
464
+ end
465
+
466
+ {
467
+ 'release' => {
468
+ 'full' => release,
469
+ 'major' => release
470
+ }
471
+ }
472
+ end
473
+ end
474
+
475
+ Facter.add(:os, :type => :aggregate) do
476
+ confine :kernel => 'aix'
477
+
478
+ chunk(:name) do
479
+ {'name' => 'AIX'}
480
+ end
481
+
482
+ chunk(:family) do
483
+ {'family' => 'AIX'}
484
+ end
485
+
486
+ chunk(:architecture) do
487
+ model_info = Facter::Core::Execution.exec('lsattr -El sys0 -a modelname')
488
+ model = if (match = model_info.match(/modelname\s(\S+)\s/))
489
+ match.captures.first
490
+ else
491
+ nil
492
+ end
493
+
494
+ arch_info = Facter::Core::Execution.exec('lsattr -El proc0 -a type')
495
+ arch = if (match = arch_info.match(/type\s(\S+)\s/))
496
+ match.captures.first
497
+ else
498
+ nil
499
+ end
500
+
501
+ architecture = {
502
+ 'architecture' => arch,
503
+ 'hardware' => model
504
+ }
505
+
506
+ architecture.reject{|_, v| v.nil?}
507
+ end
508
+
509
+ chunk(:release) do
510
+ release_info = {
511
+ 'full' => Facter.value(:kernelrelease),
512
+ 'major' => Facter.value(:kernelrelease).split('-')[0]
513
+ }
514
+
515
+ {'release' => release_info}
516
+ end
517
+ end
518
+
519
+ Facter.add(:os, :type => :aggregate) do
520
+ confine :kernel => 'sunos'
521
+
522
+ chunk(:name) do
523
+ output = Facter::Core::Execution.exec('uname -v')
524
+
525
+ name = if output =~ /^joyent_/
526
+ "SmartOS"
527
+ elsif output =~ /^oi_/
528
+ "OpenIndiana"
529
+ elsif output =~ /^omnios-/
530
+ "OmniOS"
531
+ elsif Facter::Util::FileRead.exists?("/etc/debian_version")
532
+ "Nexenta"
533
+ else
534
+ "Solaris"
535
+ end
536
+
537
+ {'name' => name}
538
+ end
539
+
540
+ chunk(:family) do
541
+ {'family' => 'Solaris'}
542
+ end
543
+
544
+ chunk(:architecture) do
545
+ arch = Facter::Core::Execution.execute('uname -m')
546
+
547
+ {
548
+ 'architecture' => arch,
549
+ 'hardware' => arch
550
+ }
551
+ end
552
+
553
+ chunk(:release, require: [:name]) do |osname|
554
+ full = if (release = Facter::Util::FileFread.read('/etc/release'))
555
+ line = release.split("\n").first
556
+
557
+ # Solaris 10: Solaris 10 10/09 s10x_u8wos_08a X86
558
+ # Solaris 11 (old naming scheme): Oracle Solaris 11 11/11 X86
559
+ # Solaris 11 (new naming scheme): Oracle Solaris 11.1 SPARC
560
+ if match = /\s+s(\d+)[sx]?(_u\d+)?.*(?:SPARC|X86)/.match(line)
561
+ match.captures.join('')
562
+ elsif match = /Solaris ([0-9\.]+(?:\s*[0-9\.\/]+))\s*(?:SPARC|X86)/.match(line)
563
+ match.captures[0]
564
+ else
565
+ Facter.value(:kernelrelease)
566
+ end
567
+ else
568
+ Facter(:kernelrelease).value
569
+ end
570
+
571
+ major = if osname['name'] == "Solaris"
572
+ if match = full.match(/^(\d+)/)
573
+ match.captures[0]
574
+ end
575
+ end
576
+
577
+ minor = if osname['name'] == "Solaris"
578
+ if match = full.match(/^\d+(?:\.|_u)(\d+)/)
579
+ match.captures[0]
580
+ end
581
+ end
582
+
583
+ release_info = {
584
+ 'full' => full,
585
+ 'major' => major,
586
+ 'minor' => minor
587
+ }
588
+
589
+ {'release' => release_info.reject{|_, v| v.nil?}}
590
+ end
591
+ end