train 2.1.13 → 2.1.19

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.
@@ -39,6 +39,7 @@ module Train::Platforms::Detect::Helpers
39
39
  line.strip!
40
40
  next if line.start_with?("#")
41
41
  next if line.empty?
42
+
42
43
  key, value = line.split("=", 2)
43
44
  memo[key] = value.gsub(/\A"|"\Z/, "") unless value.empty?
44
45
  end
@@ -68,6 +69,7 @@ module Train::Platforms::Detect::Helpers
68
69
 
69
70
  def read_linux_lsb
70
71
  return @lsb unless @lsb.empty?
72
+
71
73
  if !(raw = unix_file_contents("/etc/lsb-release")).nil?
72
74
  @lsb = lsb_config(raw)
73
75
  elsif !(raw = unix_file_contents("/usr/bin/lsb-release")).nil?
@@ -8,6 +8,7 @@ module Train::Platforms::Detect::Helpers
8
8
  # if the ver contains `Windows`, we know its a Windows system
9
9
  version = res.stdout.strip
10
10
  return false unless version.downcase =~ /windows/
11
+
11
12
  @platform[:family] = "windows"
12
13
 
13
14
  # try to extract release from eg. `Microsoft Windows [Version 6.3.9600]`
@@ -82,13 +83,14 @@ module Train::Platforms::Detect::Helpers
82
83
  uuid = windows_uuid_from_wmic if uuid.nil?
83
84
  uuid = windows_uuid_from_registry if uuid.nil?
84
85
  raise Train::TransportError, "Cannot find a UUID for your node." if uuid.nil?
86
+
85
87
  uuid
86
88
  end
87
89
 
88
90
  def windows_uuid_from_machine_file
89
91
  %W{
90
- #{ENV['SYSTEMDRIVE']}\\chef\\chef_guid
91
- #{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}\\.chef\\chef_guid
92
+ #{ENV["SYSTEMDRIVE"]}\\chef\\chef_guid
93
+ #{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}\\.chef\\chef_guid
92
94
  }.each do |path|
93
95
  file = @backend.file(path)
94
96
  return file.content.chomp if file.exist? && file.size != 0
@@ -97,8 +99,9 @@ module Train::Platforms::Detect::Helpers
97
99
  end
98
100
 
99
101
  def windows_uuid_from_chef
100
- file = @backend.file("#{ENV['SYSTEMDRIVE']}\\chef\\cache\\data_collector_metadata.json")
102
+ file = @backend.file("#{ENV["SYSTEMDRIVE"]}\\chef\\cache\\data_collector_metadata.json")
101
103
  return if !file.exist? || file.size == 0
104
+
102
105
  json = JSON.parse(file.content)
103
106
  json["node_uuid"] if json["node_uuid"]
104
107
  end
@@ -106,6 +109,7 @@ module Train::Platforms::Detect::Helpers
106
109
  def windows_uuid_from_wmic
107
110
  result = @backend.run_command("wmic csproduct get UUID")
108
111
  return unless result.exit_status == 0
112
+
109
113
  result.stdout.split("\r\n")[-1].strip
110
114
  end
111
115
 
@@ -113,6 +117,7 @@ module Train::Platforms::Detect::Helpers
113
117
  cmd = '(Get-ItemProperty "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography" -Name "MachineGuid")."MachineGuid"'
114
118
  result = @backend.run_command(cmd)
115
119
  return unless result.exit_status == 0
120
+
116
121
  result.stdout.chomp
117
122
  end
118
123
  end
@@ -59,6 +59,7 @@ module Train::Platforms::Detect
59
59
  def scan_family_children(plat)
60
60
  child_result = scan_children(plat) unless plat.children.nil?
61
61
  return if child_result.nil?
62
+
62
63
  @family_hierarchy << plat.name
63
64
  child_result
64
65
  end
@@ -16,576 +16,580 @@ module Train::Platforms::Detect::Specifications
16
16
  plat.family("os").detect { true }
17
17
 
18
18
  plat.family("windows").in_family("os")
19
- .detect do
19
+ .detect do
20
20
  # Can't return from a `proc` thus the `is_windows` shenanigans
21
- is_windows = false
22
- is_windows = true if winrm?
21
+ is_windows = false
22
+ is_windows = true if winrm?
23
23
 
24
- if @backend.class.to_s == "Train::Transports::Local::Connection"
25
- is_windows = true if ruby_host_os(/mswin|mingw32|windows/)
26
- end
24
+ if @backend.class.to_s == "Train::Transports::Local::Connection"
25
+ is_windows = true if ruby_host_os(/mswin|mingw32|windows/)
26
+ end
27
27
 
28
28
  # Try to detect windows even for ssh transport
29
- if !is_windows && detect_windows == true
30
- is_windows = true
31
- end
32
-
33
- is_windows
29
+ if !is_windows && detect_windows == true
30
+ is_windows = true
34
31
  end
32
+
33
+ is_windows
34
+ end
35
35
  # windows platform
36
36
  plat.name("windows").in_family("windows")
37
- .detect do
38
- true if detect_windows == true
39
- end
37
+ .detect do
38
+ true if detect_windows == true
39
+ end
40
40
 
41
41
  # unix master family
42
42
  plat.family("unix").in_family("os")
