-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathrefresh_parser.rb
112 lines (90 loc) · 3.37 KB
/
refresh_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# rubocop:disable Style/AccessorMethodName
module ManageIQ::Providers::Lenovo
class PhysicalInfraManager::RefreshParser < EmsRefresh::Parsers::Infra
include ManageIQ::Providers::Lenovo::RefreshHelperMethods
def initialize(ems, options = nil)
ems_auth = ems.authentications.first
@ems = ems
@connection = ems.connect(:user => ems_auth.userid,
:pass => ems_auth.password,
:host => ems.endpoints.first.hostname)
@options = options || {}
@data = {}
@data_index = {}
@host_hash_by_name = {}
end
def ems_inv_to_hashes
log_header = "MIQ(#{self.class.name}.#{__method__}) Collecting data for EMS : [#{@ems.name}] id: [#{@ems.id} ref: #{@ems.uid_ems}]"
$log.info("#{log_header}...")
get_physical_servers
$log.info("#{log_header}...Complete")
@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
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
end
end