-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e615a3e
commit 94a2de5
Showing
7 changed files
with
372 additions
and
316 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
app/models/manageiq/providers/lenovo/physical_infra_manager/parsers/component_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module ManageIQ::Providers::Lenovo | ||
module Parsers | ||
# | ||
# Superclass extended by all classes that parses LXCA components | ||
# to a MiQ format | ||
# | ||
class ComponentParser | ||
# | ||
# Returns a hash containing the structure described on dictionary | ||
# and with the values in the source. | ||
# @param source - Object that will be parse to a hash | ||
# @param dictionary - Hash containing the instructions to translate the object into a Hash | ||
# @see ParserDictionaryConstants | ||
# | ||
def self.parse(source, dictionary) | ||
result = {} | ||
dictionary&.each do |key, value| | ||
if value.kind_of?(String) | ||
next if value.empty? | ||
source_keys = value.split('.') # getting source keys navigation | ||
source_value = source | ||
source_keys.each do |source_key| | ||
begin | ||
attr_method = source_value.method(source_key) # getting method to get the attribute value | ||
source_value = attr_method.call | ||
rescue NameError | ||
# when the key doesn't correspond to a method | ||
source_value = source_value[source_key] | ||
end | ||
end | ||
result[key] = source_value | ||
elsif value.kind_of?(Hash) | ||
result[key] = parse(source, dictionary[key]) | ||
end | ||
end | ||
result | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
app/models/manageiq/providers/lenovo/physical_infra_manager/parsers/config_pattern_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module ManageIQ::Providers::Lenovo | ||
module Parsers | ||
class ConfigPatternParser < ComponentParser | ||
# | ||
# Parses the config pattern object into a Hash | ||
# @param [XClarityClient::ConfigPattern] config_pattern - object containing config | ||
# pattern data | ||
# | ||
# @return [Hash] containing the config pattern informations | ||
# | ||
def self.parse_config_pattern(config_pattern) | ||
return config_pattern.id, parse(config_pattern, ParserDictionaryConstants::CONFIG_PATTERNS) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.