43
- .detect do
43
+ .detect do
44
44
  # we want to catch a special case here where cisco commands
45
45
  # don't return an exit status and still print to stdout
46
- if unix_uname_s =~ /./ && !unix_uname_s.start_with?("Line has invalid autocommand ") && !unix_uname_s.start_with?("The command you have entered")
47
- @platform[:arch] = unix_uname_m
48
- true
49
- end
46
+ if unix_uname_s =~ /./ && !unix_uname_s.start_with?("Line has invalid autocommand ") && !unix_uname_s.start_with?("The command you have entered")
47
+ @platform[:arch] = unix_uname_m
48
+ true
50
49
  end
50
+ end
51
51
 
52
52
  # linux master family
53
53
  plat.family("linux").in_family("unix")
54
- .detect do
55
- true if unix_uname_s =~ /linux/i
56
- end
54
+ .detect do
55
+ true if unix_uname_s =~ /linux/i
56
+ end
57
57
 
58
58
  # debian family
59
59
  plat.family("debian").in_family("linux")
60
- .detect do
61
- true unless unix_file_contents("/etc/debian_version").nil?
62
- end
60
+ .detect do
61
+ true unless unix_file_contents("/etc/debian_version").nil?
62
+ end
63
63
  plat.name("ubuntu").title("Ubuntu Linux").in_family("debian")
64
- .detect do
65
- lsb = read_linux_lsb
66
- if lsb && lsb[:id] =~ /ubuntu/i
67
- @platform[:release] = lsb[:release]
68
- true
69
- end
64
+ .detect do
65
+ lsb = read_linux_lsb
66
+ if lsb && lsb[:id] =~ /ubuntu/i
67
+ @platform[:release] = lsb[:release]
68
+ true
70
69
  end
70
+ end
71
71
  plat.name("linuxmint").title("LinuxMint").in_family("debian")
72
- .detect do
73
- lsb = read_linux_lsb
74
- if lsb && lsb[:id] =~ /linuxmint/i
75
- @platform[:release] = lsb[:release]
76
- true
77
- end
72
+ .detect do
73
+ lsb = read_linux_lsb
74
+ if lsb && lsb[:id] =~ /linuxmint/i
75
+ @platform[:release] = lsb[:release]
76
+ true
78
77
  end
78
+ end
79
79
  plat.name("raspbian").title("Raspbian Linux").in_family("debian")
80
- .detect do
81
- if (linux_os_release && linux_os_release["NAME"] =~ /raspbian/i) || \
82
- unix_file_exist?("/usr/bin/raspi-config")
83
- @platform[:release] = unix_file_contents("/etc/debian_version").chomp
84
- true
85
- end
80
+ .detect do
81
+ if (linux_os_release && linux_os_release["NAME"] =~ /raspbian/i) || \
82
+ unix_file_exist?("/usr/bin/raspi-config")
83
+ @platform[:release] = unix_file_contents("/etc/debian_version").chomp
84
+ true
86
85
  end
86
+ end
87
87
  plat.name("debian").title("Debian Linux").in_family("debian")
88
- .detect do
89
- lsb = read_linux_lsb
90
- if lsb && lsb[:id] =~ /debian/i
91
- @platform[:release] = lsb[:release]
92
- true
93
- end
94
-
95
- # if we get this far we have to be some type of debian
96
- @platform[:release] = unix_file_contents("/etc/debian_version").chomp
88
+ .detect do
89
+ lsb = read_linux_lsb
90
+ if lsb && lsb[:id] =~ /debian/i
91
+ @platform[:release] = lsb[:release]
97
92
  true
98
93
  end
99
94
 
95
+ # if we get this far we have to be some type of debian
96
+ @platform[:release] = unix_file_contents("/etc/debian_version").chomp
97
+ true
98
+ end
99
+
100
100
  # fedora family
101
101
  plat.family("fedora").in_family("linux")
102
- .detect do
103
- true if linux_os_release && linux_os_release["NAME"] =~ /fedora/i
104
- end
102
+ .detect do
103
+ true if linux_os_release && linux_os_release["NAME"] =~ /fedora/i
104
+ end
105
105
  plat.name("fedora").title("Fedora").in_family("fedora")
106
- .detect do
107
- @platform[:release] = linux_os_release["VERSION_ID"]
108
- true
109
- end
106
+ .detect do
107
+ @platform[:release] = linux_os_release["VERSION_ID"]
108
+ true
109
+ end
110
110
 
111
111
  # arista_eos family
112
112
  # this checks for the arista bash shell
113
113
  # must come before redhat as it uses fedora under the hood
114
114
  plat.family("arista_eos").title("Arista EOS Family").in_family("linux")
115
- .detect do
116
- true
117
- end
115
+ .detect do
116
+ true
117
+ end
118
118
  plat.name("arista_eos_bash").title("Arista EOS Bash Shell").in_family("arista_eos")
