From 67ec22fe6911b0e12ac41baabf37d76fba7f9e60 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 26 Apr 2018 14:40:31 +0200 Subject: [PATCH 1/9] Inventory Collection Builder New Interface for definition/creating InventoryCollection from persister. --- .../providers/amazon/inventory/persister.rb | 20 +- .../inventory/persister/cloud_manager.rb | 59 ++-- .../inventory/persister/network_manager.rb | 60 +++- .../persister/shared/cloud_collections.rb | 84 +++++ .../persister/shared/network_collections.rb | 26 ++ .../persister/shared/storage_collections.rb | 58 ++++ .../persister/storage_manager/ebs.rb | 32 +- .../inventory/persister/storage_manager/s3.rb | 10 +- .../inventory/persister/target_collection.rb | 235 +++++++------- .../cloud_manager.rb | 291 ------------------ .../network_manager.rb | 261 ---------------- .../storage_manager.rb | 89 ------ 12 files changed, 407 insertions(+), 818 deletions(-) create mode 100644 app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb create mode 100644 app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb create mode 100644 app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb delete mode 100644 app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb delete mode 100644 app/models/manageiq/providers/amazon/inventory_collection_default/network_manager.rb delete mode 100644 app/models/manageiq/providers/amazon/inventory_collection_default/storage_manager.rb diff --git a/app/models/manageiq/providers/amazon/inventory/persister.rb b/app/models/manageiq/providers/amazon/inventory/persister.rb index ee087f6f5..39671da86 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister.rb @@ -10,7 +10,7 @@ class ManageIQ::Providers::Amazon::Inventory::Persister < ManagerRefresh::Invent # @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 @@ -30,18 +30,6 @@ def initialize_tag_mapper collections[:tags_to_resolve] = @tag_mapper.tags_to_resolve_collection end - def cloud - ManageIQ::Providers::Amazon::InventoryCollectionDefault::CloudManager - end - - def network - ManageIQ::Providers::Amazon::InventoryCollectionDefault::NetworkManager - end - - def storage - ManageIQ::Providers::Amazon::InventoryCollectionDefault::StorageManager - end - def targeted false end @@ -51,11 +39,9 @@ def strategy end def shared_options - settings_options = options[:inventory_collections].try(:to_hash) || {} - - settings_options.merge( + { :strategy => strategy, :targeted => targeted, - ) + } end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb index d2e892c85..28e9d6d4f 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb @@ -1,31 +1,40 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ::Providers::Amazon::Inventory::Persister + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections + def initialize_inventory_collections initialize_tag_mapper - add_inventory_collections( - cloud, - %i(vms miq_templates hardwares operating_systems networks disks availability_zones - vm_and_template_labels vm_and_template_taggings - flavors key_pairs orchestration_stacks orchestration_stacks_resources - orchestration_stacks_outputs orchestration_stacks_parameters orchestration_templates) - ) - - 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]], - :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] - } - ) - ) + %i(vms + hardwares + operating_systems + networks + disks + flavors + availability_zones).each do |name| + + add_collection(cloud, name) + end + + add_miq_templates + + add_key_pairs + + add_orchestration_stacks + + add_vm_and_template_labels + + add_vm_and_template_taggings + + %i(orchestration_stacks_resources + orchestration_stacks_outputs + orchestration_stacks_parameters + orchestration_templates).each do |name| + + add_collection(cloud, name) + end + + add_vm_and_miq_template_ancestry + + add_orchestration_stack_ancestry end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb index 2ac178bfe..c2e81622e 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb @@ -1,16 +1,54 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::NetworkManager < ManageIQ::Providers::Amazon::Inventory::Persister + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections + def initialize_inventory_collections - add_inventory_collections( - network, - %i(cloud_subnet_network_ports network_ports floating_ips cloud_subnets cloud_networks security_groups - firewall_rules load_balancers load_balancer_pools load_balancer_pool_members load_balancer_pool_member_pools - load_balancer_listeners load_balancer_listener_pools load_balancer_health_checks - load_balancer_health_check_members network_routers) - ) + initialize_network_inventory_collections + + initialize_cloud_inventory_collections + end + + private + + def initialize_network_inventory_collections + %i(network_ports + floating_ips + cloud_subnets + cloud_networks + security_groups + load_balancers + load_balancer_pools + load_balancer_pool_members + load_balancer_pool_member_pools + load_balancer_listeners + load_balancer_listener_pools + load_balancer_health_checks + load_balancer_health_check_members + network_routers).each do |name| + + add_collection(network, name) + end - add_inventory_collections(cloud, - %i(vms orchestration_stacks availability_zones), - :parent => manager.parent_manager, - :strategy => :local_db_cache_all) + add_cloud_subnet_network_ports + + add_firewall_rules + end + + def initialize_cloud_inventory_collections + %i(vms + availability_zones).each do |name| + + add_collection(cloud, name) do |builder| + builder.add_properties( + :parent => manager.parent_manager, + :strategy => :local_db_cache_all + ) + end + end + + add_orchestration_stacks( + :parent => manager.parent_manager, + :strategy => :local_db_cache_all + ) end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb new file mode 100644 index 000000000..461d2d426 --- /dev/null +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb @@ -0,0 +1,84 @@ +module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections + extend ActiveSupport::Concern + + included do + # Builder class for Cloud + def cloud + ::ManagerRefresh::InventoryCollection::Builder::CloudManager + end + + def add_miq_templates(extra_properties = {}) + add_collection(cloud, :miq_templates, extra_properties) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template) + builder.add_builder_params(:template => true) + end + end + + def add_flavors(extra_properties = {}) + add_collection(cloud, :flavors, extra_properties) + end + + def add_vm_and_template_labels + add_collection(cloud, :vm_and_template_labels) do |builder| + builder.add_targeted_arel( + lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + inventory_collection.parent.vm_and_template_labels.where( + 'vms' => {:ems_ref => manager_uuids} + ) + end + ) + end + end + + def add_vm_and_template_taggings + add_collection(cloud, :vm_and_template_taggings) do |builder| + builder.add_properties( + :model_class => Tagging, + :manager_ref => %i(taggable tag), + :parent_inventory_collections => %i(vms miq_templates) + ) + + builder.add_targeted_arel( + lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + ems = inventory_collection.parent + ems.vm_and_template_taggings.where( + 'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids) + ) + end + ) + end + end + + def add_key_pairs(extra_properties = {}) + add_collection(cloud, :key_pairs, extra_properties) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::AuthKeyPair) + end + end + + def add_orchestration_stacks(extra_properties = {}) + add_collection(cloud, :orchestration_stacks, extra_properties) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack) + end + end + + def add_vm_and_miq_template_ancestry + add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_object_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 + + def add_orchestration_stack_ancestry + add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_object_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| + builder.add_dependency_attributes( + :orchestration_stacks => [collections[:orchestration_stacks]], + :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] + ) + end + end + end +end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb new file mode 100644 index 000000000..e98238a45 --- /dev/null +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb @@ -0,0 +1,26 @@ +module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections + extend ActiveSupport::Concern + + included do + # Builder class for Network + def network + ::ManagerRefresh::InventoryCollection::Builder::NetworkManager + end + + def add_cloud_subnet_network_ports(extra_properties = {}) + add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| + builder.add_properties( + :manager_ref_allowed_nil => %i(cloud_subnet) + ) + end + end + + def add_firewall_rules(extra_properties = {}) + add_collection(network, :firewall_rules, extra_properties) do |builder| + builder.add_properties( + :manager_ref_allowed_nil => %i(source_security_group) + ) + end + end + end +end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb new file mode 100644 index 000000000..c32ca095d --- /dev/null +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb @@ -0,0 +1,58 @@ +module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + extend ActiveSupport::Concern + + included do + # Builder class for Storage + def storage + ::ManagerRefresh::InventoryCollection::Builder::StorageManager + end + + def add_cloud_volumes(extra_properties = {}) + add_collection(storage, :cloud_volumes, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume + ) + + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } + ) + end + end + + def add_cloud_volume_snapshots(extra_properties = {}) + add_collection(storage, :cloud_volume_snapshots, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot + ) + + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } + ) + end + end + + def add_cloud_object_store_containers(extra_properties = {}) + add_collection(storage, :cloud_object_store_containers, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer + ) + + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } + ) + end + end + + def add_cloud_object_store_objects(extra_properties = {}) + add_collection(storage, :cloud_object_store_objects, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject + ) + + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } + ) + end + end + end +end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb index ddc8e20b4..a9b27b426 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb @@ -1,13 +1,31 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::StorageManager::Ebs < ManageIQ::Providers::Amazon::Inventory::Persister + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + def initialize_inventory_collections - add_inventory_collections(storage, %i(cloud_volumes cloud_volume_snapshots)) + initialize_storage_inventory_collections + + initialize_cloud_inventory_collections + end + + def initialize_cloud_inventory_collections + add_cloud_volumes + + add_cloud_volume_snapshots + end + + def initialize_storage_inventory_collections + %i(availability_zones + hardwares + vms + disks).each do |name| - add_inventory_collections(cloud, %i(availability_zones hardwares vms), - :parent => manager.parent_manager, - :strategy => :local_db_cache_all) + add_collection(cloud, name) do |builder| + builder.add_properties(:parent => manager.parent_manager) - add_inventory_collections(cloud, %i(disks), - :parent => manager.parent_manager, - :update_only => true) + builder.add_properties(:update_only => true) if name == :disks + builder.add_properties(:strategy => :local_db_cache_all) unless name == :disks + end + end end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb index ef738b376..f0601dde0 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb @@ -1,5 +1,13 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::StorageManager::S3 < ManageIQ::Providers::Amazon::Inventory::Persister + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + def initialize_inventory_collections - add_inventory_collections(storage, %i(cloud_object_store_containers cloud_object_store_objects)) + initialize_storage_inventory_collections + end + + def initialize_storage_inventory_collections + add_cloud_object_store_containers + + add_cloud_object_store_objects end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb index 4cf3f0639..40838a93e 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb @@ -1,145 +1,148 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::TargetCollection < ManageIQ::Providers::Amazon::Inventory::Persister + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + + def targeted + true + end + + def strategy + :local_db_find_missing_references + end + def initialize_inventory_collections - ######### Cloud ########## initialize_tag_mapper - # Top level models with direct references for Cloud - add_inventory_collections_with_references( - cloud, - %i(vms miq_templates availability_zones orchestration_stacks) - ) - - add_inventory_collection_with_references( - cloud, - :key_pairs, - name_references(:key_pairs) - ) - - # Child models with references in the Parent InventoryCollections for Cloud - add_inventory_collections( - cloud, - %i(hardwares operating_systems networks disks vm_and_template_labels vm_and_template_taggings - orchestration_stacks_resources orchestration_stacks_outputs orchestration_stacks_parameters) - ) - - add_inventory_collection(cloud.orchestration_templates) - - ######### Network ################ - # Top level models with direct references for Network - add_inventory_collections_with_references( - network, - %i(cloud_networks cloud_subnets security_groups load_balancers), - :parent => manager.network_manager - ) - - add_inventory_collection_with_references( - network, - :network_ports, - references(:vms) + references(:network_ports) + references(:load_balancers), - :parent => manager.network_manager - ) - - add_inventory_collection_with_references( - network, - :floating_ips, - references(:floating_ips) + references(:load_balancers), - :parent => manager.network_manager - ) - - # Child models with references in the Parent InventoryCollections for Network - add_inventory_collections( - network, - %i(firewall_rules cloud_subnet_network_ports load_balancer_pools load_balancer_pool_members - load_balancer_pool_member_pools load_balancer_listeners load_balancer_listener_pools - load_balancer_health_checks load_balancer_health_check_members), - :parent => manager.network_manager - ) - - ######### Storage ############## - # Top level models with direct references for Network - add_inventory_collections_with_references( - storage, - %i(cloud_volumes cloud_volume_snapshots), - :parent => manager.ebs_storage_manager - ) + initialize_cloud_inventory_collections - if manager.s3_storage_manager - add_inventory_collections_with_references( - storage, - %i(cloud_object_store_containers cloud_object_store_objects), - :parent => manager.s3_storage_manager - ) - end + initialize_network_inventory_collections - # Model we take just from a DB, there is no flavors API - add_inventory_collections( - cloud, - %i(flavors), - :strategy => :local_db_find_references - ) - - ######## Custom processing of Ancestry ########## - 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]], - :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] - } - ) - ) + initialize_storage_inventory_collections end private - def add_inventory_collections_with_references(inventory_collections_data, names, options = {}) - names.each do |name| - add_inventory_collection_with_references(inventory_collections_data, name, references(name), options) - end + def initialize_cloud_inventory_collections + init_cloud_ics_top_level_models + + init_cloud_ics_child_models + + # Custom processing of Ancestry + add_vm_and_miq_template_ancestry + + add_orchestration_stack_ancestry end - def add_inventory_collection_with_references(inventory_collections_data, name, manager_refs, options = {}) - options = shared_options.merge(inventory_collections_data.send( - name, - :manager_uuids => manager_refs, - ).merge(options)) + # Top level models with direct references for Cloud + def init_cloud_ics_top_level_models + %i(vms availability_zones).each do |name| + add_collection(cloud, name, :manager_uuids => references(name)) + end + + add_miq_templates(:manager_uuids => references(:miq_templates)) - add_inventory_collection(options) + add_orchestration_stacks(:manager_uuids => references(:orchestration_stacks)) + + add_key_pairs(:manager_uuids => name_references(:key_pairs)) end - def targeted - true + # Child models with references in the Parent InventoryCollections for Cloud + def init_cloud_ics_child_models + %i(hardwares + operating_systems + networks + disks + orchestration_stacks_resources + orchestration_stacks_outputs + orchestration_stacks_parameters + orchestration_templates).each do |name| + + add_collection(cloud, name) + end + + add_vm_and_template_labels + + add_vm_and_template_taggings + + # Model we take just from a DB, there is no flavors API + add_flavors(:strategy => :local_db_find_references) end - def strategy - :local_db_find_missing_references + def initialize_network_inventory_collections + initialize_network_ics_top_level_models + + initialize_network_ics_child_models end - def references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :ems_ref).try(:to_a) || [] + # Top level models with direct references for Network + def initialize_network_ics_top_level_models + %i(cloud_networks + cloud_subnets + security_groups + load_balancers).each do |name| + + add_collection(network, name, :manager_uuids => references(name)) do |builder| + builder.add_properties(:parent => manager.network_manager) + end + end + + add_collection(network, :network_ports, :manager_uuids => references(:vms) + references(:network_ports) + references(:load_balancers)) do |builder| + builder.add_properties(:parent => manager.network_manager) + end + + add_collection(network, :floating_ips, :manager_uuids => references(:floating_ips) + references(:load_balancers)) do |builder| + builder.add_properties(:parent => manager.network_manager) + end end - def name_references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :name).try(:to_a) || [] + # Child models with references in the Parent InventoryCollections for Network + def initialize_network_ics_child_models + add_firewall_rules(:parent => manager.network_manager) + + add_cloud_subnet_network_ports(:parent => manager.network_manager) + + %i(load_balancer_pools + load_balancer_pool_members + load_balancer_pool_member_pools + load_balancer_listeners + load_balancer_listener_pools + load_balancer_health_checks + load_balancer_health_check_members).each do |name| + + add_collection(network, name) do |builder| + builder.add_properties(:parent => manager.network_manager) + end + end end - def cloud - ManageIQ::Providers::Amazon::InventoryCollectionDefault::CloudManager + # Top level models with direct references for Network + def initialize_storage_inventory_collections + add_cloud_volumes(:manager_uuids => references(:cloud_volumes)) do |builder| + builder.add_properties(:parent => manager.ebs_storage_manager) + end + + add_cloud_volume_snapshots(:manager_uuids => references(:cloud_volume_snapshots)) do |builder| + builder.add_properties(:parent => manager.ebs_storage_manager) + end + + if manager.s3_storage_manager + + add_cloud_object_store_containers(:manager_uuids => references(:cloud_object_store_containers)) do |builder| + builder.add_properties(:parent => manager.s3_storage_manager) + end + + add_cloud_object_store_objects(:manager_uuids => references(:cloud_object_store_objects)) do |builder| + builder.add_properties(:parent => manager.s3_storage_manager) + end + end end - def network - ManageIQ::Providers::Amazon::InventoryCollectionDefault::NetworkManager + def references(collection) + target.manager_refs_by_association.try(:[], collection).try(:[], :ems_ref).try(:to_a) || [] end - def storage - ManageIQ::Providers::Amazon::InventoryCollectionDefault::StorageManager + def name_references(collection) + target.manager_refs_by_association.try(:[], collection).try(:[], :name).try(:to_a) || [] end end diff --git a/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb deleted file mode 100644 index c1fc98733..000000000 --- a/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb +++ /dev/null @@ -1,291 +0,0 @@ -class ManageIQ::Providers::Amazon::InventoryCollectionDefault::CloudManager < ManagerRefresh::InventoryCollectionDefault::CloudManager - class << self - def vms(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::Vm, - :inventory_object_attributes => [ - :type, - :ems_id, - :uid_ems, - :ems_ref, - :name, - :vendor, - :raw_power_state, - :boot_time, - :availability_zone, - :flavor, - :genealogy_parent, - :key_pairs, - :location, - :orchestration_stack, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.id }, - :vendor => "amazon", - } - } - super(attributes.merge!(extra_attributes)) - end - - def miq_templates(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template, - :inventory_object_attributes => [ - :type, - :ems_id, - :uid_ems, - :ems_ref, - :name, - :location, - :vendor, - :raw_power_state, - :template, - :publicly_available, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.id }, - :vendor => "amazon", - :template => true - } - } - - super(attributes.merge!(extra_attributes)) - end - - def hardwares(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :guest_os, - :bitness, - :virtualization_type, - :root_device_type, - :vm_or_template, - :root_device_type, - :cpu_sockets, - :cpu_cores_per_socket, - :cpu_total_cores, - :memory_mb, - :disk_capacity, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def operating_systems(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :product_name, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def networks(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :hardware, - :ipaddress, - :hostname, - :description, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def availability_zones(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::AvailabilityZone, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def flavors(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::Flavor, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :description, - :enabled, - :cpus, - :cpu_cores, - :memory, - :supports_32_bit, - :supports_64_bit, - :supports_hvm, - :supports_paravirtual, - :block_storage_based_only, - :cloud_subnet_required, - :ephemeral_disk_size, - :ephemeral_disk_count, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def key_pairs(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::AuthKeyPair, - :inventory_object_attributes => [ - :type, - :resource, - :name, - :fingerprint, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def vm_and_template_labels(extra_attributes = {}) - # TODO(lsmola) make a generic CustomAttribute IC and move it to base class - attributes = { - :model_class => CustomAttribute, - :association => :vm_and_template_labels, - :manager_ref => [:resource, :name], - :parent_inventory_collections => [:vms, :miq_templates], - :inventory_object_attributes => [ - :resource, - :section, - :name, - :value, - :source, - ] - } - - attributes[:targeted_arel] = lambda do |inventory_collection| - manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten - inventory_collection.parent.vm_and_template_labels.where( - 'vms' => {:ems_ref => manager_uuids} - ) - end - - attributes.merge!(extra_attributes) - end - - def vm_and_template_taggings(extra_attributes = {}) - # TODO: make a generic Taggings IC and move it to base class? - attributes = { - :model_class => Tagging, - :association => :vm_and_template_taggings, - :manager_ref => [:taggable, :tag], - :parent_inventory_collections => [:vms, :miq_templates], - :inventory_object_attributes => [ - :taggable, - :tag, - ] - } - - attributes[:targeted_arel] = lambda do |inventory_collection| - manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten - ems = inventory_collection.parent - ems.vm_and_template_taggings.where( - 'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids) - ) - end - - attributes.merge!(extra_attributes) - end - - def orchestration_stacks(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :description, - :status, - :status_reason, - :parent, - :orchestration_template, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def orchestration_stacks_resources(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :ems_ref, - :stack, - :name, - :logical_resource, - :physical_resource, - :resource_category, - :resource_status, - :resource_status_reason, - :last_updated, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def orchestration_stacks_outputs(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :ems_ref, - :stack, - :key, - :value, - :description, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def orchestration_stacks_parameters(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :ems_ref, - :stack, - :name, - :value, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def orchestration_templates(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationTemplate, - :inventory_object_attributes => [ - :type, - :ems_ref, - :name, - :description, - :content, - :orderable, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def disks(extra_attributes = {}) - attributes = { - :inventory_object_attributes => %i(hardware device_name device_type controller_type location size backing), - } - - super(attributes.merge!(extra_attributes)) - end - end -end diff --git a/app/models/manageiq/providers/amazon/inventory_collection_default/network_manager.rb b/app/models/manageiq/providers/amazon/inventory_collection_default/network_manager.rb deleted file mode 100644 index 5713980fd..000000000 --- a/app/models/manageiq/providers/amazon/inventory_collection_default/network_manager.rb +++ /dev/null @@ -1,261 +0,0 @@ -class ManageIQ::Providers::Amazon::InventoryCollectionDefault::NetworkManager < ManagerRefresh::InventoryCollectionDefault::NetworkManager - class << self - def network_ports(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::NetworkPort, - :inventory_object_attributes => [ - :type, - :ems_id, - :name, - :ems_ref, - :status, - :mac_address, - :device_owner, - :device_ref, - :device, - :security_groups, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def cloud_subnet_network_ports(extra_attributes = {}) - attributes = { - :manager_ref_allowed_nil => [:cloud_subnet], - :inventory_object_attributes => [ - :address, - :cloud_subnet, - :network_port, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def floating_ips(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::FloatingIp, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :address, - :fixed_ip_address, - :cloud_network_only, - :cloud_network, - :network_port, - :status, - :vm, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def cloud_subnets(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::CloudSubnet, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :cidr, - :status, - :availability_zone, - :cloud_network, - :network_router, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def cloud_networks(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::CloudNetwork, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :cidr, - :status, - :enabled, - :orchestration_stack, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def security_groups(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::SecurityGroup, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :description, - :cloud_network, - :orchestration_stack, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def firewall_rules(extra_attributes = {}) - attributes = { - :manager_ref_allowed_nil => [:source_security_group], - :inventory_object_attributes => [ - :direction, - :host_protocol, - :port, - :end_port, - :resource, - :source_security_group, - :source_ip_range, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def network_routers(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::NetworkRouter, - :association => :network_routers, - :inventory_object_attributes => [ - :type, - :name, - :status, - :extra_attributes, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id }, - } - } - - attributes.merge!(extra_attributes) - end - - def load_balancers(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::LoadBalancer, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_pools(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::LoadBalancerPool, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_pool_members(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::LoadBalancerPoolMember, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :vm, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_pool_member_pools(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :load_balancer_pool, - :load_balancer_pool_member, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_listeners(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::LoadBalancerListener, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :load_balancer_protocol, - :load_balancer_port_range, - :instance_protocol, - :instance_port_range, - :load_balancer, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_listener_pools(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :load_balancer_listener, - :load_balancer_pool, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_health_checks(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::NetworkManager::LoadBalancerHealthCheck, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :protocol, - :port, - :url_path, - :interval, - :timeout, - :unhealthy_threshold, - :healthy_threshold, - :load_balancer, - ] - } - - super(attributes.merge!(extra_attributes)) - end - - def load_balancer_health_check_members(extra_attributes = {}) - attributes = { - :inventory_object_attributes => [ - :load_balancer_health_check, - :load_balancer_pool_member, - :status, - :status_reason, - ] - } - - super(attributes.merge!(extra_attributes)) - end - end -end diff --git a/app/models/manageiq/providers/amazon/inventory_collection_default/storage_manager.rb b/app/models/manageiq/providers/amazon/inventory_collection_default/storage_manager.rb deleted file mode 100644 index c8ee22edf..000000000 --- a/app/models/manageiq/providers/amazon/inventory_collection_default/storage_manager.rb +++ /dev/null @@ -1,89 +0,0 @@ -class ManageIQ::Providers::Amazon::InventoryCollectionDefault::StorageManager < ManagerRefresh::InventoryCollectionDefault::StorageManager - class << self - def cloud_volumes(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :status, - :creation_time, - :volume_type, - :size, - :base_snapshot, - :availability_zone, - :iops, - :encrypted, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id }, - } - } - - super(attributes.merge!(extra_attributes)) - end - - def cloud_volume_snapshots(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot, - :inventory_object_attributes => [ - :type, - :ems_id, - :ems_ref, - :name, - :status, - :creation_time, - :description, - :size, - :cloud_volume, - :encrypted, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id }, - } - } - - super(attributes.merge!(extra_attributes)) - end - - def cloud_object_store_containers(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer, - :inventory_object_attributes => [ - :ems_id, - :ems_ref, - :key, - :bytes, - :object_count, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id }, - } - } - - super(attributes.merge!(extra_attributes)) - end - - def cloud_object_store_objects(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject, - :inventory_object_attributes => [ - :ems_id, - :ems_ref, - :etag, - :last_modified, - :content_length, - :key, - :cloud_object_store_container, - ], - :builder_params => { - :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id }, - } - } - - super(attributes.merge!(extra_attributes)) - end - end -end From 14721a16ff4dcf007b859cf34bd02fed4275d2e6 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 2 May 2018 14:58:04 +0200 Subject: [PATCH 2/9] Removed included do from mixins --- .../persister/shared/cloud_collections.rb | 124 +++++++++--------- .../persister/shared/network_collections.rb | 32 +++-- .../persister/shared/storage_collections.rb | 80 ++++++----- 3 files changed, 115 insertions(+), 121 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb index 461d2d426..4330ddbc4 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb @@ -1,84 +1,82 @@ module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections extend ActiveSupport::Concern - included do - # Builder class for Cloud - def cloud - ::ManagerRefresh::InventoryCollection::Builder::CloudManager - end + # Builder class for Cloud + def cloud + ::ManagerRefresh::InventoryCollection::Builder::CloudManager + end - def add_miq_templates(extra_properties = {}) - add_collection(cloud, :miq_templates, extra_properties) do |builder| - builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template) - builder.add_builder_params(:template => true) - end + def add_miq_templates(extra_properties = {}) + add_collection(cloud, :miq_templates, extra_properties) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template) + builder.add_builder_params(:template => true) end + end - def add_flavors(extra_properties = {}) - add_collection(cloud, :flavors, extra_properties) - end + def add_flavors(extra_properties = {}) + add_collection(cloud, :flavors, extra_properties) + end - def add_vm_and_template_labels - add_collection(cloud, :vm_and_template_labels) do |builder| - builder.add_targeted_arel( - lambda do |inventory_collection| - manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten - inventory_collection.parent.vm_and_template_labels.where( - 'vms' => {:ems_ref => manager_uuids} - ) - end - ) - end + def add_vm_and_template_labels + add_collection(cloud, :vm_and_template_labels) do |builder| + builder.add_targeted_arel( + lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + inventory_collection.parent.vm_and_template_labels.where( + 'vms' => {:ems_ref => manager_uuids} + ) + end + ) end + end - def add_vm_and_template_taggings - add_collection(cloud, :vm_and_template_taggings) do |builder| - builder.add_properties( - :model_class => Tagging, - :manager_ref => %i(taggable tag), - :parent_inventory_collections => %i(vms miq_templates) - ) + def add_vm_and_template_taggings + add_collection(cloud, :vm_and_template_taggings) do |builder| + builder.add_properties( + :model_class => Tagging, + :manager_ref => %i(taggable tag), + :parent_inventory_collections => %i(vms miq_templates) + ) - builder.add_targeted_arel( - lambda do |inventory_collection| - manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten - ems = inventory_collection.parent - ems.vm_and_template_taggings.where( - 'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids) - ) - end - ) - end + builder.add_targeted_arel( + lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + ems = inventory_collection.parent + ems.vm_and_template_taggings.where( + 'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids) + ) + end + ) end + end - def add_key_pairs(extra_properties = {}) - add_collection(cloud, :key_pairs, extra_properties) do |builder| - builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::AuthKeyPair) - end + def add_key_pairs(extra_properties = {}) + add_collection(cloud, :key_pairs, extra_properties) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::AuthKeyPair) end + end - def add_orchestration_stacks(extra_properties = {}) - add_collection(cloud, :orchestration_stacks, extra_properties) do |builder| - builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack) - end + def add_orchestration_stacks(extra_properties = {}) + add_collection(cloud, :orchestration_stacks, extra_properties) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack) end + end - def add_vm_and_miq_template_ancestry - add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_object_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 + def add_vm_and_miq_template_ancestry + add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_object_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 - def add_orchestration_stack_ancestry - add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_object_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| - builder.add_dependency_attributes( - :orchestration_stacks => [collections[:orchestration_stacks]], - :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] - ) - end + def add_orchestration_stack_ancestry + add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_object_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| + builder.add_dependency_attributes( + :orchestration_stacks => [collections[:orchestration_stacks]], + :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] + ) end end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb index e98238a45..1b60932a1 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb @@ -1,26 +1,24 @@ module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections extend ActiveSupport::Concern - included do - # Builder class for Network - def network - ::ManagerRefresh::InventoryCollection::Builder::NetworkManager - end + # Builder class for Network + def network + ::ManagerRefresh::InventoryCollection::Builder::NetworkManager + end - def add_cloud_subnet_network_ports(extra_properties = {}) - add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| - builder.add_properties( - :manager_ref_allowed_nil => %i(cloud_subnet) - ) - end + def add_cloud_subnet_network_ports(extra_properties = {}) + add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| + builder.add_properties( + :manager_ref_allowed_nil => %i(cloud_subnet) + ) end + end - def add_firewall_rules(extra_properties = {}) - add_collection(network, :firewall_rules, extra_properties) do |builder| - builder.add_properties( - :manager_ref_allowed_nil => %i(source_security_group) - ) - end + def add_firewall_rules(extra_properties = {}) + add_collection(network, :firewall_rules, extra_properties) do |builder| + builder.add_properties( + :manager_ref_allowed_nil => %i(source_security_group) + ) end end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb index c32ca095d..50f9ee311 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb @@ -1,58 +1,56 @@ module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections extend ActiveSupport::Concern - included do - # Builder class for Storage - def storage - ::ManagerRefresh::InventoryCollection::Builder::StorageManager - end + # Builder class for Storage + def storage + ::ManagerRefresh::InventoryCollection::Builder::StorageManager + end - def add_cloud_volumes(extra_properties = {}) - add_collection(storage, :cloud_volumes, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume - ) + def add_cloud_volumes(extra_properties = {}) + add_collection(storage, :cloud_volumes, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume + ) - builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } - ) - end + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } + ) end + end - def add_cloud_volume_snapshots(extra_properties = {}) - add_collection(storage, :cloud_volume_snapshots, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot - ) + def add_cloud_volume_snapshots(extra_properties = {}) + add_collection(storage, :cloud_volume_snapshots, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot + ) - builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } - ) - end + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } + ) end + end - def add_cloud_object_store_containers(extra_properties = {}) - add_collection(storage, :cloud_object_store_containers, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer - ) + def add_cloud_object_store_containers(extra_properties = {}) + add_collection(storage, :cloud_object_store_containers, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer + ) - builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } - ) - end + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } + ) end + end - def add_cloud_object_store_objects(extra_properties = {}) - add_collection(storage, :cloud_object_store_objects, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject - ) + def add_cloud_object_store_objects(extra_properties = {}) + add_collection(storage, :cloud_object_store_objects, extra_properties) do |builder| + builder.add_properties( + :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject + ) - builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } - ) - end + builder.add_builder_params( + :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } + ) end end end From 77c019815abcf9c7b8b707aae3ea27b87abfdd3e Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 2 May 2018 15:04:53 +0200 Subject: [PATCH 3/9] Extracted storage managers ids from builder_params --- .../persister/shared/storage_collections.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb index 50f9ee311..dd2d0535e 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb @@ -13,7 +13,7 @@ def add_cloud_volumes(extra_properties = {}) ) builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } + :ems_id => block_storage_manager_id ) end end @@ -25,7 +25,7 @@ def add_cloud_volume_snapshots(extra_properties = {}) ) builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:ebs_storage_manager).try(:id) || persister.manager.id } + :ems_id => block_storage_manager_id ) end end @@ -37,7 +37,7 @@ def add_cloud_object_store_containers(extra_properties = {}) ) builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } + :ems_id => object_storage_manager_id ) end end @@ -49,8 +49,18 @@ def add_cloud_object_store_objects(extra_properties = {}) ) builder.add_builder_params( - :ems_id => ->(persister) { persister.manager.try(:s3_storage_manager).try(:id) || persister.manager.id } + :ems_id => object_storage_manager_id ) end end + + protected + + def block_storage_manager_id + manager.try(:ebs_storage_manager).try(:id) || manager.id + end + + def object_storage_manager_id + manager.try(:s3_storage_manager).try(:id) || manager.id + end end From 1ae44255115175dc42e2914df406bb618b1ff60b Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 3 May 2018 11:49:44 +0200 Subject: [PATCH 4/9] Unified InventoryCollection building Across cloud,network,storage man. and target coll. --- .../providers/amazon/inventory/persister.rb | 4 +- .../inventory/persister/cloud_manager.rb | 33 +---- .../inventory/persister/network_manager.rb | 24 +--- .../persister/shared/cloud_collections.rb | 45 ++++++- .../persister/shared/network_collections.rb | 57 ++++++++- .../persister/shared/storage_collections.rb | 26 ++-- .../persister/storage_manager/ebs.rb | 4 +- .../inventory/persister/target_collection.rb | 120 +----------------- 8 files changed, 121 insertions(+), 192 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister.rb b/app/models/manageiq/providers/amazon/inventory/persister.rb index 39671da86..58fd47e81 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister.rb @@ -30,7 +30,7 @@ def initialize_tag_mapper collections[:tags_to_resolve] = @tag_mapper.tags_to_resolve_collection end - def targeted + def targeted? false end @@ -41,7 +41,7 @@ def strategy def shared_options { :strategy => strategy, - :targeted => targeted, + :targeted => targeted?, } end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb index 28e9d6d4f..b8ee9cfff 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb @@ -4,37 +4,6 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ def initialize_inventory_collections initialize_tag_mapper - %i(vms - hardwares - operating_systems - networks - disks - flavors - availability_zones).each do |name| - - add_collection(cloud, name) - end - - add_miq_templates - - add_key_pairs - - add_orchestration_stacks - - add_vm_and_template_labels - - add_vm_and_template_taggings - - %i(orchestration_stacks_resources - orchestration_stacks_outputs - orchestration_stacks_parameters - orchestration_templates).each do |name| - - add_collection(cloud, name) - end - - add_vm_and_miq_template_ancestry - - add_orchestration_stack_ancestry + initialize_cloud_inventory_collections end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb index c2e81622e..828be517d 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb @@ -8,30 +8,10 @@ def initialize_inventory_collections initialize_cloud_inventory_collections end - private - def initialize_network_inventory_collections - %i(network_ports - floating_ips - cloud_subnets - cloud_networks - security_groups - load_balancers - load_balancer_pools - load_balancer_pool_members - load_balancer_pool_member_pools - load_balancer_listeners - load_balancer_listener_pools - load_balancer_health_checks - load_balancer_health_check_members - network_routers).each do |name| - - add_collection(network, name) - end - - add_cloud_subnet_network_ports + super - add_firewall_rules + add_collection(network, :network_routers) end def initialize_cloud_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb index 4330ddbc4..93c9b021b 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb @@ -6,6 +6,45 @@ def cloud ::ManagerRefresh::InventoryCollection::Builder::CloudManager end + def initialize_cloud_inventory_collections + %i(vms + hardwares + operating_systems + networks + disks + availability_zones).each do |name| + + add_collection(cloud, name) + end + + add_miq_templates + + add_flavors + + add_key_pairs + + add_vm_and_template_labels + + add_vm_and_template_taggings + + add_orchestration_stacks + + %i(orchestration_stacks_resources + orchestration_stacks_outputs + orchestration_stacks_parameters + orchestration_templates).each do |name| + + add_collection(cloud, name) + end + + # Custom processing of Ancestry + add_vm_and_miq_template_ancestry + + add_orchestration_stack_ancestry + end + + # ------ IC provider specific definitions ------------------------- + def add_miq_templates(extra_properties = {}) add_collection(cloud, :miq_templates, extra_properties) do |builder| builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template) @@ -14,7 +53,10 @@ def add_miq_templates(extra_properties = {}) end def add_flavors(extra_properties = {}) - add_collection(cloud, :flavors, extra_properties) + add_collection(cloud, :flavors, extra_properties) do |builder| + # Model we take just from a DB, there is no flavors API + builder.add_properties(:strategy => :local_db_find_references) if targeted? + end end def add_vm_and_template_labels @@ -53,6 +95,7 @@ def add_vm_and_template_taggings def add_key_pairs(extra_properties = {}) add_collection(cloud, :key_pairs, extra_properties) do |builder| builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::AuthKeyPair) + builder.add_properties(:manager_uuids => name_references(:key_pairs)) if targeted? end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb index 1b60932a1..c618feb23 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb @@ -6,19 +6,64 @@ def network ::ManagerRefresh::InventoryCollection::Builder::NetworkManager end + def initialize_network_inventory_collections + %i(cloud_networks + cloud_subnets + security_groups + load_balancers + load_balancer_pools + load_balancer_pool_members + load_balancer_pool_member_pools + load_balancer_listeners + load_balancer_listener_pools + load_balancer_health_checks + load_balancer_health_check_members).each do |name| + + add_collection(network, name) do |builder| + builder.add_properties(:parent => manager.network_manager) if targeted? + end + end + + add_cloud_subnet_network_ports + + add_firewall_rules + + add_floating_ips + + add_network_ports + end + + # ------ IC provider specific definitions ------------------------- + + def add_network_ports(extra_properties = {}) + add_collection(network, :network_ports, extra_properties) do |builder| + if targeted? + builder.add_properties(:manager_uuids => references(:vms) + references(:network_ports) + references(:load_balancers)) + builder.add_properties(:parent => manager.network_manager) + end + end + end + + def add_floating_ips(extra_properties = {}) + add_collection(network, :floating_ips, extra_properties) do |builder| + if targeted? + builder.add_properties(:manager_uuids => references(:floating_ips) + references(:load_balancers)) + builder.add_properties(:parent => manager.network_manager) + end + end + end + def add_cloud_subnet_network_ports(extra_properties = {}) add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| - builder.add_properties( - :manager_ref_allowed_nil => %i(cloud_subnet) - ) + builder.add_properties(:manager_ref_allowed_nil => %i(cloud_subnet)) + builder.add_properties(:parent => manager.network_manager) if targeted? end end def add_firewall_rules(extra_properties = {}) add_collection(network, :firewall_rules, extra_properties) do |builder| - builder.add_properties( - :manager_ref_allowed_nil => %i(source_security_group) - ) + builder.add_properties(:manager_ref_allowed_nil => %i(source_security_group)) + builder.add_properties(:parent => manager.network_manager) if targeted? end end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb index dd2d0535e..6c3861754 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb @@ -6,11 +6,16 @@ def storage ::ManagerRefresh::InventoryCollection::Builder::StorageManager end + def initialize_storage_inventory_collections + # should be defined by concrete persisters + end + + # ------ IC provider specific definitions ------------------------- + def add_cloud_volumes(extra_properties = {}) add_collection(storage, :cloud_volumes, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume - ) + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume) + builder.add_properties(:parent => manager.ebs_storage_manager) if targeted? builder.add_builder_params( :ems_id => block_storage_manager_id @@ -20,9 +25,8 @@ def add_cloud_volumes(extra_properties = {}) def add_cloud_volume_snapshots(extra_properties = {}) add_collection(storage, :cloud_volume_snapshots, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot - ) + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot) + builder.add_properties(:parent => manager.ebs_storage_manager) if targeted? builder.add_builder_params( :ems_id => block_storage_manager_id @@ -32,9 +36,8 @@ def add_cloud_volume_snapshots(extra_properties = {}) def add_cloud_object_store_containers(extra_properties = {}) add_collection(storage, :cloud_object_store_containers, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer - ) + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer) + builder.add_properties(:parent => manager.s3_storage_manager) if targeted? builder.add_builder_params( :ems_id => object_storage_manager_id @@ -44,9 +47,8 @@ def add_cloud_object_store_containers(extra_properties = {}) def add_cloud_object_store_objects(extra_properties = {}) add_collection(storage, :cloud_object_store_objects, extra_properties) do |builder| - builder.add_properties( - :model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject - ) + builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject) + builder.add_properties(:parent => manager.s3_storage_manager) if targeted? builder.add_builder_params( :ems_id => object_storage_manager_id diff --git a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb index a9b27b426..d9df027f3 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb @@ -8,13 +8,13 @@ def initialize_inventory_collections initialize_cloud_inventory_collections end - def initialize_cloud_inventory_collections + def initialize_storage_inventory_collections add_cloud_volumes add_cloud_volume_snapshots end - def initialize_storage_inventory_collections + def initialize_cloud_inventory_collections %i(availability_zones hardwares vms diff --git a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb index 40838a93e..319f6cb1f 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb @@ -3,7 +3,7 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::TargetCollection < Mana include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections - def targeted + def targeted? true end @@ -23,126 +23,16 @@ def initialize_inventory_collections private - def initialize_cloud_inventory_collections - init_cloud_ics_top_level_models - - init_cloud_ics_child_models - - # Custom processing of Ancestry - add_vm_and_miq_template_ancestry - - add_orchestration_stack_ancestry - end - - # Top level models with direct references for Cloud - def init_cloud_ics_top_level_models - %i(vms availability_zones).each do |name| - add_collection(cloud, name, :manager_uuids => references(name)) - end - - add_miq_templates(:manager_uuids => references(:miq_templates)) - - add_orchestration_stacks(:manager_uuids => references(:orchestration_stacks)) - - add_key_pairs(:manager_uuids => name_references(:key_pairs)) - end - - # Child models with references in the Parent InventoryCollections for Cloud - def init_cloud_ics_child_models - %i(hardwares - operating_systems - networks - disks - orchestration_stacks_resources - orchestration_stacks_outputs - orchestration_stacks_parameters - orchestration_templates).each do |name| - - add_collection(cloud, name) - end - - add_vm_and_template_labels - - add_vm_and_template_taggings - - # Model we take just from a DB, there is no flavors API - add_flavors(:strategy => :local_db_find_references) - end - - def initialize_network_inventory_collections - initialize_network_ics_top_level_models - - initialize_network_ics_child_models - end - - # Top level models with direct references for Network - def initialize_network_ics_top_level_models - %i(cloud_networks - cloud_subnets - security_groups - load_balancers).each do |name| - - add_collection(network, name, :manager_uuids => references(name)) do |builder| - builder.add_properties(:parent => manager.network_manager) - end - end - - add_collection(network, :network_ports, :manager_uuids => references(:vms) + references(:network_ports) + references(:load_balancers)) do |builder| - builder.add_properties(:parent => manager.network_manager) - end - - add_collection(network, :floating_ips, :manager_uuids => references(:floating_ips) + references(:load_balancers)) do |builder| - builder.add_properties(:parent => manager.network_manager) - end - end - - # Child models with references in the Parent InventoryCollections for Network - def initialize_network_ics_child_models - add_firewall_rules(:parent => manager.network_manager) - - add_cloud_subnet_network_ports(:parent => manager.network_manager) - - %i(load_balancer_pools - load_balancer_pool_members - load_balancer_pool_member_pools - load_balancer_listeners - load_balancer_listener_pools - load_balancer_health_checks - load_balancer_health_check_members).each do |name| - - add_collection(network, name) do |builder| - builder.add_properties(:parent => manager.network_manager) - end - end - end - # Top level models with direct references for Network def initialize_storage_inventory_collections - add_cloud_volumes(:manager_uuids => references(:cloud_volumes)) do |builder| - builder.add_properties(:parent => manager.ebs_storage_manager) - end + add_cloud_volumes - add_cloud_volume_snapshots(:manager_uuids => references(:cloud_volume_snapshots)) do |builder| - builder.add_properties(:parent => manager.ebs_storage_manager) - end + add_cloud_volume_snapshots if manager.s3_storage_manager + add_cloud_object_store_containers - add_cloud_object_store_containers(:manager_uuids => references(:cloud_object_store_containers)) do |builder| - builder.add_properties(:parent => manager.s3_storage_manager) - end - - add_cloud_object_store_objects(:manager_uuids => references(:cloud_object_store_objects)) do |builder| - builder.add_properties(:parent => manager.s3_storage_manager) - end + add_cloud_object_store_objects end end - - def references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :ems_ref).try(:to_a) || [] - end - - def name_references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :name).try(:to_a) || [] - end end From 97bc3addb13a183bf9e644349431089850d2cc16 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 3 May 2018 19:43:20 +0200 Subject: [PATCH 5/9] Automatic Network ICs parent for TargetedCollection persister Parent property moved to core --- .../manageiq/providers/amazon/inventory/persister.rb | 4 ---- .../inventory/persister/shared/cloud_collections.rb | 2 ++ .../inventory/persister/shared/network_collections.rb | 8 +------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister.rb b/app/models/manageiq/providers/amazon/inventory/persister.rb index 58fd47e81..76896538b 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister.rb @@ -30,10 +30,6 @@ def initialize_tag_mapper collections[:tags_to_resolve] = @tag_mapper.tags_to_resolve_collection end - def targeted? - false - end - def strategy nil end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb index 93c9b021b..89bebe0e8 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb @@ -45,6 +45,7 @@ def initialize_cloud_inventory_collections # ------ IC provider specific definitions ------------------------- + # TODO: Derive model class in core def add_miq_templates(extra_properties = {}) add_collection(cloud, :miq_templates, extra_properties) do |builder| builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::Template) @@ -99,6 +100,7 @@ def add_key_pairs(extra_properties = {}) end end + # TODO: mslemr - parent model_class used anywhere? If not, should be deleted def add_orchestration_stacks(extra_properties = {}) add_collection(cloud, :orchestration_stacks, extra_properties) do |builder| builder.add_properties(:model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb index c618feb23..8d7db1d29 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb @@ -19,9 +19,7 @@ def initialize_network_inventory_collections load_balancer_health_checks load_balancer_health_check_members).each do |name| - add_collection(network, name) do |builder| - builder.add_properties(:parent => manager.network_manager) if targeted? - end + add_collection(network, name) end add_cloud_subnet_network_ports @@ -39,7 +37,6 @@ def add_network_ports(extra_properties = {}) add_collection(network, :network_ports, extra_properties) do |builder| if targeted? builder.add_properties(:manager_uuids => references(:vms) + references(:network_ports) + references(:load_balancers)) - builder.add_properties(:parent => manager.network_manager) end end end @@ -48,7 +45,6 @@ def add_floating_ips(extra_properties = {}) add_collection(network, :floating_ips, extra_properties) do |builder| if targeted? builder.add_properties(:manager_uuids => references(:floating_ips) + references(:load_balancers)) - builder.add_properties(:parent => manager.network_manager) end end end @@ -56,14 +52,12 @@ def add_floating_ips(extra_properties = {}) def add_cloud_subnet_network_ports(extra_properties = {}) add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| builder.add_properties(:manager_ref_allowed_nil => %i(cloud_subnet)) - builder.add_properties(:parent => manager.network_manager) if targeted? end end def add_firewall_rules(extra_properties = {}) add_collection(network, :firewall_rules, extra_properties) do |builder| builder.add_properties(:manager_ref_allowed_nil => %i(source_security_group)) - builder.add_properties(:parent => manager.network_manager) if targeted? end end end From 030e5c9148f1b0293c778f61c2d1607ac33c2d3c Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 10 May 2018 16:06:18 +0200 Subject: [PATCH 6/9] Changed :auto_object_attributes => :auto_inventory_attributes --- .../amazon/inventory/persister/shared/cloud_collections.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb index 89bebe0e8..c2ce467aa 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb @@ -108,7 +108,7 @@ def add_orchestration_stacks(extra_properties = {}) end def add_vm_and_miq_template_ancestry - add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_object_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| + 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]] @@ -117,7 +117,7 @@ def add_vm_and_miq_template_ancestry end def add_orchestration_stack_ancestry - add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_object_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder| + 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]], :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] From 964d5ef5170a64480d598a945446bd3d087ba9f9 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 24 May 2018 17:23:45 +0200 Subject: [PATCH 7/9] IC builder class definitions moved to core Methods with class names unified across providers --- .../amazon/inventory/persister/shared/cloud_collections.rb | 5 ----- .../amazon/inventory/persister/shared/network_collections.rb | 5 ----- .../amazon/inventory/persister/shared/storage_collections.rb | 5 ----- 3 files changed, 15 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb index c2ce467aa..5ddfea813 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb @@ -1,11 +1,6 @@ module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections extend ActiveSupport::Concern - # Builder class for Cloud - def cloud - ::ManagerRefresh::InventoryCollection::Builder::CloudManager - end - def initialize_cloud_inventory_collections %i(vms hardwares diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb index 8d7db1d29..a8bd9eeb7 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb @@ -1,11 +1,6 @@ module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections extend ActiveSupport::Concern - # Builder class for Network - def network - ::ManagerRefresh::InventoryCollection::Builder::NetworkManager - end - def initialize_network_inventory_collections %i(cloud_networks cloud_subnets diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb index 6c3861754..73d9ede50 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb @@ -1,11 +1,6 @@ module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections extend ActiveSupport::Concern - # Builder class for Storage - def storage - ::ManagerRefresh::InventoryCollection::Builder::StorageManager - end - def initialize_storage_inventory_collections # should be defined by concrete persisters end From cfa6467f6717a9af2a6a1979f9174bd531b1ce01 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 6 Jun 2018 11:33:52 +0200 Subject: [PATCH 8/9] Renamed IC definitions folder --- .../providers/amazon/inventory/persister/cloud_manager.rb | 2 +- .../persister/{shared => definitions}/cloud_collections.rb | 2 +- .../{shared => definitions}/network_collections.rb | 2 +- .../{shared => definitions}/storage_collections.rb | 2 +- .../providers/amazon/inventory/persister/network_manager.rb | 4 ++-- .../amazon/inventory/persister/storage_manager/ebs.rb | 4 ++-- .../amazon/inventory/persister/storage_manager/s3.rb | 2 +- .../amazon/inventory/persister/target_collection.rb | 6 +++--- 8 files changed, 12 insertions(+), 12 deletions(-) rename app/models/manageiq/providers/amazon/inventory/persister/{shared => definitions}/cloud_collections.rb (97%) rename app/models/manageiq/providers/amazon/inventory/persister/{shared => definitions}/network_collections.rb (94%) rename app/models/manageiq/providers/amazon/inventory/persister/{shared => definitions}/storage_collections.rb (96%) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb index b8ee9cfff..56b195d20 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb @@ -1,5 +1,5 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ::Providers::Amazon::Inventory::Persister - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections def initialize_inventory_collections initialize_tag_mapper diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb similarity index 97% rename from app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb rename to app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb index 5ddfea813..c60d0d679 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb @@ -1,4 +1,4 @@ -module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections +module ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections extend ActiveSupport::Concern def initialize_cloud_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb similarity index 94% rename from app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb rename to app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb index a8bd9eeb7..d78c16849 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/network_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb @@ -1,4 +1,4 @@ -module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections +module ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::NetworkCollections extend ActiveSupport::Concern def initialize_network_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/definitions/storage_collections.rb similarity index 96% rename from app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb rename to app/models/manageiq/providers/amazon/inventory/persister/definitions/storage_collections.rb index 73d9ede50..712e4c173 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/shared/storage_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/definitions/storage_collections.rb @@ -1,4 +1,4 @@ -module ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections +module ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::StorageCollections extend ActiveSupport::Concern def initialize_storage_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb index 828be517d..a730ae4e8 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/network_manager.rb @@ -1,6 +1,6 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::NetworkManager < ManageIQ::Providers::Amazon::Inventory::Persister - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::NetworkCollections def initialize_inventory_collections initialize_network_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb index d9df027f3..df3451893 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/ebs.rb @@ -1,6 +1,6 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::StorageManager::Ebs < ManageIQ::Providers::Amazon::Inventory::Persister - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::StorageCollections def initialize_inventory_collections initialize_storage_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb index f0601dde0..ec489d8c0 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/storage_manager/s3.rb @@ -1,5 +1,5 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::StorageManager::S3 < ManageIQ::Providers::Amazon::Inventory::Persister - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::StorageCollections def initialize_inventory_collections initialize_storage_inventory_collections diff --git a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb index 319f6cb1f..1eac31c51 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb @@ -1,7 +1,7 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::TargetCollection < ManageIQ::Providers::Amazon::Inventory::Persister - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::CloudCollections - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::NetworkCollections - include ManageIQ::Providers::Amazon::Inventory::Persister::Shared::StorageCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::CloudCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::NetworkCollections + include ManageIQ::Providers::Amazon::Inventory::Persister::Definitions::StorageCollections def targeted? true From b50d3947c9105e1244051ba0875121d40d9bb146 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 6 Jun 2018 12:55:27 +0200 Subject: [PATCH 9/9] Added parent to IC definitions --- .../manageiq/providers/amazon/inventory/persister.rb | 5 +++++ .../inventory/persister/definitions/cloud_collections.rb | 4 ++-- .../persister/definitions/network_collections.rb | 8 +++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/persister.rb b/app/models/manageiq/providers/amazon/inventory/persister.rb index 76896538b..8449eba03 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister.rb @@ -34,10 +34,15 @@ def strategy nil end + def parent + manager.presence + end + def shared_options { :strategy => strategy, :targeted => targeted?, + :parent => parent } end end diff --git a/app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb index c60d0d679..927e00865 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/definitions/cloud_collections.rb @@ -103,7 +103,7 @@ def add_orchestration_stacks(extra_properties = {}) end 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| + add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_inventory_attributes => false, :without_model_class => true}) do |builder| builder.add_dependency_attributes( :vms => [collections[:vms]], :miq_templates => [collections[:miq_templates]] @@ -112,7 +112,7 @@ def add_vm_and_miq_template_ancestry end 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| + add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_inventory_attributes => false, :without_model_class => true}) do |builder| builder.add_dependency_attributes( :orchestration_stacks => [collections[:orchestration_stacks]], :orchestration_stacks_resources => [collections[:orchestration_stacks_resources]] diff --git a/app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb b/app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb index d78c16849..6eac3efe1 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/definitions/network_collections.rb @@ -14,7 +14,9 @@ def initialize_network_inventory_collections load_balancer_health_checks load_balancer_health_check_members).each do |name| - add_collection(network, name) + add_collection(network, name) do |builder| + builder.add_properties(:parent => manager.network_manager) if targeted? + end end add_cloud_subnet_network_ports @@ -32,6 +34,7 @@ def add_network_ports(extra_properties = {}) add_collection(network, :network_ports, extra_properties) do |builder| if targeted? builder.add_properties(:manager_uuids => references(:vms) + references(:network_ports) + references(:load_balancers)) + builder.add_properties(:parent => manager.network_manager) end end end @@ -40,6 +43,7 @@ def add_floating_ips(extra_properties = {}) add_collection(network, :floating_ips, extra_properties) do |builder| if targeted? builder.add_properties(:manager_uuids => references(:floating_ips) + references(:load_balancers)) + builder.add_properties(:parent => manager.network_manager) end end end @@ -47,12 +51,14 @@ def add_floating_ips(extra_properties = {}) def add_cloud_subnet_network_ports(extra_properties = {}) add_collection(network, :cloud_subnet_network_ports, extra_properties) do |builder| builder.add_properties(:manager_ref_allowed_nil => %i(cloud_subnet)) + builder.add_properties(:parent => manager.network_manager) if targeted? end end def add_firewall_rules(extra_properties = {}) add_collection(network, :firewall_rules, extra_properties) do |builder| builder.add_properties(:manager_ref_allowed_nil => %i(source_security_group)) + builder.add_properties(:parent => manager.network_manager) if targeted? end end end