-
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.
Add compliance information to a server
- Loading branch information
1 parent
2081cc4
commit 8d86983
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...iq/providers/lenovo/physical_infra_manager/parsers/components/compliance_policy_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,45 @@ | ||
require_relative 'component_parser' | ||
|
||
module ManageIQ::Providers::Lenovo | ||
module Parsers | ||
class CompliancePolicyParser < ComponentParser | ||
COMPLIANCE_NAME = 'No policy assigned'.freeze | ||
COMPLIANCE_STATUS = { | ||
'no' => 'Non-compliant', | ||
'yes' => 'Compliant', | ||
'' => 'None' | ||
}.freeze | ||
|
||
class << self | ||
|
||
def parse_compliance_policy(compliance_policies) | ||
parse_to_hash(compliance_policies) | ||
end | ||
|
||
private | ||
|
||
def map_by_uuid(collection) | ||
collection.collect do |result| | ||
policy_name = result['policyName'] | ||
data = { | ||
:policy_name => policy_name.empty? ? COMPLIANCE_NAME : policy_name, | ||
:status => "#{COMPLIANCE_STATUS[result['endpointCompliant']]} #{result['message'].join(', ')}", | ||
} | ||
# Return a tuple [key, value] for each result | ||
[result['uuid'], data] | ||
end.to_h | ||
end | ||
|
||
def parse_to_hash(persisted_results) | ||
persisted_results.collect do |persisted_result| | ||
if persisted_result.xITEs.present? | ||
map_by_uuid(persisted_result.xITEs) | ||
elsif persisted_result.racklist.present? | ||
map_by_uuid(persisted_result.racklist) | ||
end | ||
end.compact.reduce({}, :merge) | ||
end | ||
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
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
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
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