diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 1997adf9258..a4cc264c75d 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -106,8 +106,6 @@ def self.create_from_params(params, endpoints, authentications) has_many :customization_scripts, :foreign_key => "manager_id", :dependent => :destroy, :inverse_of => :ext_management_system has_many :cloud_subnets, :foreign_key => :ems_id, :dependent => :destroy - has_one :iso_datastore, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system - belongs_to :zone belongs_to :zone_before_pause, :class_name => "Zone", :inverse_of => :paused_ext_management_systems # used for maintenance mode @@ -129,6 +127,8 @@ def self.create_from_params(params, endpoints, authentications) has_many :ems_licenses, :foreign_key => :ems_id, :dependent => :destroy, :inverse_of => :ext_management_system has_many :ems_extensions, :foreign_key => :ems_id, :dependent => :destroy, :inverse_of => :ext_management_system + has_many :iso_images, :through => :storages + validates :name, :presence => true, :uniqueness_when_changed => {:scope => [:tenant_id]} validates :hostname, :presence => true, :if => :hostname_required? validates :zone, :presence => true @@ -994,11 +994,6 @@ def self.class_by_ems(class_name) end delegate :class_by_ems, :to => :class - # @return [Boolean] true if a datastore exists for this type of ems - def self.datastore? - IsoDatastore.where(:ems_id => all).exists? - end - def tenant_identity User.super_admin.tap { |u| u.current_group = tenant.default_miq_group } end diff --git a/app/models/iso_datastore.rb b/app/models/iso_datastore.rb deleted file mode 100644 index 94c14fe0912..00000000000 --- a/app/models/iso_datastore.rb +++ /dev/null @@ -1,53 +0,0 @@ -class IsoDatastore < ApplicationRecord - belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :iso_datastore - has_many :iso_images, :dependent => :destroy - - virtual_delegate :name, :to => :ext_management_system, :allow_nil => true, :type => :string - - # Synchronize advertised images as a queued task. The - # queue name and the queue zone are derived from the EMS. - # - def synchronize_advertised_images_queue - MiqQueue.put_unless_exists( - :class_name => self.class.name, - :instance_id => id, - :method_name => "synchronize_advertised_images", - :queue_name => ext_management_system.queue_name_for_ems_operations, - :zone => ext_management_system.try(:my_zone), - :role => "ems_operations" - ) - end - - def advertised_images - return [] unless ext_management_system.kind_of?(ManageIQ::Providers::Ovirt::InfraManager) - - ext_management_system.ovirt_services.advertised_images - end - - def synchronize_advertised_images - log_for = "ISO Datastore on Management System <#{name}>" - - _log.info("Synchronizing images on #{log_for}...") - db_image_hash = iso_images.index_by(&:name) - - advertised_images.each do |image_name| - if db_image_hash.include?(image_name) - db_image_hash.delete(image_name) - else - iso_images.create(:name => image_name) - end - end - - db_image_hash.each_value(&:destroy) - - clear_association_cache - update_attribute(:last_refresh_on, Time.now.utc) - - _log.info("Synchronizing images on #{log_for}...Complete") - rescue ManageIQ::Providers::Ovirt::InfraManager::OvirtServices::Error - end - - def self.display_name(number = 1) - n_('ISO Datastore', 'ISO Datastores', number) - end -end diff --git a/app/models/iso_image.rb b/app/models/iso_image.rb index c9cef9e1587..90c76e876f4 100644 --- a/app/models/iso_image.rb +++ b/app/models/iso_image.rb @@ -1,5 +1,5 @@ class IsoImage < ApplicationRecord - belongs_to :iso_datastore + belongs_to :storage belongs_to :pxe_image_type has_many :customization_templates, :through => :pxe_image_type diff --git a/app/models/manageiq/providers/inventory/persister/builder/infra_manager.rb b/app/models/manageiq/providers/inventory/persister/builder/infra_manager.rb index 16b14a9c5ed..ae2313292a0 100644 --- a/app/models/manageiq/providers/inventory/persister/builder/infra_manager.rb +++ b/app/models/manageiq/providers/inventory/persister/builder/infra_manager.rb @@ -296,6 +296,14 @@ def vm_resource_pools ) end + def iso_images + add_properties( + :parent_inventory_collections => %i[storages], + :manager_ref => %i[name], + :model_class => IsoImage + ) + end + private def root_folder_relationship_save_block diff --git a/app/models/miq_request_workflow.rb b/app/models/miq_request_workflow.rb index f2df7271e79..aed0081d47e 100644 --- a/app/models/miq_request_workflow.rb +++ b/app/models/miq_request_workflow.rb @@ -1405,7 +1405,7 @@ def allowed_images(options = {}) def get_iso_images template = VmOrTemplate.find_by(:id => get_value(@values[:src_vm_id])) - template.try(:ext_management_system).try(:iso_datastore).try(:iso_images) || [] + template.try(:ext_management_system).try(:iso_images) || [] end def allowed_iso_images(_options = {}) diff --git a/app/models/storage.rb b/app/models/storage.rb index 6b93907baa8..1ac573a5d1e 100644 --- a/app/models/storage.rb +++ b/app/models/storage.rb @@ -22,6 +22,7 @@ class Storage < ApplicationRecord has_many :storage_files, :dependent => :destroy has_many :storage_files_files, -> { where("rsc_type = 'file'") }, :class_name => "StorageFile", :foreign_key => "storage_id" has_many :files, -> { where("rsc_type = 'file'") }, :class_name => "StorageFile", :foreign_key => "storage_id" + has_many :iso_images, :dependent => :destroy has_many :miq_events, :as => :target, :dependent => :destroy @@ -80,6 +81,7 @@ class Storage < ApplicationRecord supports(:delete) { _("Only storage without VMs and Hosts can be removed") if vms_and_templates.any? || hosts.any? } supports_not :evacuate + supports_not :iso_datastore def to_s name diff --git a/locale/en.yml b/locale/en.yml index 3f9b0fbdbcd..0c343481803 100644 --- a/locale/en.yml +++ b/locale/en.yml @@ -1456,7 +1456,6 @@ en: Host: Host HostInitiator: Host Initiators HostPerformance: Performance - Host - IsoDatastore: ISO Datastore IsoImage: ISO Image LdapDomain: LDAP Domain LdapRegion: LDAP Region @@ -1778,7 +1777,6 @@ en: hosts: Hosts host_initiator: Host Initiator host_services: Services - iso_datastore: ISO Datastore iso_image: ISO Image lans: vLANs last_compliance: Last Compliance History diff --git a/spec/models/iso_datastore_spec.rb b/spec/models/iso_datastore_spec.rb deleted file mode 100644 index 21f9079a919..00000000000 --- a/spec/models/iso_datastore_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -RSpec.describe IsoDatastore do - include Spec::Support::ArelHelper - - let(:ems) { FactoryBot.create(:ems_redhat) } - let(:iso_datastore) { FactoryBot.create(:iso_datastore, :ext_management_system => ems) } - - context "queued methods" do - it 'queues a sync task with synchronize_advertised_images_queue' do - queue = iso_datastore.synchronize_advertised_images_queue - - expect(queue).to have_attributes( - :class_name => described_class.name, - :method_name => 'synchronize_advertised_images', - :role => 'ems_operations', - :queue_name => 'generic', - :zone => ems.my_zone, - :args => [] - ) - end - end - - describe "#advertised_images" do - subject(:advertised_images) { iso_datastore.advertised_images } - - context "ems is not rhv" do - let(:ems) { FactoryBot.create(:ems_vmware) } - it "returns empty array" do - expect(advertised_images).to eq([]) - end - end - - context "ems is rhv" do - context "supports api4" do - it "send the method to ovirt services v4" do - expect_any_instance_of(ManageIQ::Providers::Redhat::InfraManager::OvirtServices::V4) - .to receive(:advertised_images) - advertised_images - end - end - end - - describe "#name" do - it "has a name" do - expect(iso_datastore.name).to eq(ems.name) - end - - it "fetches name via sql" do - iso_datastore - expect(virtual_column_sql_value(IsoDatastore, "name")).to eq(ems.name) - end - end - end -end