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

Persister: InventoryCollection building through add_collection() #104

Merged
merged 1 commit into from
Jul 23, 2018
Merged
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
201 changes: 0 additions & 201 deletions app/models/manageiq/providers/kubevirt/inventory/collections.rb

This file was deleted.

149 changes: 88 additions & 61 deletions app/models/manageiq/providers/kubevirt/inventory/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,96 +19,123 @@
#
class ManageIQ::Providers::Kubevirt::Inventory::Persister < ManagerRefresh::Inventory::Persister
def cluster_collection(targeted: false, ids: [])
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.ems_clusters(
:targeted => targeted,
:manager_uuids => ids,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :ems_clusters) do |builder|
builder.add_properties(
:manager_uuids => ids,
:targeted => targeted
)
end
end

def host_collection(targeted: false, ids: [])
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.hosts(
:targeted => targeted,
:manager_uuids => ids,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :hosts) do |builder|
builder.add_properties(
:manager_uuids => ids,
:targeted => targeted
)
end
end

def host_storage_collection(targeted: false)
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.host_storages(
:targeted => targeted,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :host_storages) do |builder|
builder.add_properties(
:targeted => targeted,
:parent_inventory_collections => %i(hosts)
)
builder.add_targeted_arel(lambda do |collection|
host_ids = collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
collection.parent.host_storages.references(:host).where(
:hosts => { :ems_ref => host_ids }
)
end)
end
end

def hw_collection(targeted: false)
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.hardwares(
:targeted => targeted,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :hardwares) do |builder|
builder.add_properties(
:targeted => targeted
)
end
end

def network_collection(targeted: false)
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.networks(
:targeted => targeted,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :networks) do |builder|
builder.add_properties(
:targeted => targeted,
:manager_ref => %i(hardware ipaddress),
:parent_inventory_collections => %i(vms)
)
end
end

def os_collection(targeted: false)
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.host_operating_systems(
:targeted => targeted,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :host_operating_systems) do |builder|
builder.add_properties(
:targeted => targeted,
:parent_inventory_collections => %i(hosts)
)
end
end

def template_collection(targeted: false, ids: [])
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.miq_templates(
:targeted => targeted,
:manager_uuids => ids,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :miq_templates) do |builder|
builder.add_properties(
:model_class => ::ManageIQ::Providers::Kubevirt::InfraManager::Template,
:targeted => targeted,
:manager_uuids => ids,
:parent_inventory_collections => %i(vms)
)
end
end

def storage_collection(targeted: false, ids: [])
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.storages(
:targeted => targeted,
:manager_uuids => ids,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :storages) do |builder|
builder.add_properties(
:targeted => targeted,
:manager_uuids => ids,
)
end
end

def vm_collection(targeted: false, ids: [])
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.vms(
:targeted => targeted,
:manager_uuids => ids,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :vms) do |builder|
builder.add_properties(
:targeted => targeted,
:manager_uuids => ids,
)
end
end

def vm_os_collection(targeted: false, ids: [])
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.operating_systems(
:targeted => targeted,
:manager_uuids => ids,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :operating_systems) do |builder|
builder.add_properties(
:targeted => targeted,
:manager_uuids => ids,
:manager_ref => %i(vm_or_template),
:parent_inventory_collections => %i(vms)
)
end
end

def disk_collection(targeted: false)
attributes = ManageIQ::Providers::Kubevirt::Inventory::Collections.disks(
:targeted => targeted,
:strategy => :local_db_find_missing_references
)
add_inventory_collection(attributes)
add_collection(infra, :disks) do |builder|
builder.add_properties(
:targeted => targeted,
)
end
end

protected

def strategy
:local_db_find_missing_references
end

def shared_options
{
:strategy => strategy,
:parent => manager.presence,
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def create_manager
manager = double
allow(manager).to receive(:name).and_return('mykubevirt')
allow(manager).to receive(:id).and_return(0)
allow(manager.class).to receive(:ems_type).and_return(::ManageIQ::Providers::Kubevirt::Constants::VENDOR)
manager
end

Expand Down
Loading