Skip to content

Commit

Permalink
Merge remote-tracking branch 'ManageIQ/master' into provider_discover
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielsvinha committed Jul 25, 2017
2 parents 9d4852e + df2a27b commit 9763347
Show file tree
Hide file tree
Showing 23 changed files with 886 additions and 48 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
--require spec_helper
--color
--order random
--exclude-pattern "spec/manageiq/**/*_spec.rb"
1 change: 1 addition & 0 deletions .rspec_ci
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
--color
--order random
--profile 25
--exclude-pattern "spec/manageiq/**/*_spec.rb"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

See the section on pluggable providers in the [ManageIQ Developer Setup](http://manageiq.org/docs/guides/developer_setup)

For quick local setup run `bin/setup`, which will clone the core ManageIQ repository under the *spec* directory and setup necessary config files. If you have already cloned it, you can run `bin/update` to bring the core ManageIQ code up to date.

## License

The gem is available as open source under the terms of the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
Expand Down
10 changes: 3 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
require 'bundler/setup'
require 'bundler/gem_tasks'

begin
require 'rspec/core/rake_task'

APP_RAKEFILE = File.expand_path("../spec/manageiq/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
load 'rails/tasks/statistics.rake'
rescue LoadError
end

namespace :spec do
desc "Setup environment for specs"
task :setup => 'app:test:providers:lenovo:setup'
end
require 'bundler/gem_tasks'

desc "Run all Lenovo specs"
task :spec => 'app:test:providers:lenovo'
FileList['lib/tasks_private/**/*.rake'].each { |r| load r }

task :default => :spec
6 changes: 4 additions & 2 deletions app/models/manageiq/providers/lenovo/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def connect(options = {})
username = options[:user] || authentication_userid(options[:auth_type])
password = options[:pass] || authentication_password(options[:auth_type])
host = options[:host]
port = options[:port]
# TODO: improve this SSL verification
verify_ssl = options[:verify_ssl] == 1 ? 'PEER' : 'NONE'
self.class.raw_connect(username, password, host, verify_ssl)
self.class.raw_connect(username, password, host, port, verify_ssl)
end

def translate_exception(err)
Expand All @@ -31,12 +32,13 @@ module ClassMethods
#
# Connections
#
def raw_connect(username, password, host, verify_ssl)
def raw_connect(username, password, host, port, verify_ssl)
require 'xclarity_client'
xclarity = XClarityClient::Configuration.new(
:username => username,
:password => password,
:host => host,
:port => port,
:verify_ssl => verify_ssl
)
XClarityClient::Client.new(xclarity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def create_event_monitor_handle(ems)

ems.connect(:user => ems_auth.userid,
:pass => ems_auth.password,
:host => ems.endpoints.first.hostname)
:host => ems.endpoints.first.hostname,
:port => ems.endpoints.first.port)
end

def get_last_cnn_from_events(ems_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def change_resource_state(verb, args, options = {})
endpoint = endpoints.first
client = connect(:user => auth.userid,
:pass => auth.password,
:host => endpoint.hostname)
:host => endpoint.hostname,
:port => endpoint.port)

# Turn on the location LED using the xclarity_client API
client.send(verb, args.ems_ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def initialize(ems, options = nil)
@ems = ems
@connection = ems.connect(:user => ems_auth.userid,
:pass => ems_auth.password,
:host => ems.endpoints.first.hostname)
:host => ems.endpoints.first.hostname,
:port => ems.endpoints.first.port)
@options = options || {}
@data = {}
@data_index = {}
Expand Down Expand Up @@ -66,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 @@ -105,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 @@ -120,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 @@ -138,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
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ unless gem_root.join("spec/manageiq").exist?
end

require gem_root.join("spec/manageiq/lib/manageiq/environment").to_s
ManageIQ::Environment.manageiq_plugin_setup
ManageIQ::Environment.manageiq_plugin_setup(gem_root)
2 changes: 1 addition & 1 deletion bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ else
end

require gem_root.join("spec/manageiq/lib/manageiq/environment").to_s
ManageIQ::Environment.manageiq_plugin_setup
ManageIQ::Environment.manageiq_plugin_update(gem_root)
2 changes: 0 additions & 2 deletions config/initializers/descendant_loader.rb

This file was deleted.

12 changes: 12 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
:ems:
:ems_lenovo:
:blacklisted_event_names: []
:event_handling:
:event_groups:
:http_proxy:
:lenovo:
:host:
:password:
:port:
:user:
2 changes: 2 additions & 0 deletions lib/manageiq-providers-lenovo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "manageiq/providers/lenovo/engine"
require "manageiq/providers/lenovo/version"
6 changes: 6 additions & 0 deletions lib/tasks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Tasks (.rake files) in this directory will be available in the main ManageIQ app.
They can be executed in the provider gem via the app: namespace

bin/rails app:<task>

Task private to the provider should go into lib/tasks/tasks_private.
10 changes: 10 additions & 0 deletions lib/tasks/lenovo.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#namespace :manageiq do
# namespace :providers do
# namespace :lenovo do
# desc "Explaining what the task does"
# task :your_task do
# # Task goes here
# end
# end
# end
#end
10 changes: 10 additions & 0 deletions lib/tasks_private/spec.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace :spec do
desc "Setup environment specs"
task :setup => ["app:test:vmdb:setup"]
end

desc "Run all specs"
RSpec::Core::RakeTask.new(:spec => ["app:test:initialize", "app:evm:compile_sti_loader"]) do |t|
spec_dir = File.expand_path("../../spec", __dir__)
EvmTestHelper.init_rspec_task(t, ['--require', File.join(spec_dir, 'spec_helper')])
end
2 changes: 1 addition & 1 deletion manageiq-providers-lenovo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config,lib}/**/*"]

s.add_dependency "xclarity_client", "~> 0.4.1"
s.add_dependency "xclarity_client", "~> 0.5.2"
s.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
s.add_development_dependency "webmock", "~> 2.1.0"
s.add_development_dependency "simplecov"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
let(:ems) do
FactoryGirl.create(:physical_infra_with_authentication,
:name => "LXCA",
:hostname => "https://10.243.9.123")
:hostname => "https://10.243.9.123",
:port => "443")
end

let(:stream) { described_class.new(ems) }
Expand Down
Loading

0 comments on commit 9763347

Please sign in to comment.