From 4b61465fa6e823a9159c2f05dfa0306737b5dc1c Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Thu, 27 Jul 2023 13:22:03 -0400 Subject: [PATCH] extend relationships to define the appropriate class names WIP: quite a bit of stuff has happened since then. there is a HasNetworkManagerMixin that may meet many of the needs WIP: do a diff with origin to make sure the rebase didn't change too much seems quite a few concepts have been changed in master so definitely need to re-evaluate this use parent definition of ensure since they are now pretty generic. They may be no longer necessary and a build_ may suffice. Use parent definition of propagation so all attributes go across Extend parent managers to group the functionality together WIP: quite a bit of stuff has happened since then. there is a HasNetworkManagerMixin that may meet many of the needs --- .../providers/openstack/cloud_manager.rb | 61 ++++++------------- .../providers/openstack/infra_manager.rb | 14 +++-- 2 files changed, 26 insertions(+), 49 deletions(-) diff --git a/app/models/manageiq/providers/openstack/cloud_manager.rb b/app/models/manageiq/providers/openstack/cloud_manager.rb index ad755532e..a0c5cea12 100644 --- a/app/models/manageiq/providers/openstack/cloud_manager.rb +++ b/app/models/manageiq/providers/openstack/cloud_manager.rb @@ -27,13 +27,17 @@ class ManageIQ::Providers::Openstack::CloudManager < ManageIQ::Providers::CloudM :foreign_key => :parent_ems_id, :class_name => "ManageIQ::Providers::Openstack::NetworkManager", :autosave => true, - :dependent => :destroy + :dependent => :destroy, + :inverse_of => :parent_manager has_many :storage_managers, :foreign_key => :parent_ems_id, - :class_name => "ManageIQ::Providers::StorageManager", + :class_name => "ManageIQ::Providers::Openstack::StorageManager", :autosave => true, - :dependent => :destroy + :dependent => :destroy, + :auto_save => true, + :inverse_of => :parent_manager has_many :snapshots, :through => :vms_and_templates + include ManageIQ::Providers::Openstack::CinderManagerMixin include ManageIQ::Providers::Openstack::SwiftManagerMixin include ManageIQ::Providers::Openstack::ManagerMixin @@ -67,9 +71,12 @@ class ManageIQ::Providers::Openstack::CloudManager < ManageIQ::Providers::CloudM unsupported_reason_add(:swift_service, "Swift service unavailable") unless openstack_handle.detect_volume_service.name == :swift end + # TODO: move to after_initialization before_create :ensure_managers + # TODO: move to before_validation before_update :ensure_managers_zone_and_provider_region + # TODO: after fixing inverse_of, this may go away after_save :refresh_parent_infra_manager private_class_method def self.provider_id_options @@ -445,51 +452,19 @@ def ensure_managers ensure_network_manager ensure_cinder_manager ensure_swift_manager + # TODO: remove when this moves to before_initialization ensure_managers_zone_and_provider_region end - def ensure_managers_zone_and_provider_region - if network_manager - network_manager.enabled = enabled - network_manager.zone_id = zone_id - network_manager.tenant_id = tenant_id - network_manager.provider_region = provider_region - end - - if cinder_manager - cinder_manager.enabled = enabled - cinder_manager.zone_id = zone_id - cinder_manager.tenant_id = tenant_id - cinder_manager.provider_region = provider_region - end - - if swift_manager - swift_manager.enabled = enabled - swift_manager.zone_id = zone_id - swift_manager.tenant_id = tenant_id - swift_manager.provider_region = provider_region - end + # sigh, methods like this always start out innocent enough + def child_manager_references + [network_manager, cinder_manager, swift_manager].compact end - def ensure_network_manager - build_network_manager unless network_manager - end - - def ensure_cinder_manager - build_cinder_manager unless cinder_manager - end - - def ensure_swift_manager - build_swift_manager unless swift_manager - end - - after_save :save_on_other_managers - - def save_on_other_managers - storage_managers.update_all(:tenant_mapping_enabled => tenant_mapping_enabled) - if network_manager - network_manager.tenant_mapping_enabled = tenant_mapping_enabled - network_manager.save! + def ensure_managers_zone_and_provider_region + child_manager_references.each do |child_manager| + propagate_child_manager_attributes(child_manager) + child_manager.tenant_mapping_enabled = tenant_mapping_enabled end end diff --git a/app/models/manageiq/providers/openstack/infra_manager.rb b/app/models/manageiq/providers/openstack/infra_manager.rb index 20a3075d8..b6a59a104 100644 --- a/app/models/manageiq/providers/openstack/infra_manager.rb +++ b/app/models/manageiq/providers/openstack/infra_manager.rb @@ -14,11 +14,17 @@ class ManageIQ::Providers::Openstack::InfraManager < ManageIQ::Providers::InfraM include ManageIQ::Providers::Openstack::ManagerMixin include HasManyOrchestrationStackMixin - include HasNetworkManagerMixin + include HasNetworkManagerMixin # TODO: also included in parent class + + has_one :network_manager, + :foreign_key => :parent_ems_id, + :class_name => "ManageIQ::Providers::Openstack::NetworkManager", + :autosave => true, + :dependent => :destroy before_save :ensure_parent_provider before_destroy :destroy_parent_provider - before_create :ensure_managers + before_create :ensure_managers # defined by HasNetworkManagerMixin before_update :ensure_managers_zone_and_provider_region supports :create @@ -286,10 +292,6 @@ def self.params_for_create } end - def ensure_network_manager - build_network_manager(:type => 'ManageIQ::Providers::Openstack::NetworkManager') unless network_manager - end - def allow_targeted_refresh? false end