Skip to content

Commit

Permalink
Merge pull request #59 from skovic/network-adapter
Browse files Browse the repository at this point in the history
Update provider to support network adapters
  • Loading branch information
juliancheal authored Jul 24, 2017
2 parents 45b530d + e7be4da commit df2a27b
Show file tree
Hide file tree
Showing 3 changed files with 806 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,8 @@ def get_hardwares(node)
{
:memory_mb => get_memory_info(node),
:cpu_total_cores => get_total_cores(node),
:guest_devices => get_guest_devices(node),
:firmwares => get_firmwares(node.firmware)
}
end

def get_guest_devices(node)
[
{
:device_type => "ethernet",
:network => get_network(node),
:address => node.macAddress
}
]
end

def get_network(node)
{
:ipaddress => node.mgmtProcIPaddress,
:ipv6address => node.ipv6Addresses.join(", ")
:firmwares => get_firmwares(node),
:guest_devices => get_guest_devices(node)
}
end

Expand All @@ -106,12 +89,119 @@ def get_total_cores(node)
end

def get_firmwares(node)
firmwares = node.map do |firmware|
firmwares = node.firmware.map do |firmware|
parse_firmware(firmware)
end
firmwares
end

def get_guest_devices(node)
# Retrieve the addin cards associated with the node
addin_cards = get_addin_cards(node)
guest_devices = addin_cards.map do |addin_card|
addin_card
end

# Retrieve management devices
guest_devices.push(parse_management_device(node))

guest_devices
end

def get_addin_cards(node)
parsed_addin_cards = []

# For each of the node's addin cards, parse the addin card and then see
# if it is already in the list of parsed addin cards. If it is, see if
# all of its ports are already in the existing parsed addin card entry.
# If it's not, then add the port to the existing addin card entry and
# don't add the card again to the list of parsed addin cards.
# This is needed because xclarity_client seems to represent each port
# as a separate addin card. The code below ensures that each addin
# card is represented by a single addin card with multiple ports.
node_addin_cards = node.addinCards
unless node_addin_cards.nil?
node_addin_cards.each do |node_addin_card|
if get_device_type(node_addin_card) == "ethernet"
add_card = true
parsed_node_addin_card = parse_addin_cards(node_addin_card)

parsed_addin_cards.each do |addin_card|
if parsed_node_addin_card[:device_name] == addin_card[:device_name]
if parsed_node_addin_card[:location] == addin_card[:location]
parsed_node_addin_card[:child_devices].each do |parsed_port|
card_found = false

addin_card[:child_devices].each do |port|
if parsed_port[:device_name] == port[:device_name]
card_found = true
end
end

unless card_found
addin_card[:child_devices].push(parsed_port)
add_card = false
end
end
end
end
end

if add_card
parsed_addin_cards.push(parsed_node_addin_card)
end
end
end
end

parsed_addin_cards
end

def get_device_type(card)
device_type = ""

card_name = card["name"].downcase
if card_name.include?("nic") || card_name.include?("ethernet")
device_type = "ethernet"
end

device_type
end

def get_guest_device_ports(card)
device_ports = []

unless card.nil?
port_info = card["portInfo"]
physical_ports = port_info["physicalPorts"]
unless physical_ports.nil?
physical_ports.each do |physical_port|
parsed_physical_port = parse_physical_port(physical_port)
logical_ports = physical_port["logicalPorts"]
parsed_logical_port = parse_logical_port(logical_ports[0])
device_ports.push(parsed_logical_port.merge(parsed_physical_port))
end
end
end

device_ports
end

def get_guest_device_firmware(card)
device_fw = []

unless card.nil?
firmware = card["firmware"]
unless firmware.nil?
device_fw = firmware.map do |fw|
parse_firmware(fw)
end
end
end

device_fw
end

def parse_firmware(firmware)
{
:name => "#{firmware["role"]} #{firmware["name"]}-#{firmware["status"]}",
Expand All @@ -121,6 +211,50 @@ def parse_firmware(firmware)
}
end

def parse_management_device(node)
{
:device_type => "management",
:network => parse_management_network(node),
:address => node.macAddress
}
end

def parse_management_network(node)
{
:ipaddress => node.mgmtProcIPaddress,
:ipv6address => node.ipv6Addresses.join(", ")
}
end

def parse_addin_cards(addin_card)
{
:device_name => addin_card["productName"],
:device_type => get_device_type(addin_card),
:firmwares => get_guest_device_firmware(addin_card),
:manufacturer => addin_card["manufacturer"],
:field_replaceable_unit => addin_card["FRU"],
:location => "Bay #{addin_card['slotNumber']}",
:child_devices => get_guest_device_ports(addin_card)
}
end

def parse_physical_port(port)
{
:device_type => "ethernet port",
:device_name => "Physical Port #{port['physicalPortIndex']}"
}
end

def parse_logical_port(port)
{
:address => format_mac_address(port["addresses"])
}
end

def format_mac_address(mac_address)
mac_address.scan(/\w{2}/).join(":")
end

def parse_physical_server(node)
new_result = {
:type => ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer.name,
Expand All @@ -139,7 +273,7 @@ def parse_physical_server(node)
:health_state => HEALTH_STATE_MAP[node.cmmHealthState.downcase],
:vendor => "lenovo",
:computer_system => {
:hardware => {
:hardware => {
:guest_devices => [],
:firmwares => [] # Filled in later conditionally on what's available
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@
expect(result[:physical_servers].size).to eq(4)
end

it 'will retrieve addin cards on the physical servers' do
pim = FactoryGirl.create(:physical_infra,
:name => "LXCA",
:hostname => "https://10.243.9.123",
:ipaddress => "https://10.243.9.123")
auth = FactoryGirl.create(:authentication,
:userid => 'admin',
:password => 'password',
:authtype => 'default')
pim.authentications = [auth]
rp = described_class.new(pim)

result = VCR.use_cassette("#{described_class.name.underscore}_retrieve_addin_cards") do
rp.ems_inv_to_hashes
end

physical_server = result[:physical_servers][0]
computer_system = physical_server[:computer_system]
hardware = computer_system[:hardware]
guest_device = hardware[:guest_devices][0]

expect(guest_device[:device_name]).to eq("Broadcom 2-port 1GbE NIC Card for IBM")
expect(guest_device[:device_type]).to eq("ethernet")
expect(guest_device[:firmwares][0][:name]).to eq("Primary 17.4.4.2a-Active")
expect(guest_device[:firmwares][0][:version]).to eq("17.4.4.2a")
expect(guest_device[:manufacturer]).to eq("IBM")
expect(guest_device[:field_replaceable_unit]).to eq("90Y9373")
expect(guest_device[:location]).to eq("Bay 7")

expect(guest_device[:child_devices][0][:address]).to eq("00:0A:F7:25:67:38")
expect(guest_device[:child_devices][0][:device_type]).to eq("ethernet port")
expect(guest_device[:child_devices][0][:device_name]).to eq("Physical Port 1")
end

it 'will return its miq_template_type' do
expect(described_class.miq_template_type).to eq("ManageIQ::Providers::Lenovo::PhysicalInfraManager::Template")
end
Expand Down
Loading

0 comments on commit df2a27b

Please sign in to comment.