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 Feb 21, 2018
1 parent 3184e10 commit db17f20
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 34 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,29 @@ 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)
# Parse a rack object to a hash with its data
#
# @param cab [XClarity::PhysicalRack] a rack object
# @param physical_servers [Hash] a already parsed physical_servers that belong to cab
#
# @return [Integer, Hash] 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
#
# @param node [XClarity::Node]Object containing physical server data
# @param 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, :inverse_of => :physical_racks,
:class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager"

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, :inverse_of => :physical_servers,
:class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager"

belongs_to :physical_rack, :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_physical_infra_from_rack
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 that can be obtained from a rack in LXCA (racks, chassis, servers)
# as XClarity objects and add it to the +@data+ as a hash.
def get_physical_infra_from_rack
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.
#
# @param cabinet [PhysicalRack] The rack from where it will retrieve the physical servers.
#
# Yields a XClarity Node object.
# @return [Hash] 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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@
computer_system = physical_server_with_disk[:computer_system]
hardware = computer_system[:hardware]

expect(hardware[:disk_capacity]).to eq(3_000_614_658_000)
physical_server_with_disk2 = @result[:physical_racks][0][:physical_servers][1]
computer_system2 = physical_server_with_disk2[:computer_system]
hardware2 = computer_system2[:hardware]

expect(hardware[:disk_capacity]).to eq(0)
expect(hardware2[:disk_capacity]).to eq(300_000_000_000)
end

it 'will try to retrieve disk capacity from a physical server without RAID information' do
Expand All @@ -91,4 +96,30 @@
expect(hardware[:disk_capacity]).to eq(0)
end
end

context 'retrieve physical rack info' do
let(:result) do
VCR.use_cassette("#{described_class.name.underscore}_ems_inv_to_hashes") do
refresh_parser.ems_inv_to_hashes
end
end

it 'will retrieve physical racks' do
expect(result[:physical_racks].size).to eq(1)
end

it 'will retrieve physical racks fields' do
physical_rack = result[:physical_racks].first

expect(physical_rack[:uid_ems]).to eq('096F8C92-08D4-4A24-ABD8-FE56D482F8C4')
expect(physical_rack[:name]).to eq('cabinet71')
end

it 'will retrieve physical servers in physical racks' do
physical_rack = result[:physical_racks].first
physical_servers = physical_rack[:physical_servers]

expect(physical_servers.size).to eq(1)
end
end
end
Loading

0 comments on commit db17f20

Please sign in to comment.