119
- .detect do
120
- if unix_file_exist?("/usr/bin/FastCli")
121
- cmd = @backend.run_command('FastCli -p 15 -c "show version | json"')
122
- if cmd.exit_status == 0 && !cmd.stdout.empty?
123
- require "json"
124
- begin
125
- eos_ver = JSON.parse(cmd.stdout)
126
- @platform[:release] = eos_ver["version"]
127
- @platform[:arch] = eos_ver["architecture"]
128
- true
129
- rescue JSON::ParserError
130
- nil
131
- end
119
+ .detect do
120
+ if unix_file_exist?("/usr/bin/FastCli")
121
+ cmd = @backend.run_command('FastCli -p 15 -c "show version | json"')
122
+ if cmd.exit_status == 0 && !cmd.stdout.empty?
123
+ require "json"
124
+ begin
125
+ eos_ver = JSON.parse(cmd.stdout)
126
+ @platform[:release] = eos_ver["version"]
127
+ @platform[:arch] = eos_ver["architecture"]
128
+ true
129
+ rescue JSON::ParserError
130
+ nil
132
131
  end
133
132
  end
134
133
  end
134
+ end
135
135
 
136
136
  # redhat family
137
137
  plat.family("redhat").in_family("linux")
138
- .detect do
138
+ .detect do
139
139
  # I am not sure this returns true for all redhats in this family
140
140
  # for now we are going to just try each platform
141
141
  # return true unless unix_file_contents('/etc/redhat-release').nil?
142
142
 
143
- true
144
- end
143
+ true
144
+ end
145
145
  plat.name("centos").title("Centos Linux").in_family("redhat")
146
- .detect do
147
- lsb = read_linux_lsb
148
- if lsb && lsb[:id] =~ /centos/i
149
- @platform[:release] = lsb[:release]
150
- true
151
- elsif linux_os_release && linux_os_release["NAME"] =~ /centos/i
152
- @platform[:release] = redhatish_version(unix_file_contents("/etc/redhat-release"))
153
- true
154
- end
146
+ .detect do
147
+ lsb = read_linux_lsb
148
+ if lsb && lsb[:id] =~ /centos/i
149
+ @platform[:release] = lsb[:release]
150
+ true
151
+ elsif linux_os_release && linux_os_release["NAME"] =~ /centos/i
152
+ @platform[:release] = redhatish_version(unix_file_contents("/etc/redhat-release"))
153
+ true
155
154
  end
155
+ end
156
156
  plat.name("oracle").title("Oracle Linux").in_family("redhat")
157
- .detect do
158
- if !(raw = unix_file_contents("/etc/oracle-release")).nil?
159
- @platform[:release] = redhatish_version(raw)
160
- true
161
- elsif !(raw = unix_file_contents("/etc/enterprise-release")).nil?
162
- @platform[:release] = redhatish_version(raw)
163
- true
164
- end
157
+ .detect do
158
+ if !(raw = unix_file_contents("/etc/oracle-release")).nil?
159
+ @platform[:release] = redhatish_version(raw)
160
+ true
161
+ elsif !(raw = unix_file_contents("/etc/enterprise-release")).nil?
162
+ @platform[:release] = redhatish_version(raw)
163
+ true
165
164
  end
165
+ end
166
166
  plat.name("scientific").title("Scientific Linux").in_family("redhat")
167
- .detect do
168
- lsb = read_linux_lsb
169
- if lsb && lsb[:id] =~ /scientific/i
170
- @platform[:release] = lsb[:release]
171
- true
172
- end
167
+ .detect do
168
+ lsb = read_linux_lsb
169
+ if lsb && lsb[:id] =~ /scientific/i
170
+ @platform[:release] = lsb[:release]
171
+ true
173
172
  end
173
+ end
174
174
  plat.name("xenserver").title("Xenserer Linux").in_family("redhat")
175
- .detect do
176
- lsb = read_linux_lsb
177
- if lsb && lsb[:id] =~ /xenserver/i
178
- @platform[:release] = lsb[:release]
179
- true
180
- end
175
+ .detect do
176
+ lsb = read_linux_lsb
177
+ if lsb && lsb[:id] =~ /xenserver/i
178
+ @platform[:release] = lsb[:release]
179
+ true
181
180
  end
181
+ end
182
182
  plat.name("parallels-release").title("Parallels Linux").in_family("redhat")
183
- .detect do
184
- if !(raw = unix_file_contents("/etc/parallels-release")).nil?
185
- @platform[:name] = redhatish_platform(raw)
186
- @platform[:release] = raw[/(\d\.\d\.\d)/, 1]
187
- true
188
- end
183
+ .detect do
184
+ unless (raw = unix_file_contents("/etc/parallels-release")).nil?
185
+ @platform[:name] = redhatish_platform(raw)
186
+ @platform[:release] = raw[/(\d\.\d\.\d)/, 1]
187
+ true
189
188
  end
189
+ end
190
190
  plat.name("wrlinux").title("Wind River Linux").in_family("redhat")
191
- .detect do
192
- if linux_os_release && linux_os_release["ID_LIKE"] =~ /wrlinux/i
193
- @platform[:release] = linux_os_release["VERSION"]
194
- true
195
- end
191
+ .detect do
192
+ if linux_os_release && linux_os_release["ID_LIKE"] =~ /wrlinux/i
193
+ @platform[:release] = linux_os_release["VERSION"]
194
+ true
196
195
  end
196
+ end
197
197
  plat.name("amazon").title("Amazon Linux").in_family("redhat")
