train-core 2.1.7 → 2.1.13

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