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() #288

Merged
merged 7 commits into from
Jun 14, 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
18 changes: 11 additions & 7 deletions app/models/manageiq/providers/openstack/inventory/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ManageIQ::Providers::Openstack::Inventory::Persister < ManagerRefresh::Inv
attr_reader :collector
# @param manager [ManageIQ::Providers::BaseManager] A manager object
# @param target [Object] A refresh Target object
# @param target [ManagerRefresh::Inventory::Collector] A Collector object
# @param collector [ManagerRefresh::Inventory::Collector] A Collector object
def initialize(manager, target = nil, collector = nil)
@manager = manager
@target = target
Expand All @@ -21,15 +21,19 @@ def initialize(manager, target = nil, collector = nil)

protected

def cloud
ManageIQ::Providers::Openstack::InventoryCollectionDefault::CloudManager
def strategy
nil
end

def network
ManageIQ::Providers::Openstack::InventoryCollectionDefault::NetworkManager
def parent
manager.presence
end

def storage
ManageIQ::Providers::Openstack::InventoryCollectionDefault::StorageManager
def shared_options
{
:parent => parent,
:strategy => strategy,
:targeted => targeted?
}
end
end
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
class ManageIQ::Providers::Openstack::Inventory::Persister::CinderManager < ManageIQ::Providers::Openstack::Inventory::Persister
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::CloudCollections
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::NetworkCollections
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::StorageCollections

def initialize_inventory_collections
add_inventory_collections(storage,
%i(
cloud_volumes
cloud_volume_snapshots
cloud_volume_backups
),
:builder_params => {:ext_management_system => manager})
initialize_storage_inventory_collections

initialize_cloud_inventory_collections
end

def initialize_cloud_inventory_collections
%i(vms
availability_zones
hardwares
cloud_tenants
disks).each do |name|

add_collection(cloud, name, shared_cloud_properties) do |builder|
builder.add_properties(:strategy => :local_db_cache_all) unless name == :disks
builder.add_properties(:complete => false) if name == :disks
end
end
end

add_inventory_collections(cloud,
%i(
vms
availability_zones
hardwares
cloud_tenants
),
:parent => manager.parent_manager,
:strategy => :local_db_cache_all)
private

add_inventory_collections(cloud,
%i(
disks
),
:parent => manager.parent_manager,
:complete => false)
def shared_cloud_properties
{ :parent => manager.parent_manager }
end
end
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
class ManageIQ::Providers::Openstack::Inventory::Persister::CloudManager < ManageIQ::Providers::Openstack::Inventory::Persister
def initialize_inventory_collections
add_inventory_collections(
cloud,
%i(
availability_zones
cloud_resource_quotas
cloud_services
cloud_tenants
flavors
host_aggregates
miq_templates
orchestration_stacks
vms
),
:builder_params => {:ext_management_system => manager}
)

add_inventory_collections(
cloud,
%i(
key_pairs
),
:builder_params => {:resource => manager}
)

add_inventory_collections(
cloud,
%i(
hardwares
operating_systems
disks
networks
orchestration_templates
orchestration_stacks_resources
orchestration_stacks_outputs
orchestration_stacks_parameters
)
)
include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::CloudCollections

add_inventory_collection(
cloud.vm_and_miq_template_ancestry(
:dependency_attributes => {
:vms => [collections[:vms]],
:miq_templates => [collections[:miq_templates]]
}
)
)

add_inventory_collection(
cloud.orchestration_stack_ancestry(
:dependency_attributes => {
:orchestration_stacks => [collections[:orchestration_stacks]],
}
)
)
def initialize_inventory_collections
initialize_cloud_inventory_collections
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
module ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::CloudCollections
extend ActiveSupport::Concern

include ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::Utils

# used also in ovirt, so automatic model_classes are not possible in many cases
def initialize_cloud_inventory_collections
add_vms

add_miq_templates

add_availability_zones

add_cloud_tenants

add_flavors

add_key_pairs

unless targeted?
add_cloud_resource_quotas

add_cloud_services

add_host_aggregates
end

add_orchestration_stacks_with_ems_param

%i(hardwares
operating_systems
disks
networks
orchestration_stacks_resources
orchestration_stacks_outputs
orchestration_stacks_parameters).each do |name|

add_collection(cloud, name)
end

add_orchestration_templates

add_vm_and_miq_template_ancestry

add_orchestration_stack_ancestry
end

# ------ IC provider specific definitions -------------------------

# model_class defined due to ovirt dependency
def add_vms
add_collection_with_ems_param(cloud, :vms) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::Vm)
end
end

def add_miq_templates
add_collection(cloud, :miq_templates) do |builder|
builder.add_properties(:model_class => ::MiqTemplate)

builder.add_builder_params(:ext_management_system => manager)

# Extra added to automatic attributes
builder.add_inventory_attributes(%i(cloud_tenant cloud_tenants))
end
end

# model_class defined due to ovirt dependency
def add_availability_zones
add_collection_with_ems_param(cloud, :availability_zones) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::AvailabilityZone)
end
end

# model_class defined due to ovirt dependency
def add_cloud_tenants
add_collection_with_ems_param(cloud, :cloud_tenants) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::CloudTenant)
end
end

# model_class defined due to ovirt dependency
def add_flavors
add_collection_with_ems_param(cloud, :flavors) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::Flavor)
end
end

# model_class defined due to ovirt dependency
def add_cloud_resource_quotas
add_collection_with_ems_param(cloud, :cloud_resource_quotas) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::CloudResourceQuota)
end
end

def add_cloud_services
add_collection_with_ems_param(cloud, :cloud_services)
end

# model_class defined due to ovirt dependency
def add_host_aggregates
add_collection_with_ems_param(cloud, :host_aggregates) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::CloudManager::HostAggregate)
end
end

def add_orchestration_stacks(extra_properties = {})
add_collection(cloud, :orchestration_stacks, extra_properties) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::CloudManager::OrchestrationStack)

yield builder if block_given?
end
end

def add_orchestration_templates
add_collection(cloud, :orchestration_templates) do |builder|
builder.add_properties(:model_class => ::OrchestrationTemplate)
end
end

# TODO: mslemr - parent model class used anywhere?
def add_key_pairs(extra_properties = {})
add_collection(cloud, :key_pairs, extra_properties) do |builder|
builder.add_properties(
:model_class => ManageIQ::Providers::Openstack::CloudManager::AuthKeyPair,
)

builder.add_builder_params(:resource => manager) unless targeted?
end
end

# TODO: mslemr - same as amazon!
def add_vm_and_miq_template_ancestry
add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_inventory_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder|
builder.add_dependency_attributes(
:vms => [collections[:vms]],
:miq_templates => [collections[:miq_templates]]
)
end
end

# TODO: mslemr - almost same as amazon!
# Needed remove_dependency_attributes for core basic definition
def add_orchestration_stack_ancestry
add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_inventory_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder|
builder.add_dependency_attributes(
:orchestration_stacks => [collections[:orchestration_stacks]]
)

if targeted?
builder.add_dependency_attributes(
:orchestration_stacks_resources => [collections[:orchestration_stacks_resources]]
)
end
end
end

protected

# Shortcut for better code readability
def add_orchestration_stacks_with_ems_param
add_orchestration_stacks do |builder|
builder.add_builder_params(:ext_management_system => manager)
end
end
end
Loading