198
- .detect do
199
- lsb = read_linux_lsb
200
- if lsb && lsb[:id] =~ /amazon/i
201
- @platform[:release] = lsb[:release]
202
- true
203
- elsif (raw = unix_file_contents("/etc/system-release")) =~ /amazon/i
204
- @platform[:name] = redhatish_platform(raw)
205
- @platform[:release] = redhatish_version(raw)
206
- true
207
- end
198
+ .detect do
199
+ lsb = read_linux_lsb
200
+ if lsb && lsb[:id] =~ /amazon/i
201
+ @platform[:release] = lsb[:release]
202
+ true
203
+ elsif (raw = unix_file_contents("/etc/system-release")) =~ /amazon/i
204
+ @platform[:name] = redhatish_platform(raw)
205
+ @platform[:release] = redhatish_version(raw)
206
+ true
208
207
  end
208
+ end
209
209
  plat.name("cloudlinux").title("CloudLinux").in_family("redhat")
210
- .detect do
211
- lsb = read_linux_lsb
212
- if lsb && lsb[:id] =~ /cloudlinux/i
213
- @platform[:release] = lsb[:release]
214
- true
215
- elsif (raw = unix_file_contents("/etc/redhat-release")) =~ /cloudlinux/i
216
- @platform[:name] = redhatish_platform(raw)
217
- @platform[:release] = redhatish_version(raw)
218
- true
219
- end
210
+ .detect do
211
+ lsb = read_linux_lsb
212
+ if lsb && lsb[:id] =~ /cloudlinux/i
213
+ @platform[:release] = lsb[:release]
214
+ true
215
+ elsif (raw = unix_file_contents("/etc/redhat-release")) =~ /cloudlinux/i
216
+ @platform[:name] = redhatish_platform(raw)
217
+ @platform[:release] = redhatish_version(raw)
218
+ true
220
219
  end
220
+ end
221
221
  # keep redhat at the end as a fallback for anything with a redhat-release
222
222
  plat.name("redhat").title("Red Hat Linux").in_family("redhat")
223
- .detect do
224
- lsb = read_linux_lsb
225
- if lsb && lsb[:id] =~ /redhat/i
226
- @platform[:release] = lsb[:release]
227
- true
228
- elsif !(raw = unix_file_contents("/etc/redhat-release")).nil?
229
- # must be some type of redhat
230
- @platform[:name] = redhatish_platform(raw)
231
- @platform[:release] = redhatish_version(raw)
232
- true
233
- end
223
+ .detect do
224
+ lsb = read_linux_lsb
225
+ if lsb && lsb[:id] =~ /redhat/i
226
+ @platform[:release] = lsb[:release]
227
+ true
228
+ elsif !(raw = unix_file_contents("/etc/redhat-release")).nil?
229
+ # must be some type of redhat
230
+ @platform[:name] = redhatish_platform(raw)
231
+ @platform[:release] = redhatish_version(raw)
232
+ true
234
233
  end
234
+ end
235
235
 
236
236
  # suse family
237
237
  plat.family("suse").in_family("linux")
238
- .detect do
239
- if !(suse = unix_file_contents("/etc/SuSE-release")).nil?
240
- # https://rubular.com/r/UKaYWolCYFMfp1
241
- version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
242
- # https://rubular.com/r/b5PN3hZDxa5amV
243
- version = suse[/VERSION\s?=\s?"?([\d\.]{2,})"?/, 1] if version == ""
244
- @platform[:release] = version
245
- true
246
- end
238
+ .detect do
239
+ unless (suse = unix_file_contents("/etc/SuSE-release")).nil?
240
+ # https://rubular.com/r/UKaYWolCYFMfp1
241
+ version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
242
+ # https://rubular.com/r/b5PN3hZDxa5amV
243
+ version = suse[/VERSION\s?=\s?"?([\d\.]{2,})"?/, 1] if version == ""
244
+ @platform[:release] = version
245
+ true
247
246
  end
247
+ end
248
248
  plat.name("opensuse").title("OpenSUSE Linux").in_family("suse")
249
- .detect do
250
- true if unix_file_contents("/etc/SuSE-release") =~ /^opensuse/i
251
- end
249
+ .detect do
250
+ true if unix_file_contents("/etc/SuSE-release") =~ /^opensuse/i
251
+ end
252
252
  plat.name("suse").title("Suse Linux").in_family("suse")
253
- .detect do
254
- true if unix_file_contents("/etc/SuSE-release") =~ /suse/i
255
- end
253
+ .detect do
254
+ true if unix_file_contents("/etc/SuSE-release") =~ /suse/i
255
+ end
256
256
 
257
257
  # arch
258
258
  plat.name("arch").title("Arch Linux").in_family("linux")
259
- .detect do
260
- if !unix_file_contents("/etc/arch-release").nil?
261
- # Because this is a rolling release distribution,
262
- # use the kernel release, ex. 4.1.6-1-ARCH
263
- @platform[:release] = unix_uname_r
264
- true
265
- end
259
+ .detect do
260
+ unless unix_file_contents("/etc/arch-release").nil?
261
+ # Because this is a rolling release distribution,
262
+ # use the kernel release, ex. 4.1.6-1-ARCH
263
+ @platform[:release] = unix_uname_r
264
+ true
266
265
  end
266
+ end
267
267
 
268
268
  # slackware
269
269
  plat.name("slackware").title("Slackware Linux").in_family("linux")
