-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathrefresh_parser.rb
111 lines (87 loc) · 3.64 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
# rubocop:disable Naming/AccessorMethodName
module ManageIQ::Providers::Lenovo
class PhysicalInfraManager::RefreshParser < EmsRefresh::Parsers::Infra
include ManageIQ::Providers::Lenovo::RefreshHelperMethods
require_relative './parsers/parser'
require_relative './parsers/parser_dictionary_constants'
def self.miq_template_type
ManageIQ::Providers::Lenovo::ParserDictionaryConstants::MIQ_TYPES["template"]
end
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,
:port => ems.endpoints.first.port)
@options = options || {}
@data = {}
@data_index = {}
@host_hash_by_name = {}
@parser = init_parser(@connection)
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
discover_ip_physical_infra
get_config_patterns
$log.info("#{log_header}...Complete")
@data
end
private
# returns the specific parser based on the version of the appliance
def init_parser(connection)
version = connection.discover_aicc.first.appliance['version'] # getting the appliance version
ManageIQ::Providers::Lenovo::Parser.get_instance(version)
end
def get_physical_servers
nodes = all_server_resources
nodes = nodes.map do |node|
XClarityClient::Node.new node
end
process_collection(nodes, :physical_servers) { |node| @parser.parse_physical_server(node) }
end
def get_config_patterns
config_patterns = @connection.discover_config_pattern
process_collection(config_patterns, :customization_scripts) { |config_pattern| @parser.parse_config_pattern(config_pattern) }
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?
resolve_ip_address(hostname, @ems)
end
if @ems.hostname_ipaddress?(hostname)
resolve_hostname(hostname, @ems)
end
end
def resolve_hostname(ipaddress, ems)
ems.hostname = Resolv.getname(ipaddress)
$log.info("EMS ID: #{ems.id}" + " Resolved hostname successfully.")
rescue => err
$log.warn("EMS ID: #{ems.id}" + " It's not possible resolve hostname of the physical infra, #{err}.")
end
def resolve_ip_address(hostname, ems)
ems.ipaddress = Resolv.getaddress(hostname)
$log.info("EMS ID: #{ems.id}" + " Resolved ip address successfully.")
rescue => err
$log.warn("EMS ID: #{ems.id}" + " It's not possible resolve ip address of the physical infra, #{err}.")
end
end
end
# rubocop:enable Naming/AccessorMethodName