Class: Train::Platforms::Detect::Scanner
- Inherits:
-
Object
- Object
- Train::Platforms::Detect::Scanner
- Includes:
- Helpers::OSCommon
- Defined in:
- lib/train/platforms/detect/scanner.rb
Instance Method Summary collapse
- #check_condition(condition) ⇒ Object
- #get_platform(plat) ⇒ Object
-
#initialize(backend) ⇒ Scanner
constructor
A new instance of Scanner.
-
#scan ⇒ Object
Main detect method to scan all platforms for a match.
- #scan_children(parent) ⇒ Object
- #scan_family_children(plat) ⇒ Object
Methods included from Helpers::OSCommon
#backend_name, #brocade_version, #cisco_show_version, #command_output, #json_cmd, #ruby_host_os, #set_from_uname, #unix_file_contents, #unix_file_exist?, #unix_uname_m, #unix_uname_r, #unix_uname_s, #unix_uuid, #unix_uuid_from_chef, #unix_uuid_from_machine_file, #uuid_from_command, #uuid_from_containerized_system, #uuid_from_string, #winrm?
Methods included from Helpers::Windows
#check_cmd, #check_powershell, #detect_windows, #local_windows?, #read_wmic, #read_wmic_cpu, #windows_uuid, #windows_uuid_from_chef, #windows_uuid_from_machine_file, #windows_uuid_from_registry, #windows_uuid_from_wmic
Methods included from Helpers::Linux
#linux_os_release, #lsb_config, #lsb_release, #parse_os_release_info, #read_linux_lsb, #redhatish, #redhatish_platform, #redhatish_version
Constructor Details
#initialize(backend) ⇒ Scanner
Returns a new instance of Scanner.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/train/platforms/detect/scanner.rb', line 7 def initialize(backend) @backend = backend @platform = {} @family_hierarchy = [] # detect cache variables @files = {} @uname = {} @lsb = {} @cache = {} end |
Instance Method Details
#check_condition(condition) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/train/platforms/detect/scanner.rb', line 65 def check_condition(condition) condition.each do |k, v| op, expected = v.strip.split(" ") op = "==" if op == "=" return false if @platform[k].nil? || !instance_eval("'#{@platform[k]}' #{op} '#{expected}'") end true end |
#get_platform(plat) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/train/platforms/detect/scanner.rb', line 75 def get_platform(plat) plat.backend = @backend plat.platform = @platform plat.add_platform_methods plat.family_hierarchy = @family_hierarchy plat end |
#scan ⇒ Object
Main detect method to scan all platforms for a match
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/train/platforms/detect/scanner.rb', line 22 def scan # start with the platform/families who have no families (the top levels) top = Train::Platforms.top_platforms top.each do |_name, plat| # we are doing a instance_eval here to make sure we have the proper # context with all the detect helper methods next unless instance_eval(&plat.detect) # if we have a match start looking at the children plat_result = scan_children(plat) next if plat_result.nil? # return platform to backend @family_hierarchy << plat.name return get_platform(plat_result) end raise Train::PlatformDetectionFailed, "Sorry, we are unable to detect your platform" end |
#scan_children(parent) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/train/platforms/detect/scanner.rb', line 42 def scan_children(parent) parent.children.each do |plat, condition| next unless instance_eval(&plat.detect) if plat.class == Train::Platforms::Platform return plat if condition.empty? || check_condition(condition) elsif plat.class == Train::Platforms::Family plat = scan_family_children(plat) return plat unless plat.nil? end end nil end |
#scan_family_children(plat) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/train/platforms/detect/scanner.rb', line 57 def scan_family_children(plat) child_result = scan_children(plat) unless plat.children.nil? return if child_result.nil? @family_hierarchy << plat.name child_result end |