270
- .detect do
271
- if !(raw = unix_file_contents("/etc/slackware-version")).nil?
272
- @platform[:release] = raw.scan(/(\d+|\.+)/).join
273
- true
274
- end
270
+ .detect do
271
+ unless (raw = unix_file_contents("/etc/slackware-version")).nil?
272
+ @platform[:release] = raw.scan(/(\d+|\.+)/).join
273
+ true
275
274
  end
275
+ end
276
276
 
277
277
  # gentoo
278
278
  plat.name("gentoo").title("Gentoo Linux").in_family("linux")
279
- .detect do
280
- if !(raw = unix_file_contents("/etc/gentoo-release")).nil?
281
- @platform[:release] = raw.scan(/(\d+|\.+)/).join
282
- true
283
- end
279
+ .detect do
280
+ unless (raw = unix_file_contents("/etc/gentoo-release")).nil?
281
+ @platform[:release] = raw.scan(/(\d+|\.+)/).join
282
+ true
284
283
  end
284
+ end
285
285
 
286
286
  # exherbo
287
287
  plat.name("exherbo").title("Exherbo Linux").in_family("linux")
288
- .detect do
289
- unless unix_file_contents("/etc/exherbo-release").nil?
290
- # Because this is a rolling release distribution,
291
- # use the kernel release, ex. 4.1.6
292
- @platform[:release] = unix_uname_r
293
- true
294
- end
288
+ .detect do
289
+ unless unix_file_contents("/etc/exherbo-release").nil?
290
+ # Because this is a rolling release distribution,
291
+ # use the kernel release, ex. 4.1.6
292
+ @platform[:release] = unix_uname_r
293
+ true
295
294
  end
295
+ end
296
296
 
297
297
  # alpine
298
298
  plat.name("alpine").title("Alpine Linux").in_family("linux")
299
- .detect do
300
- if !(raw = unix_file_contents("/etc/alpine-release")).nil?
301
- @platform[:release] = raw.strip
302
- true
303
- end
299
+ .detect do
300
+ unless (raw = unix_file_contents("/etc/alpine-release")).nil?
301
+ @platform[:release] = raw.strip
302
+ true
304
303
  end
304
+ end
305
305
 
306
306
  # coreos
307
307
  plat.name("coreos").title("CoreOS Linux").in_family("linux")
308
- .detect do
309
- unless unix_file_contents("/etc/coreos/update.conf").nil?
310
- lsb = read_linux_lsb
311
- @platform[:release] = lsb[:release]
312
- true
313
- end
308
+ .detect do
309
+ unless unix_file_contents("/etc/coreos/update.conf").nil?
310
+ lsb = read_linux_lsb
311
+ @platform[:release] = lsb[:release]
312
+ true
314
313
  end
314
+ end
315
315
 
316
316
  # brocade family detected here if device responds to 'uname' command,
317
317
  # happens when logging in as root
318
318
  plat.family("brocade").title("Brocade Family").in_family("linux")
319
- .detect do
320
- !brocade_version.nil?
321
- end
319
+ .detect do
320
+ !brocade_version.nil?
321
+ end
322
322
 
323
323
  # genaric linux
324
324
  # this should always be last in the linux family list
325
325
  plat.name("linux").title("Genaric Linux").in_family("linux")
326
- .detect do
327
- true
328
- end
326
+ .detect do
327
+ true
328
+ end
329
329
 
330
330
  # openvms
331
331
  plat.name("openvms").title("OpenVMS").in_family("unix")
332
- .detect do
333
- if unix_uname_s =~ /unrecognized command verb/i
334
- cmd = @backend.run_command("show system/noprocess")
335
- unless cmd.exit_status != 0 || cmd.stdout.empty?
336
- @platform[:name] = cmd.stdout.downcase.split(" ")[0]
337
- cmd = @backend.run_command('write sys$output f$getsyi("VERSION")')
338
- @platform[:release] = cmd.stdout.downcase.split("\n")[1][1..-1]
339
- cmd = @backend.run_command('write sys$output f$getsyi("ARCH_NAME")')
340
- @platform[:arch] = cmd.stdout.downcase.split("\n")[1]
341
- true
342
- end
332
+ .detect do
333
+ if unix_uname_s =~ /unrecognized command verb/i
334
+ cmd = @backend.run_command("show system/noprocess")
335
+ unless cmd.exit_status != 0 || cmd.stdout.empty?
336
+ @platform[:name] = cmd.stdout.downcase.split(" ")[0]
337
+ cmd = @backend.run_command('write sys$output f$getsyi("VERSION")')
338
+ @platform[:release] = cmd.stdout.downcase.split("\n")[1][1..-1]
339
+ cmd = @backend.run_command('write sys$output f$getsyi("ARCH_NAME")')
340
+ @platform[:arch] = cmd.stdout.downcase.split("\n")[1]
341
+ true
343
342
  end
344
343
  end
344
+ end
345
345
 
346
346
  # aix
347
347
  plat.family("aix").in_family("unix")
348
- .detect do
349
- true if unix_uname_s =~ /aix/i
350
- end
348
+ .detect do
349
+ true if unix_uname_s =~ /aix/i
350
+ end
351
351
  plat.name("aix").title("Aix").in_family("aix")
