Skip to content

Commit

Permalink
InventoryCollection Builder
Browse files Browse the repository at this point in the history
Persister's add_collection() interface
  • Loading branch information
slemrmartin committed Jun 25, 2018
1 parent a130964 commit 9fcac27
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 262 deletions.
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

0 comments on commit 9fcac27

Please sign in to comment.