Skip to content

Commit

Permalink
Implement asset details collector
Browse files Browse the repository at this point in the history
New functionality from this commit stores information that is not
strictly related to the physical server to asset_details table that
serves as a source of data for summary view in ManageIQ UI.

Please take note that asset details mapping is fairly raw right now,
since mapping tree-like Redfish structures into flat array of XClarity
properties is not trivial and will probably need some tweaking based
on real data that we will get from test bed before we get it right.
  • Loading branch information
Tadej Borovšak committed May 30, 2018
1 parent 52b5b3e commit 146e89e
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@ class Inventory::Collector::PhysicalInfraManager < Inventory::Collector
def physical_servers
rf_client.Systems.Members.collect(&:raw)
end

def physical_server_details
rf_client.Systems.Members.collect { |s| get_server_location(s) }
end

private

def get_server_location(server)
loc = { :server_id => server["@odata.id"] }
return loc if server.Links.Chassis.length.zero?

chassis = [server.Links.Chassis.first]
while chassis.last.Links.respond_to?("ContainedBy")
chassis.push(chassis.last.Links.ContainedBy)
end
chassis.reduce(loc) do |acc, c|
acc.merge!(c.respond_to?(:Location) ? c.Location.raw : {})
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ManageIQ::Providers::Redfish
class Inventory::Parser::PhysicalInfraManager < Inventory::Parser
def parse
physical_servers
physical_server_details
end

private
Expand All @@ -28,5 +29,36 @@ def physical_servers
)
end
end

def physical_server_details
# TODO(tadeboro): There is no similar data in Redfish service, so
# mapping will need to be quite sophisticated if we would like to get
# more info into database.
collector.physical_server_details.each do |d|
server = persister.physical_servers.lazy_find(d[:server_id])
persister.physical_server_details.build(
:resource => server,
:contact => "",
:description => "",
:location => get_location(d),
:room => "",
:rack_name => get_rack(d),
:lowest_rack_unit => ""
)
end
end

def get_location(detail)
[
detail.dig("PostalAddress", "HouseNumber"),
detail.dig("PostalAddress", "Street"),
detail.dig("PostalAddress", "City"),
detail.dig("PostalAddress", "Country")
].compact.join(", ")
end

def get_rack(detail)
detail.dig("Placement", "Rack") || ""
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module ManageIQ::Providers::Redfish
class Inventory::Persister::PhysicalInfraManager < Inventory::Persister
def initialize_inventory_collections
add_inventory_collections(physical_infra, %i(physical_servers))
collections = %i(
physical_servers
physical_server_details
)
add_inventory_collections(physical_infra, collections)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,19 @@ def self.physical_servers(extra_attributes = {})
}
super(attributes.merge(extra_attributes))
end

def self.physical_server_details(extra_attributes = {})
attributes = {
:inventory_object_attributes => %i(
contact
description
location
room
rack_name
lowest_rack_unit
)
}
super(attributes.merge(extra_attributes))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class PhysicalInfraManager < ManageIQ::Providers::PhysicalInfraManager
include Vmdb::Logging
include ManagerMixin

has_many :physical_server_details,
:class_name => "AssetDetail",
:source => :asset_detail,
:through => :physical_servers,
:as => :physical_server

def self.ems_type
@ems_type ||= "redfish_ph_infra".freeze
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

assert_ems
assert_physical_servers
assert_physical_server_details
end
end
end

def assert_ems
expect(ems.physical_servers.count).to eq(1)
expect(ems.physical_servers.map(&:ems_ref)).to match_array([server_id])
expect(ems.physical_server_details.count).to eq(1)
end

def assert_physical_servers
Expand All @@ -45,4 +47,13 @@ def assert_physical_servers
:physical_rack_id => 0
)
end

def assert_physical_server_details
d = AssetDetail.find_by(:resource_type => "PhysicalServer")
# TODO(tadeboro): We need better source of data before we can create more
# meaningful test.
expect(d).to have_attributes(
:resource_type => "PhysicalServer"
)
end
end
Loading

0 comments on commit 146e89e

Please sign in to comment.