352
- .detect do
353
- out = @backend.run_command("uname -rvp").stdout
354
- m = out.match(/(\d+)\s+(\d+)\s+(.*)/)
355
- unless m.nil?
356
- @platform[:release] = "#{m[2]}.#{m[1]}"
357
- @platform[:arch] = m[3].to_s
358
- end
359
- true
352
+ .detect do
353
+ out = @backend.run_command("uname -rvp").stdout
354
+ m = out.match(/(\d+)\s+(\d+)\s+(.*)/)
355
+ unless m.nil?
356
+ @platform[:release] = "#{m[2]}.#{m[1]}"
357
+ @platform[:arch] = m[3].to_s
360
358
  end
359
+ true
360
+ end
361
361
 
362
362
  # solaris family
363
363
  plat.family("solaris").in_family("unix")
364
- .detect do
365
- if unix_uname_s =~ /sunos/i
366
- unless (version = /^5\.(?<release>\d+)$/.match(unix_uname_r)).nil?
367
- @platform[:release] = version["release"]
368
- end
369
-
370
- arch = @backend.run_command("uname -p")
371
- @platform[:arch] = arch.stdout.chomp if arch.exit_status == 0
372
- true
364
+ .detect do
365
+ if unix_uname_s =~ /sunos/i
366
+ unless (version = /^5\.(?<release>\d+)$/.match(unix_uname_r)).nil?
367
+ @platform[:release] = version["release"]
373
368
  end
369
+
370
+ arch = @backend.run_command("uname -p")
371
+ @platform[:arch] = arch.stdout.chomp if arch.exit_status == 0
372
+ true
374
373
  end
374
+ end
375
375
  plat.name("smartos").title("SmartOS").in_family("solaris")
376
- .detect do
377
- rel = unix_file_contents("/etc/release")
378
- if /^.*(SmartOS).*$/ =~ rel
379
- true
380
- end
376
+ .detect do
377
+ rel = unix_file_contents("/etc/release")
378
+ if /^.*(SmartOS).*$/ =~ rel
379
+ true
381
380
  end
381
+ end
382
382
  plat.name("omnios").title("Omnios").in_family("solaris")
383
- .detect do
384
- rel = unix_file_contents("/etc/release")
385
- if !(m = /^\s*(OmniOS).*r(\d+).*$/.match(rel)).nil?
386
- @platform[:release] = m[2]
387
- true
388
- end
383
+ .detect do
384
+ rel = unix_file_contents("/etc/release")
385
+ unless (m = /^\s*(OmniOS).*r(\d+).*$/.match(rel)).nil?
386
+ @platform[:release] = m[2]
387
+ true
389
388
  end
389
+ end
390
390
  plat.name("openindiana").title("Openindiana").in_family("solaris")
391
- .detect do
392
- rel = unix_file_contents("/etc/release")
393
- if !(m = /^\s*(OpenIndiana).*oi_(\d+).*$/.match(rel)).nil?
394
- @platform[:release] = m[2]
395
- true
396
- end
391
+ .detect do
392
+ rel = unix_file_contents("/etc/release")
393
+ unless (m = /^\s*(OpenIndiana).*oi_(\d+).*$/.match(rel)).nil?
394
+ @platform[:release] = m[2]
395
+ true
397
396
  end
397
+ end
398
398
  plat.name("opensolaris").title("Open Solaris").in_family("solaris")
399
- .detect do
400
- rel = unix_file_contents("/etc/release")
401
- if !(m = /^\s*(OpenSolaris).*snv_(\d+).*$/.match(rel)).nil?
402
- @platform[:release] = m[2]
403
- true
404
- end
399
+ .detect do
400
+ rel = unix_file_contents("/etc/release")
401
+ unless (m = /^\s*(OpenSolaris).*snv_(\d+).*$/.match(rel)).nil?
402
+ @platform[:release] = m[2]
403
+ true
405
404
  end
405
+ end
406
406
  plat.name("nexentacore").title("Nexentacore").in_family("solaris")
407
- .detect do
408
- rel = unix_file_contents("/etc/release")
409
- if /^\s*(NexentaCore)\s.*$/ =~ rel
410
- true
411
- end
407
+ .detect do
408
+ rel = unix_file_contents("/etc/release")
409
+ if /^\s*(NexentaCore)\s.*$/ =~ rel
410
+ true
412
411
  end
412
+ end
413
413
  plat.name("solaris").title("Solaris").in_family("solaris")
414
- .detect do
415
- rel = unix_file_contents("/etc/release")
416
- if !(m = /Oracle Solaris (\d+)/.match(rel)).nil?
417
- # TODO: should be string!
418
- @platform[:release] = m[1]
419
- true
420
- elsif /^\s*(Solaris)\s.*$/ =~ rel
421
- true
422
- end
423
-
424
- # must be some unknown solaris
414
+ .detect do
415
+ rel = unix_file_contents("/etc/release")
416
+ if !(m = /Oracle Solaris (\d+)/.match(rel)).nil?
417
+ # TODO: should be string!
418
+ @platform[:release] = m[1]
419
+ true
420
+ elsif /^\s*(Solaris)\s.*$/ =~ rel
425
421
  true
426
422
  end
427
423
 
424
+ # must be some unknown solaris
425
+ true
426
+ end
427
+
428
428
  # hpux
429
429
  plat.family("hpux").in_family("unix")
