Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement asset details collector #1

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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