diff --git a/app/models/container.rb b/app/models/container.rb index dd9ce7c3ba6..fdc4e426aae 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -47,8 +47,6 @@ def disconnect_inv return if ems_id.nil? _log.info "Disconnecting Container [#{name}] id [#{id}] from EMS " self.deleted_on = Time.now.utc - self.old_ems_id = self.ems_id - self.ems_id = nil save end end diff --git a/app/models/container_definition.rb b/app/models/container_definition.rb index 222d111d291..9dbde42469a 100644 --- a/app/models/container_definition.rb +++ b/app/models/container_definition.rb @@ -15,8 +15,6 @@ def disconnect_inv _log.info "Disconnecting Container definition [#{name}] id [#{id}]" self.container.try(:disconnect_inv) self.deleted_on = Time.now.utc - self.old_ems_id = self.ems_id - self.ems_id = nil save end end diff --git a/app/models/container_group.rb b/app/models/container_group.rb index 18610856f0f..45e91bdeb04 100644 --- a/app/models/container_group.rb +++ b/app/models/container_group.rb @@ -85,8 +85,6 @@ def disconnect_inv _log.info "Disconnecting Pod [#{name}] id [#{id}] from EMS [#{ext_management_system.name}]" \ "id [#{ext_management_system.id}] " self.container_definitions.each(&:disconnect_inv) - self.old_ems_id = ems_id - self.ext_management_system = nil self.container_node_id = nil self.container_services = [] self.container_replicator_id = nil diff --git a/app/models/container_image.rb b/app/models/container_image.rb index 4a8189a4cb2..280001cdb11 100644 --- a/app/models/container_image.rb +++ b/app/models/container_image.rb @@ -106,8 +106,6 @@ def disconnect_inv _log.info "Disconnecting Image [#{name}] id [#{id}] from EMS [#{ext_management_system.name}]" \ "id [#{ext_management_system.id}] " self.container_image_registry = nil - self.old_ems_id = ems_id - self.ext_management_system = nil self.deleted_on = Time.now.utc save end diff --git a/app/models/container_project.rb b/app/models/container_project.rb index 14c1f2d9ba3..e848edde6a9 100644 --- a/app/models/container_project.rb +++ b/app/models/container_project.rb @@ -64,8 +64,6 @@ def disconnect_inv return if ems_id.nil? _log.info "Disconnecting Container Project [#{name}] id [#{id}] from EMS [#{ext_management_system.name}]" \ "id [#{ext_management_system.id}] " - self.old_ems_id = ems_id - self.ext_management_system = nil self.deleted_on = Time.now.utc save end diff --git a/app/models/manageiq/providers/container_manager.rb b/app/models/manageiq/providers/container_manager.rb index dd63f7da6ce..03d89fc0696 100644 --- a/app/models/manageiq/providers/container_manager.rb +++ b/app/models/manageiq/providers/container_manager.rb @@ -4,15 +4,16 @@ class ContainerManager < BaseManager include SupportsFeatureMixin has_many :container_nodes, :foreign_key => :ems_id, :dependent => :destroy - has_many :container_groups, :foreign_key => :ems_id, :dependent => :destroy + has_many :container_groups, -> { active }, :foreign_key => :ems_id has_many :container_services, :foreign_key => :ems_id, :dependent => :destroy has_many :container_replicators, :foreign_key => :ems_id, :dependent => :destroy - has_many :containers, :foreign_key => :ems_id - has_many :container_projects, :foreign_key => :ems_id, :dependent => :destroy + has_many :containers, -> { active }, :foreign_key => :ems_id + has_many :container_definitions, -> { active }, :foreign_key => :ems_id + has_many :container_projects, -> { active }, :foreign_key => :ems_id has_many :container_quotas, :foreign_key => :ems_id, :dependent => :destroy has_many :container_limits, :foreign_key => :ems_id, :dependent => :destroy has_many :container_image_registries, :foreign_key => :ems_id, :dependent => :destroy - has_many :container_images, :foreign_key => :ems_id, :dependent => :destroy + has_many :container_images, -> { active }, :foreign_key => :ems_id has_many :persistent_volumes, :as => :parent, :dependent => :destroy has_many :persistent_volume_claims, :foreign_key => :ems_id, :dependent => :destroy has_many :container_component_statuses, :foreign_key => :ems_id, :dependent => :destroy @@ -26,7 +27,6 @@ class ContainerManager < BaseManager has_many :computer_system_hardwares, :through => :computer_systems, :source => :hardware has_many :computer_system_operating_systems, :through => :computer_systems, :source => :operating_system has_many :container_volumes, :through => :container_groups - has_many :container_definitions, :through => :container_groups has_many :container_port_configs, :through => :container_definitions has_many :container_env_vars, :through => :container_definitions has_many :security_contexts, :through => :container_definitions @@ -36,10 +36,13 @@ class ContainerManager < BaseManager has_many :container_limit_items, :through => :container_limits has_many :container_template_parameters, :through => :container_templates - # Archived entities to destroy when the container manager is deleted - has_many :old_container_groups, :foreign_key => :old_ems_id, :dependent => :destroy, :class_name => "ContainerGroup" - has_many :old_container_projects, :foreign_key => :old_ems_id, :dependent => :destroy, :class_name => "ContainerProject" - has_many :old_container_images, :foreign_key => :old_ems_id, :dependent => :destroy, :class_name => "ContainerImage" + # Archived and active entities to destroy when the container manager is deleted + has_many :all_containers, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "Container" + has_many :all_container_groups, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerGroup" + has_many :all_container_projects, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerProject" + has_many :all_container_images, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerImage" + has_many :all_container_definitions, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerDefinition" + virtual_column :port_show, :type => :string diff --git a/app/models/mixins/archived_mixin.rb b/app/models/mixins/archived_mixin.rb index f9633a7c371..55555896202 100644 --- a/app/models/mixins/archived_mixin.rb +++ b/app/models/mixins/archived_mixin.rb @@ -2,11 +2,18 @@ module ArchivedMixin extend ActiveSupport::Concern included do + scope :archived, -> { where.not(:deleted_on => nil) } + scope :active, -> { where(:deleted_on => nil) } + belongs_to :old_ext_management_system, :foreign_key => :old_ems_id, :class_name => 'ExtManagementSystem' end def archived? - ems_id.nil? + !active? + end + + def active? + deleted_on.nil? end # Needed for metrics