430
- .detect do
431
- true if unix_uname_s =~ /hp-ux/i
432
- end
430
+ .detect do
431
+ true if unix_uname_s =~ /hp-ux/i
432
+ end
433
433
  plat.name("hpux").title("Hpux").in_family("hpux")
434
- .detect do
435
- @platform[:release] = unix_uname_r.lines[0].chomp
436
- true
437
- end
434
+ .detect do
435
+ @platform[:release] = unix_uname_r.lines[0].chomp
436
+ true
437
+ end
438
438
 
439
439
  # qnx
440
440
  plat.family("qnx").in_family("unix")
441
- .detect do
442
- true if unix_uname_s =~ /qnx/i
443
- end
441
+ .detect do
442
+ true if unix_uname_s =~ /qnx/i
443
+ end
444
444
  plat.name("qnx").title("QNX").in_family("qnx")
445
- .detect do
446
- @platform[:name] = unix_uname_s.lines[0].chomp.downcase
447
- @platform[:release] = unix_uname_r.lines[0].chomp
448
- @platform[:arch] = unix_uname_m
449
- true
450
- end
445
+ .detect do
446
+ @platform[:name] = unix_uname_s.lines[0].chomp.downcase
447
+ @platform[:release] = unix_uname_r.lines[0].chomp
448
+ @platform[:arch] = unix_uname_m
449
+ true
450
+ end
451
451
 
452
452
  # bsd family
453
453
  plat.family("bsd").in_family("unix")
454
- .detect do
454
+ .detect do
455
455
  # we need a better way to determin this family
456
456
  # for now we are going to just try each platform
457
- true
458
- end
457
+ true
458
+ end
459
459
  plat.family("darwin").in_family("bsd")
460
- .detect do
461
- if unix_uname_s =~ /darwin/i
462
- cmd = unix_file_contents("/usr/bin/sw_vers")
463
- unless cmd.nil?
464
- m = cmd.match(/^ProductVersion:\s+(.+)$/)
465
- @platform[:release] = m.nil? ? nil : m[1]
466
- m = cmd.match(/^BuildVersion:\s+(.+)$/)
467
- @platform[:build] = m.nil? ? nil : m[1]
468
- end
469
- @platform[:release] = unix_uname_r.lines[0].chomp if @platform[:release].nil?
470
- @platform[:arch] = unix_uname_m
471
- true
472
- end
460
+ .detect do
461
+ if unix_uname_s =~ /darwin/i
462
+ cmd = unix_file_contents("/usr/bin/sw_vers")
463
+ unless cmd.nil?
464
+ m = cmd.match(/^ProductVersion:\s+(.+)$/)
465
+ @platform[:release] = m.nil? ? nil : m[1]
466
+ m = cmd.match(/^BuildVersion:\s+(.+)$/)
467
+ @platform[:build] = m.nil? ? nil : m[1]
468
+ end
469
+ @platform[:release] = unix_uname_r.lines[0].chomp if @platform[:release].nil?
470
+ @platform[:arch] = unix_uname_m
471
+ true
473
472
  end
473
+ end
474
474
  plat.name("mac_os_x").title("macOS X").in_family("darwin")
475
- .detect do
476
- cmd = unix_file_contents("/System/Library/CoreServices/SystemVersion.plist")
477
- @platform[:uuid_command] = "system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'"
478
- true if cmd =~ /Mac OS X/i
479
- end
475
+ .detect do
476
+ cmd = unix_file_contents("/System/Library/CoreServices/SystemVersion.plist")
477
+ @platform[:uuid_command] = "system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'"
478
+ true if cmd =~ /Mac OS X/i
479
+ end
480
480
  plat.name("darwin").title("Darwin").in_family("darwin")
481
- .detect do
481
+ .detect do
482
482
  # must be some other type of darwin
483
+ @platform[:name] = unix_uname_s.lines[0].chomp
484
+ true
485
+ end
486
+ plat.name("freebsd").title("Freebsd").in_family("bsd")
487
+ .detect do
488
+ if unix_uname_s =~ /freebsd/i
483
489
  @platform[:name] = unix_uname_s.lines[0].chomp
490
+ @platform[:release] = unix_uname_r.lines[0].chomp
484
491
  true
485
492
  end
486
- plat.name("freebsd").title("Freebsd").in_family("bsd")
487
- .detect do
488
- if unix_uname_s =~ /freebsd/i
489
- @platform[:name] = unix_uname_s.lines[0].chomp
490
- @platform[:release] = unix_uname_r.lines[0].chomp
491
- true
492
- end
493
- end
493
+ end
494
494
  plat.name("openbsd").title("Openbsd").in_family("bsd")
495
- .detect do
496
- if unix_uname_s =~ /openbsd/i
497
- @platform[:name] = unix_uname_s.lines[0].chomp
498
- @platform[:release] = unix_uname_r.lines[0].chomp
499
- true
500
- end
495
+ .detect do
496
+ if unix_uname_s =~ /openbsd/i
497
+ @platform[:name] = unix_uname_s.lines[0].chomp
498
+ @platform[:release] = unix_uname_r.lines[0].chomp
499
+ true
501
500
  end
501
+ end
502
502
  plat.name("netbsd").title("Netbsd").in_family("bsd")
