From 08331b54b5fa81f2d0f77704986c06cc5c6a2517 Mon Sep 17 00:00:00 2001 From: Greg Blomquist Date: Tue, 4 Apr 2017 12:58:07 -0400 Subject: [PATCH] Merge pull request #34 from juliancheal/refactor_refresh refactoring of refresh (cherry picked from commit e92dc1f7e335cca6fd8968aa2f9bcca2c5f0017d) --- .../providers/lenovo/manager_mixin.rb | 2 +- .../lenovo/physical_infra_manager.rb | 2 +- .../lenovo/physical_infra_manager/firmware.rb | 7 ++ .../physical_infra_manager/refresh_parser.rb | 108 ++++++++++-------- 4 files changed, 70 insertions(+), 49 deletions(-) create mode 100644 app/models/manageiq/providers/lenovo/physical_infra_manager/firmware.rb diff --git a/app/models/manageiq/providers/lenovo/manager_mixin.rb b/app/models/manageiq/providers/lenovo/manager_mixin.rb index fbbb67bde8..f80edfe156 100644 --- a/app/models/manageiq/providers/lenovo/manager_mixin.rb +++ b/app/models/manageiq/providers/lenovo/manager_mixin.rb @@ -14,7 +14,7 @@ def connect(options = {}) username = options[:user] || authentication_userid(options[:auth_type]) password = options[:pass] || authentication_password(options[:auth_type]) host = options[:host] - #TODO: improve this SSL verification + # TODO: improve this SSL verification verify_ssl = options[:verify_ssl] == 1 ? 'PEER' : 'NONE' self.class.raw_connect(username, password, host, verify_ssl) end diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager.rb index 2ff8bd9203..027451a1c5 100644 --- a/app/models/manageiq/providers/lenovo/physical_infra_manager.rb +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager.rb @@ -1,5 +1,5 @@ class ManageIQ::Providers::Lenovo::PhysicalInfraManager < ManageIQ::Providers::PhysicalInfraManager - has_many :physical_servers, foreign_key: "ems_id", class_name: "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer" + has_many :physical_servers, :foreign_key => "ems_id", :class_name => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer" include ManageIQ::Providers::Lenovo::ManagerMixin diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/firmware.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/firmware.rb new file mode 100644 index 0000000000..0f8497562c --- /dev/null +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/firmware.rb @@ -0,0 +1,7 @@ +module ManageIQ::Providers + class Lenovo::PhysicalInfraManager::Firmware < ::Firmware + def name + "firmware" + end + end +end diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/refresh_parser.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/refresh_parser.rb index d54f945527..94013a2fe6 100644 --- a/app/models/manageiq/providers/lenovo/physical_infra_manager/refresh_parser.rb +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/refresh_parser.rb @@ -1,3 +1,4 @@ +# rubocop:disable Style/AccessorMethodName module ManageIQ::Providers::Lenovo class PhysicalInfraManager::RefreshParser < EmsRefresh::Parsers::Infra include ManageIQ::Providers::Lenovo::RefreshHelperMethods @@ -27,9 +28,68 @@ def ems_inv_to_hashes @data end + def self.miq_template_type + "ManageIQ::Providers::Lenovo::PhysicalInfraManager::Template" + end + private def get_physical_servers + nodes = all_server_resources + + nodes = nodes.map do |node| + XClarityClient::Node.new node + end + process_collection(nodes, :physical_servers) { |node| parse_physical_server(node) } + end + + def get_hardwares(node) + {:firmwares => get_firmwares(node.firmware)} + end + + def get_firmwares(node) + firmwares = node.map do |firmware| + parse_firmware(firmware) + end + firmwares + end + + def parse_firmware(firmware) + { + :name => "#{firmware["role"]} #{firmware["name"]}-#{firmware["status"]}", + :build => firmware["build"], + :version => firmware["version"], + :release_date => firmware["date"], + } + end + + def parse_physical_server(node) + new_result = { + :type => ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer.name, + :name => node.name, + :ems_ref => node.uuid, + :uid_ems => @ems.uid_ems, + :hostname => node.hostname, + :product_name => node.productName, + :manufacturer => node.manufacturer, + :machine_type => node.machineType, + :model => node.model, + :serial_number => node.serialNumber, + :field_replaceable_unit => node.FRU, + :computer_system => { + :hardware => { + :networks => [], + :firmwares => [] # Filled in later conditionally on what's available + } + } + } + new_result[:computer_system][:hardware] = get_hardwares(node) + return node.uuid, new_result + end + + def all_server_resources + return @all_server_resources if @all_server_resources + cabinets = @connection.discover_cabinet(:status => "includestandalone") nodes = cabinets.map(&:nodeList).flatten @@ -46,53 +106,7 @@ def get_physical_servers nodes += nodes_chassis - nodes = nodes.map do |node| - Firmware.where(:ph_server_uuid => node["uuid"]).delete_all - - # TODO: (walteraa) see how to save it using process_collection - node["firmware"].map do |firmware| - f = Firmware.new parse_firmware(firmware, node["uuid"]) - f.save! - end - XClarityClient::Node.new node - end - process_collection(nodes, :physical_servers) { |node| parse_nodes(node) } - end - - def parse_firmware(firmware, uuid) - new_result = { - :name => firmware["name"], - :build => firmware["build"], - :version => firmware["version"], - :release_date => firmware["date"], - :ph_server_uuid => uuid - } - end - - def parse_nodes(node) - new_result = { - :type => ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer.name, - :name => node.name, - :ems_ref => node.uuid, - :uid_ems => @ems.uid_ems, - :hostname => node.hostname, - :product_name => node.productName, - :manufacturer => node.manufacturer, - :machine_type => node.machineType, - :model => node.model, - :serial_number => node.serialNumber, - :uuid => node.uuid, - :FRU => node.FRU, - :macAddresses => node.macAddress.split(",").flatten, - :ipv4Addresses => node.ipv4Addresses.split.flatten, - :ipv6Addresses => node.ipv6Addresses.split.flatten - } - - return node.uuid, new_result - end - - def self.miq_template_type - "ManageIQ::Providers::Lenovo::PhysicalInfraManager::Template" + @all_server_resources = nodes end end end