diff --git a/app/models/manageiq/providers/ovirt/infra_manager.rb b/app/models/manageiq/providers/ovirt/infra_manager.rb index 19b051b6..1a254679 100644 --- a/app/models/manageiq/providers/ovirt/infra_manager.rb +++ b/app/models/manageiq/providers/ovirt/infra_manager.rb @@ -17,6 +17,7 @@ class ManageIQ::Providers::Ovirt::InfraManager < ManageIQ::Providers::InfraManag require_nested :ProvisionWorkflow require_nested :Snapshot require_nested :Storage + require_nested :IsoDatastore require_nested :Template require_nested :Vm require_nested :DistributedVirtualSwitch @@ -27,6 +28,8 @@ class ManageIQ::Providers::Ovirt::InfraManager < ManageIQ::Providers::InfraManag has_many :vm_and_template_ems_custom_fields, :through => :vms_and_templates, :source => :ems_custom_attributes has_many :external_distributed_virtual_switches, :dependent => :destroy, :foreign_key => :ems_id, :inverse_of => :ext_management_system has_many :external_distributed_virtual_lans, -> { distinct }, :through => :external_distributed_virtual_switches, :source => :lans + has_many :iso_datastores, :dependent => :destroy, :foreign_key => :ems_id, :inverse_of => :ext_management_system + has_many :iso_images, :through => :storages include HasNetworkManagerMixin @@ -42,7 +45,7 @@ class ManageIQ::Providers::Ovirt::InfraManager < ManageIQ::Providers::InfraManag end supports :create_iso_datastore do - unsupported_reason_add(:create_iso_datastore, _("Already has an ISO datastore")) if iso_datastore + unsupported_reason_add(:create_iso_datastore, _("Already has an ISO datastore")) if iso_datastores end def ensure_managers diff --git a/app/models/manageiq/providers/ovirt/infra_manager/iso_datastore.rb b/app/models/manageiq/providers/ovirt/infra_manager/iso_datastore.rb new file mode 100644 index 00000000..eb2b4a84 --- /dev/null +++ b/app/models/manageiq/providers/ovirt/infra_manager/iso_datastore.rb @@ -0,0 +1,9 @@ +class ManageIQ::Providers::Ovirt::InfraManager::IsoDatastore < ManageIQ::Providers::Ovirt::InfraManager::Storage + belongs_to :ext_management_system, :foreign_key => :ems_id + + virtual_delegate :name, :to => :ext_management_system, :allow_nil => true, :type => :string + + def self.display_name(number = 1) + n_('ISO Datastore', 'ISO Datastores', number) + end +end diff --git a/app/models/manageiq/providers/ovirt/infra_manager/ovirt_services.rb b/app/models/manageiq/providers/ovirt/infra_manager/ovirt_services.rb index bfee395f..7befba68 100644 --- a/app/models/manageiq/providers/ovirt/infra_manager/ovirt_services.rb +++ b/app/models/manageiq/providers/ovirt/infra_manager/ovirt_services.rb @@ -352,7 +352,8 @@ def advertised_images sd_service = ems_service.system_service.storage_domains_service.storage_domain_service(iso_sd.id) iso_images = sd_service.files_service.list - iso_images.collect(&:name) + + iso_images end rescue OvirtSDK4::Error => err name = ext_management_system.try(:name) diff --git a/app/models/manageiq/providers/ovirt/inventory/collector/infra_manager.rb b/app/models/manageiq/providers/ovirt/inventory/collector/infra_manager.rb index 57475a7c..bdc56d5e 100644 --- a/app/models/manageiq/providers/ovirt/inventory/collector/infra_manager.rb +++ b/app/models/manageiq/providers/ovirt/inventory/collector/infra_manager.rb @@ -42,6 +42,10 @@ def templates collected_inventory[:template] end + def advertised_images + manager.ovirt_services.advertised_images + end + def collect_networks collected_inventory[:network] end diff --git a/app/models/manageiq/providers/ovirt/inventory/collector/target_collection.rb b/app/models/manageiq/providers/ovirt/inventory/collector/target_collection.rb index 5ae5aae3..3998a78f 100644 --- a/app/models/manageiq/providers/ovirt/inventory/collector/target_collection.rb +++ b/app/models/manageiq/providers/ovirt/inventory/collector/target_collection.rb @@ -150,6 +150,10 @@ def templates t end + def advertised_images + [] + end + def parse_targets! target.targets.each do |t| case t diff --git a/app/models/manageiq/providers/ovirt/inventory/parser/infra_manager.rb b/app/models/manageiq/providers/ovirt/inventory/parser/infra_manager.rb index 1d00e266..2daa88df 100644 --- a/app/models/manageiq/providers/ovirt/inventory/parser/infra_manager.rb +++ b/app/models/manageiq/providers/ovirt/inventory/parser/infra_manager.rb @@ -11,6 +11,7 @@ def parse vms networks vnic_profiles + advertised_images $rhevm_log.info("#{log_header}...Complete") end @@ -85,7 +86,7 @@ def storagedomains storage_type = storagedomain.dig(:storage, :type).upcase ems_ref = ManageIQ::Providers::Ovirt::InfraManager.make_ems_ref(storagedomain.try(:href)) location = case storage_type - when 'LOCALFS' + when 'LOCALFS', 'ISO' ems_ref when 'NFS', 'GLUSTERFS' "#{storagedomain.dig(:storage, :address)}:#{storagedomain.dig(:storage, :path)}" @@ -98,17 +99,32 @@ def storagedomains total = free + used committed = storagedomain.try(:committed).to_i + storage_domain_type = storagedomain.dig(:type, :downcase) + type = storage_domain_type == 'iso' ? "IsoDatastore" : "Storage" + persister.storages.find_or_build(ems_ref).assign_attributes( :ems_ref => ems_ref, :name => storagedomain.try(:name), :store_type => storage_type, - :storage_domain_type => storagedomain.dig(:type, :downcase), + :storage_domain_type => storage_domain_type, :total_space => total, :free_space => free, :uncommitted => total - committed, :multiplehostaccess => true, :location => location, - :master => storagedomain.try(:master) + :master => storagedomain.try(:master), + :type => "ManageIQ::Providers::Ovirt::InfraManager::#{type}" + ) + end + end + + def advertised_images + collector.advertised_images.each do |image| + parent_ems_ref = ManageIQ::Providers::Ovirt::InfraManager.make_ems_ref(image.dig(:storage_domain, :href)) + + persister.iso_images.build( + :name => image.name, + :storage => persister.storages.lazy_find(parent_ems_ref) ) end end diff --git a/app/models/manageiq/providers/ovirt/inventory/persister/infra_manager.rb b/app/models/manageiq/providers/ovirt/inventory/persister/infra_manager.rb index 5472f4b2..13492dd6 100644 --- a/app/models/manageiq/providers/ovirt/inventory/persister/infra_manager.rb +++ b/app/models/manageiq/providers/ovirt/inventory/persister/infra_manager.rb @@ -26,6 +26,7 @@ def initialize_inventory_collections add_resource_pools add_snapshots add_storages + add_iso_images add_collection(infra, :distributed_virtual_switches) add_collection(infra, :external_distributed_virtual_switches) do |builder| @@ -101,4 +102,14 @@ def add_parent_blue_folders builder.add_dependency_attributes(dependency_attributes) end end + + def add_iso_images + add_collection(infra, :iso_images) do |builder| + builder.add_properties( + :parent_inventory_collections => %i(storages), + :manager_ref => %i[name], + :model_class => IsoImage + ) + end + end end diff --git a/spec/factories/iso_datastore.rb b/spec/factories/iso_datastore.rb new file mode 100644 index 00000000..dce035dc --- /dev/null +++ b/spec/factories/iso_datastore.rb @@ -0,0 +1,3 @@ +FactoryBot.define do + factory :iso_datastore, :class => 'ManageIQ::Providers::Ovirt::InfraManager::IsoDatastore' +end diff --git a/spec/models/manageiq/providers/ovirt/infra_manager/iso_datastore_spec.rb b/spec/models/manageiq/providers/ovirt/infra_manager/iso_datastore_spec.rb new file mode 100644 index 00000000..4c6f04af --- /dev/null +++ b/spec/models/manageiq/providers/ovirt/infra_manager/iso_datastore_spec.rb @@ -0,0 +1,38 @@ +RSpec.describe ManageIQ::Providers::Ovirt::InfraManager::IsoDatastore do + include Spec::Support::ArelHelper + + let(:ems) { FactoryBot.create(:ems_redhat) } + let(:iso_datastore) { FactoryBot.create(:iso_datastore, :ext_management_system => ems, :name => ems.name) } + + 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(Storage, "name")).to eq(ems.name) + end + end + end +end diff --git a/spec/models/manageiq/providers/ovirt/infra_manager/ovirt_services/v4_spec.rb b/spec/models/manageiq/providers/ovirt/infra_manager/ovirt_services/v4_spec.rb index c93b09cb..a54f7be6 100644 --- a/spec/models/manageiq/providers/ovirt/infra_manager/ovirt_services/v4_spec.rb +++ b/spec/models/manageiq/providers/ovirt/infra_manager/ovirt_services/v4_spec.rb @@ -40,7 +40,8 @@ context "there are iso domains attached to the data-center" do context "there are active iso domains" do it 'returns iso images from an active domain' do - expect(advertised_images).to match_array(%w[iso_1 iso_2]) + res = advertised_images.map { |img| img.name } + expect(res).to match_array(%w[iso_1 iso_2]) end end