503
- .detect do
504
- if unix_uname_s =~ /netbsd/i
505
- @platform[:name] = unix_uname_s.lines[0].chomp
506
- @platform[:release] = unix_uname_r.lines[0].chomp
507
- true
508
- end
503
+ .detect do
504
+ if unix_uname_s =~ /netbsd/i
505
+ @platform[:name] = unix_uname_s.lines[0].chomp
506
+ @platform[:release] = unix_uname_r.lines[0].chomp
507
+ true
509
508
  end
509
+ end
510
510
 
511
511
  # arista_eos family
512
512
  plat.family("arista_eos").title("Arista EOS Family").in_family("os")
513
- .detect do
514
- true
515
- end
513
+ .detect do
514
+ true
515
+ end
516
516
  plat.name("arista_eos").title("Arista EOS").in_family("arista_eos")
517
- .detect do
518
- cmd = @backend.run_command("show version | json")
519
- if cmd.exit_status == 0 && !cmd.stdout.empty?
520
- require "json"
521
- begin
522
- eos_ver = JSON.parse(cmd.stdout)
523
- @platform[:release] = eos_ver["version"]
524
- @platform[:arch] = eos_ver["architecture"]
525
- true
526
- rescue JSON::ParserError
527
- nil
528
- end
517
+ .detect do
518
+ cmd = @backend.run_command("show version | json")
519
+ if cmd.exit_status == 0 && !cmd.stdout.empty?
520
+ require "json"
521
+ begin
522
+ eos_ver = JSON.parse(cmd.stdout)
523
+ @platform[:release] = eos_ver["version"]
524
+ @platform[:arch] = eos_ver["architecture"]
525
+ true
526
+ rescue JSON::ParserError
527
+ nil
529
528
  end
530
529
  end
530
+ end
531
531
 
532
532
  # esx
533
533
  plat.family("esx").title("ESXi Family").in_family("os")
534
- .detect do
535
- true if unix_uname_s =~ /vmkernel/i
536
- end
534
+ .detect do
535
+ true if unix_uname_s =~ /vmkernel/i
536
+ end
537
537
  plat.name("vmkernel").in_family("esx")
538
- .detect do
539
- @platform[:name] = unix_uname_s.lines[0].chomp
540
- @platform[:release] = unix_uname_r.lines[0].chomp
541
- true
542
- end
538
+ .detect do
539
+ @platform[:name] = unix_uname_s.lines[0].chomp
540
+ @platform[:release] = unix_uname_r.lines[0].chomp
541
+ true
542
+ end
543
543
 
544
544
  # cisco_ios family
545
545
  plat.family("cisco").title("Cisco Family").in_family("os")
546
- .detect do
547
- !cisco_show_version.nil?
548
- end
546
+ .detect do
547
+ !cisco_show_version.nil?
548
+ end
549
549
  plat.name("cisco_ios").title("Cisco IOS").in_family("cisco")
550
- .detect do
551
- v = cisco_show_version
552
- next unless v[:type] == "ios"
553
- @platform[:release] = v[:version]
554
- @platform[:arch] = nil
555
- true
556
- end
550
+ .detect do
551
+ v = cisco_show_version
552
+ next unless v[:type] == "ios"
553
+
554
+ @platform[:release] = v[:version]
555
+ @platform[:arch] = nil
556
+ true
557
+ end
557
558
  plat.name("cisco_ios_xe").title("Cisco IOS XE").in_family("cisco")
558
- .detect do
559
- v = cisco_show_version
560
- next unless v[:type] == "ios-xe"
561
- @platform[:release] = v[:version]
562
- @platform[:arch] = nil
563
- true
564
- end
559
+ .detect do
560
+ v = cisco_show_version
561
+ next unless v[:type] == "ios-xe"
562
+
563
+ @platform[:release] = v[:version]
564
+ @platform[:arch] = nil
565
+ true
566
+ end
565
567
  plat.name("cisco_nexus").title("Cisco Nexus").in_family("cisco")
566
- .detect do
567
- v = cisco_show_version
568
- next unless v[:type] == "nexus"
569
- @platform[:release] = v[:version]
570
- @platform[:arch] = nil
571
- @platform[:uuid_command] = "show version | include Processor"
572
- true
573
- end
568
+ .detect do
569
+ v = cisco_show_version
570
+ next unless v[:type] == "nexus"
571
+
572
+ @platform[:release] = v[:version]
573
+ @platform[:arch] = nil
574
+ @platform[:uuid_command] = "show version | include Processor"
575
+ true
576
+ end
574
577
 
575
578
  # brocade family
576
579
  plat.family("brocade").title("Brocade Family").in_family("os")
577
- .detect do
578
- !brocade_version.nil?
579
- end
580
+ .detect do
581
+ !brocade_version.nil?
582
+ end
580
583
 
581
584
  plat.name("brocade_fos").title("Brocade FOS").in_family("brocade")
582
- .detect do
583
- v = brocade_version
584
- next unless v[:type] == "fos"
585
- @platform[:release] = v[:version]
586
- @platform[:arch] = nil
587
- true
588
- end
585
+ .detect do
586
+ v = brocade_version
587
+ next unless v[:type] == "fos"
588
+
589
+ @platform[:release] = v[:version]
590
+ @platform[:arch] = nil
591
+ true
592
+ end
589
593
  end
590
594
  end
591
595
  end