Module: Train::Platforms::Detect::Helpers::OSCommon
- Includes:
- Linux, Windows
- Included in:
- Scanner
- Defined in:
- lib/train/platforms/detect/helpers/os_common.rb
Instance Method Summary
collapse
Methods included from Windows
#detect_windows, #read_wmic, #read_wmic_cpu
Methods included from Linux
#linux_os_release, #lsb_config, #lsb_release, #parse_os_release_info, #read_linux_lsb, #redhatish_platform, #redhatish_version
Instance Method Details
#brocade_version ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 56
def brocade_version
return @cache[:brocade] if @cache.key?(:brocade)
res = command_output('version')
m = res.match(/^Fabric OS:\s+v(\S+)$/)
unless m.nil?
return @cache[:brocade] = { version: m[1], type: 'fos' }
end
@cache[:brocade] = nil
end
|
#cisco_show_version ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 68
def cisco_show_version
return @cache[:cisco] if @cache.key?(:cisco)
res = command_output('show version')
m = res.match(/^Cisco IOS Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+)/)
unless m.nil?
return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios' }
end
m = res.match(/^Cisco IOS Software, IOS-XE Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+\.\d+[A-Z]*)/)
unless m.nil?
return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios-xe' }
end
m = res.match(/^Cisco Nexus Operating System \(NX-OS\) Software/)
unless m.nil?
v = res[/^\s*system:\s+version (\d+\.\d+)/, 1]
return @cache[:cisco] = { version: v, type: 'nexus' }
end
@cache[:cisco] = nil
end
|
#command_output(cmd) ⇒ Object
35
36
37
38
39
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 35
def command_output(cmd)
res = @backend.run_command(cmd).stdout
res.strip! unless res.nil?
res
end
|
#ruby_host_os(regex) ⇒ Object
12
13
14
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 12
def ruby_host_os(regex)
::RbConfig::CONFIG['host_os'] =~ regex
end
|
#unix_file_contents(path) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 21
def unix_file_contents(path)
return @files[path] if @files.key?(path)
res = @backend.run_command("test -f #{path} && cat #{path}")
@files[path] = res.exit_status.zero? ? res.stdout : nil
@files[path]
end
|
#unix_file_exist?(path) ⇒ Boolean
31
32
33
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 31
def unix_file_exist?(path)
@backend.run_command("test -f #{path}").exit_status.zero?
end
|
#unix_uname_m ⇒ Object
51
52
53
54
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 51
def unix_uname_m
return @uname[:m] if @uname.key?(:m)
@uname[:m] = command_output('uname -m')
end
|
#unix_uname_r ⇒ Object
46
47
48
49
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 46
def unix_uname_r
return @uname[:r] if @uname.key?(:r)
@uname[:r] = command_output('uname -r')
end
|
#unix_uname_s ⇒ Object
41
42
43
44
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 41
def unix_uname_s
return @uname[:s] if @uname.key?(:s)
@uname[:s] = command_output('uname -s')
end
|
#winrm? ⇒ Boolean
16
17
18
19
|
# File 'lib/train/platforms/detect/helpers/os_common.rb', line 16
def winrm?
Object.const_defined?('Train::Transports::WinRM::Connection') &&
@backend.class == Train::Transports::WinRM::Connection
end
|