Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use SDK4 for refreshing #13742

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ def self.host_inv_to_guest_device_hashes(inv, switch_uids, ems_inv)
result = []
result_uids = {}
return result, result_uids if pnic.nil?

result_uids[:pnic] = {}
pnic.to_miq_a.each do |data|
# Find the switch to which this pnic is connected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,97 @@
module ManageIQ::Providers::Redhat::InfraManager::Refresh::Parse::Strategies
class Api4 < ManageIQ::Providers::Redhat::InfraManager::Refresh::Parse::Parser
def self.cluster_inv_to_hashes(inv)
result = []
result_uids = {}
result_res_pools = []
return result, result_uids, result_res_pools if inv.nil?

inv.each do |data|
mor = data.id

# Create a default Resource Pool for the cluster
default_res_pool = {
:name => "Default for Cluster #{data.name}",
:uid_ems => "#{mor}_respool",
:is_default => true,
:ems_children => {:vms => []}
}
result_res_pools << default_res_pool

ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(data.href)

new_result = {
:ems_ref => ems_ref,
:ems_ref_obj => ems_ref,
:uid_ems => data.id,
:name => data.name,

# Capture datacenter id so we can link up to it's sub-folders later
:datacenter_id => data.dig(:data_center, :id),

:ems_children => {:resource_pools => [default_res_pool]}
}

result << new_result
result_uids[mor] = new_result
end
return result, result_uids, result_res_pools
end

def self.storage_inv_to_hashes(inv)
result = []
result_uids = {:storage_id => {}}
return result, result_uids if inv.nil?

inv.each do |storage_inv|
mor = storage_inv.id

storage_type = storage_inv.dig(:storage, :type).upcase
location = if storage_type == 'NFS' || storage_type == 'GLUSTERFS'
"#{storage_inv.dig(:storage, :address)}:#{storage_inv.dig(:storage, :path)}"
else
storage_inv.dig(:storage, :volume_group, :logical_unit, :id)
end

free = storage_inv.try(:available).to_i
used = storage_inv.try(:used).to_i
total = free + used
committed = storage_inv.try(:committed).to_i
uncommitted = total - committed

ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(storage_inv.try(:href))

new_result = {
:ems_ref => ems_ref,
:ems_ref_obj => ems_ref,
:name => storage_inv.try(:name),
:store_type => storage_type,
:storage_domain_type => storage_inv.dig(:type, :downcase),
:total_space => total,
:free_space => free,
:uncommitted => uncommitted,
:multiplehostaccess => true,
:location => location,
:master => storage_inv.try(:master)
}

result << new_result
result_uids[mor] = new_result
result_uids[:storage_id][storage_inv.try(:id)] = new_result
end
return result, result_uids
end

def self.host_inv_to_hashes(inv, ems_inv, cluster_uids, storage_uids)
HostInventory.new(:inv => inv, :logger => _log).host_inv_to_hashes(inv, ems_inv, cluster_uids, storage_uids)
end

def self.vm_inv_to_hashes(inv, storage_inv, storage_uids, cluster_uids, host_uids, lan_uids)
VmInventory.new(:inv => inv, :logger => _log).vm_inv_to_hashes(inv, storage_inv, storage_uids, cluster_uids, host_uids, lan_uids)
end

def self.datacenter_inv_to_hashes(inv, cluster_uids, vm_uids, storage_uids, host_uids)
DatacenterInventory.new(:inv => inv, :logger => _log).datacenter_inv_to_hashes(inv, cluster_uids, vm_uids, storage_uids, host_uids)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module ManageIQ::Providers::Redhat::InfraManager::Refresh::Parse::Strategies
class DatacenterInventory
attr_reader :datacenter_inv, :_log

def initialize(args)
@datacenter_inv = args[:inv]
@_log = args[:logger]
end

def datacenter_inv_to_hashes(inv, cluster_uids, vm_uids, storage_uids, host_uids)
result = [{
:name => 'Datacenters',
:type => 'EmsFolder',
:uid_ems => 'root_dc',
:hidden => true,

:ems_children => {:folders => []}
}]
return result if inv.nil?

root_children = result.first[:ems_children][:folders]

inv.each do |data|
uid = data.id

host_folder = {:name => 'host', :type => 'EmsFolder', :uid_ems => "#{uid}_host", :hidden => true}
vm_folder = {:name => 'vm', :type => 'EmsFolder', :uid_ems => "#{uid}_vm", :hidden => true}

# Link clusters to datacenter host folder
clusters = cluster_uids.values.select { |c| c[:datacenter_id] == uid }
host_folder[:ems_children] = {:clusters => clusters}

# Link vms to datacenter vm folder
vms = vm_uids.values.select { |v| v.fetch_path(:ems_cluster, :datacenter_id) == uid }
vm_folder[:ems_children] = {:vms => vms}

ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(data.href)

new_result = {
:name => data.name,
:type => 'Datacenter',
:ems_ref => ems_ref,
:ems_ref_obj => ems_ref,
:uid_ems => uid,

:ems_children => {:folders => [host_folder, vm_folder]}
}

result << new_result
result << host_folder
result << vm_folder
root_children << new_result

# Link hosts to storages
hosts = host_uids.values.select { |v| v.fetch_path(:ems_cluster, :datacenter_id) == uid }
storage_ids = data.storage_domains.to_miq_a.collect(&:id)
hosts.each { |h| h[:storages] = storage_uids.values_at(*storage_ids).compact } unless storage_ids.blank?
end

result
end
end
end
Loading