Skip to content

Commit

Permalink
Change on how physical_server and physical_rack will be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
felipedf committed Jan 25, 2018
1 parent 3184e10 commit b9c7159
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ManageIQ::Providers::Lenovo::PhysicalInfraManager < ManageIQ::Providers::PhysicalInfraManager
has_many :physical_servers, :foreign_key => "ems_id", :class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer", :dependent => :destroy

has_many :physical_racks, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system,
:class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalRack"
has_many :physical_servers, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system,
:class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer"
include ManageIQ::Providers::Lenovo::ManagerMixin
include_concern 'Operations'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,28 @@ def self.get_instance(version)
parser.new
end

# parse a node object to a hash with physical servers data
# +node+ - object containing physical server data
def parse_physical_server(node)
#
# cab - PhysicalRack object
# physical_servers - Already parsed physical_servers that belong to cab
#
# Returns PhysicalRack UUID and a parsed hash from PhysicalRack and every components inside it
def parse_physical_rack(cab, physical_servers)
result = parse(cab, dictionary::PHYSICAL_RACK)
result[:physical_servers] = physical_servers

return cab.UUID, result
end

# Parse a node object to a hash with physical server data.
#
# node - Object containing physical server data.
# ems_id - The ems id from the ems which contains the server.
def parse_physical_server(node, ems_id = nil)
result = parse(node, dictionary::PHYSICAL_SERVER)

# Keep track of the ems where this server is in, so it won't be lost when we access a server through a rack.
result[:ems_id] = ems_id unless ems_id.nil?

result[:vendor] = "lenovo"
result[:type] = dictionary::MIQ_TYPES["physical_server"]
result[:power_state] = dictionary::POWER_STATE_MAP[node.powerStatus]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class ParserDictionaryConstants
},
}.freeze

PHYSICAL_RACK = {
:name => 'cabinetName',
:uid_ems => 'UUID',
}.freeze

CONFIG_PATTERNS = {
:manager_ref => 'id',
:name => 'name',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ManageIQ::Providers
class Lenovo::PhysicalInfraManager::PhysicalRack < ::PhysicalRack
belongs_to :ext_management_system, :foreign_key => :ems_id,
:class_name => "ManageIQ::Providers:::Lenovo::PhysicalInfraManager", :inverse_of => :physical_racks

has_many :physical_servers, :dependent => :destroy, :inverse_of => :physical_rack,
:class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer"
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module ManageIQ::Providers
class Lenovo::PhysicalInfraManager::PhysicalServer < ::PhysicalServer
belongs_to :ext_management_system, :foreign_key => :ems_id,
:class_name => "ManageIQ::Providers:::Lenovo::PhysicalInfraManager", :inverse_of => :physical_servers

belongs_to :physical_racks, :dependent => :destroy, :inverse_of => :physical_servers,
:class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalRack"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def ems_inv_to_hashes

$log.info("#{log_header}...")

get_physical_servers
get_all_physical_infra
discover_ip_physical_infra
get_config_patterns

Expand All @@ -47,15 +47,68 @@ def init_parser(connection)
ManageIQ::Providers::Lenovo::Parser.get_instance(version)
end

def get_physical_servers
nodes = all_server_resources
# Retrieve all physical infrastructure (racks, chassis, servers) as XClarity objects
# and adds it to the +@data+ as a hash.
def get_all_physical_infra
cabinets = get_physical_racks

nodes = nodes.map do |node|
XClarityClient::Node.new node
# Retrieve the standalone rack (mock of a rack) so it is possible to retrieve all components
# from it and associate with the provider instead a mock rack.
standalone = nil
cabinets.reverse_each do |cab|
if cab.UUID == 'STANDALONE_OBJECT_UUID'
standalone = cabinets.delete(cab)
break
end
end

# Process physical racks and all of its subcomponents.
process_collection(cabinets, :physical_racks) do |cab|
physical_servers = []
get_physical_servers(cab) do |node|
_, parsed = @parser.parse_physical_server(node, @ems.id)
physical_servers << parsed
end
@parser.parse_physical_rack(cab, physical_servers)
end

# Process physical servers and all of its subcomponents.
nodes = get_physical_servers(standalone)
process_collection(nodes, :physical_servers) { |node| @parser.parse_physical_server(node) }
end

# Returns all physical rack from the api.
def get_physical_racks
@connection.discover_cabinet(:status => "includestandalone")
end

# Create a XClarity Node object for every node in a rack.
#
# cabinet - The PhysicalRack from where it will retrieve the physical servers.
#
# Yields a XClarity Node object.
# Returns a parsed hash for every PhysicalServer that belongs to the cabinet.
def get_physical_servers(cabinet)
return if cabinet.nil?
chassis = cabinet.chassisList

nodes_chassis = chassis.map do |chassi|
chassi["itemInventory"]["nodes"]
end.flatten
nodes_chassis = nodes_chassis.reject { |node| node["type"] == "SCU" }

nodes = cabinet.nodeList
nodes = nodes.map { |node| node["itemInventory"] }

nodes += nodes_chassis

nodes.map do |node|
xc_node = XClarityClient::Node.new(node)
yield(xc_node) if block_given?
xc_node
end
end

def get_config_patterns
config_patterns = @connection.discover_config_pattern
process_collection(config_patterns, :customization_scripts) { |config_pattern| parse_config_pattern(config_pattern) }
Expand Down Expand Up @@ -173,28 +226,6 @@ def get_host_relationship(node)
Host.joins(:hardware).find_by('hardwares.serial_number' => node.serialNumber)
end

def all_server_resources
return @all_server_resources if @all_server_resources

cabinets = @connection.discover_cabinet(:status => "includestandalone")

nodes = cabinets.map(&:nodeList).flatten
nodes = nodes.map do |node|
node["itemInventory"]
end.flatten

chassis = cabinets.map(&:chassisList).flatten

nodes_chassis = chassis.map do |chassi|
chassi["itemInventory"]["nodes"]
end.flatten
nodes_chassis = nodes_chassis.select { |node| node["type"] != "SCU" }

nodes += nodes_chassis

@all_server_resources = nodes
end

def discover_ip_physical_infra
hostname = URI.parse(@ems.hostname).host || URI.parse(@ems.hostname).path
if @ems.ipaddress.blank?
Expand Down

0 comments on commit b9c7159

Please sign in to comment.