diff --git a/app/models/manageiq/providers/redhat/infra_manager.rb b/app/models/manageiq/providers/redhat/infra_manager.rb index 76b5a0ee5..2cac805a7 100644 --- a/app/models/manageiq/providers/redhat/infra_manager.rb +++ b/app/models/manageiq/providers/redhat/infra_manager.rb @@ -18,6 +18,8 @@ class ManageIQ::Providers::Redhat::InfraManager < ManageIQ::Providers::InfraMana supports :provisioning supports :refresh_new_target + has_many :ems_custom_attributes, :through => :vms_and_templates + def refresher Refresh::RefresherBuilder.new(self).build end @@ -76,7 +78,7 @@ def self.provision_class(via) def vm_reconfigure(vm, options = {}) ovirt_services_for_reconfigure = ManageIQ::Providers::Redhat::InfraManager::OvirtServices::Builder.new(self) - .build(:use_highest_supported_version => true).new(:ems => self) + .build(:use_highest_supported_version => true).new(:ems => self) ovirt_services_for_reconfigure.vm_reconfigure(vm, options) end diff --git a/app/models/manageiq/providers/redhat/inventory/collector.rb b/app/models/manageiq/providers/redhat/inventory/collector.rb index 2c92ef5df..3275f9ea3 100644 --- a/app/models/manageiq/providers/redhat/inventory/collector.rb +++ b/app/models/manageiq/providers/redhat/inventory/collector.rb @@ -2,7 +2,7 @@ class ManageIQ::Providers::Redhat::Inventory::Collector < ManagerRefresh::Invent require_nested :InfraManager require_nested :TargetCollection - attr_reader :emsclusters + attr_reader :ems_clusters attr_reader :networks attr_reader :storagedomains attr_reader :datacenters @@ -19,7 +19,7 @@ def initialize(manager, _target) end def initialize_inventory_sources - @emsclusters = [] + @ems_clusters = [] @networks = [] @storagedomains = [] @datacenters = [] @@ -33,7 +33,7 @@ def hash_collection ::ManageIQ::Providers::Redhat::Inventory::HashCollection end - def collect_emsclusters + def collect_ems_clusters manager.with_provider_connection(VERSION_HASH) do |connection| connection.system_service.clusters_service.list end diff --git a/app/models/manageiq/providers/redhat/inventory/collector/infra_manager.rb b/app/models/manageiq/providers/redhat/inventory/collector/infra_manager.rb index 683b01cd8..9ff306965 100644 --- a/app/models/manageiq/providers/redhat/inventory/collector/infra_manager.rb +++ b/app/models/manageiq/providers/redhat/inventory/collector/infra_manager.rb @@ -1,6 +1,6 @@ class ManageIQ::Providers::Redhat::Inventory::Collector::InfraManager < ManageIQ::Providers::Redhat::Inventory::Collector - def emsclusters - collect_emsclusters + def ems_clusters + collect_ems_clusters end def networks diff --git a/app/models/manageiq/providers/redhat/inventory/collector/target_collection.rb b/app/models/manageiq/providers/redhat/inventory/collector/target_collection.rb index 5c7e5f182..2a2c9a356 100644 --- a/app/models/manageiq/providers/redhat/inventory/collector/target_collection.rb +++ b/app/models/manageiq/providers/redhat/inventory/collector/target_collection.rb @@ -8,79 +8,95 @@ def initialize(_manager, _target) target.manager_refs_by_association_reset end - def clusters - if target.kind_of? VmOrTemplate - return collect_emsclusters + def ems_clusters + clusters = [] + return clusters if references(:ems_clusters).blank? + + manager.with_provider_connection(VERSION_HASH) do |connection| + references(:ems_clusters).each do |id| + clusters + connection.system_service.clusters_service.cluster_service(id).get + end end - [] + clusters end def networks - if target.kind_of? Host - return collect_networks + nets = [] + return domains if references(:networks).blank? + + manager.with_provider_connection(VERSION_HASH) do |connection| + references(:networks).each do |id| + nets + connection.system_service.networks_service.network_service(id).get + end end - [] + nets end def storagedomains - if target.kind_of? VmOrTemplate - domains = if target.storages.empty? - collect_storagedomains - else - collect_storagedomain(target.storages.map { |s| uuid_from_target(s) }) - end - return domains - end - - [] - end + domains = [] + return domains if references(:storagedomains).blank? - def collect_storagedomain(uuids) manager.with_provider_connection(VERSION_HASH) do |connection| - uuids.collect do |uuid| - connection.system_service.storage_domains_service.storage_domain_service(uuid).get + references(:storagedomains).each do |id| + domains + connection.system_service.storage_domains_service.storage_domain_service(id).get end end + + domains end def datacenters - if target.kind_of? VmOrTemplate - return collect_datacenters + dcs = [] + return dcs if references(:datacenters).blank? + + manager.with_provider_connection(VERSION_HASH) do |connection| + references(:datacenters).each do |id| + dcs + connection.system_service.data_centers_service.data_center_service(id).get + end end - [] + dcs end def hosts - if target.kind_of? Host - manager.with_provider_connection(VERSION_HASH) do |connection| - return connection.system_service.hosts_service.host_service(uuid_from_target(target)).get + h = [] + return h if references(:hosts).blank? + + manager.with_provider_connection(VERSION_HASH) do |connection| + references(:vms).each do |ems_ref| + h + connection.system_service.hosts_service.host_service(uuid_from_ems_ref(ems_ref)).get end end - [] + h end def vms - if target.kind_of? VmOrTemplate - manager.with_provider_connection(VERSION_HASH) do |connection| - return connection.system_service.vms_service.vm_service(uuid_from_target(target)).get + v = [] + return v if references(:vms).blank? + + manager.with_provider_connection(VERSION_HASH) do |connection| + references(:vms).each do |ems_ref| + v + connection.system_service.vms_service.vm_service(uuid_from_ems_ref(ems_ref)).get end end - [] + v end def templates - if target.kind_of? VmOrTemplate - manager.with_provider_connection(VERSION_HASH) do |connection| - connection.system_service.templates_service.list(:search => "vm.id=#{uuid_from_target(target)}") + temp = [] + return temp if references(:templates).blank? + + manager.with_provider_connection(VERSION_HASH) do |connection| + references(:templates).each do |id| + temp + connection.system_service.templates_service.list(:search => "vm.id=#{id}") end end - [] + temp end def references(collection) @@ -126,13 +142,24 @@ def infer_related_vm_ems_refs_db! changed_vms = manager.vms.where(:ems_ref => references(:vms)) changed_vms.each do |vm| - # TODO + add_simple_target!(:ems_clusters, uuid_from_target(vm.ems_cluster)) + vm.storages.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:storagedomains, uuid_from_ems_ref(ems_ref)) } + add_simple_target!(:datacenters, uuid_from_target(vm.parent_datacenter)) + add_simple_target!(:templates, uuid_from_target(vm)) end end def infer_related_vm_ems_refs_api! vms.each do |vm| - # TODO + add_simple_target!(:ems_clusters, vm.cluster.id) + disks = collect_attached_disks(vm) + disks.each do |disk| + disk.storage_domains.to_miq_a.each do |sd| + add_simple_target!(:storagedomains, sd.id) + end + end + add_simple_target!(:datacenters, vm.cluster.data_center.id) + add_simple_target!(:templates, vm.id) end end @@ -140,20 +167,28 @@ def infer_related_host_ems_refs_db! changed_hosts = manager.hosts.where(:ems_ref => references(:hosts)) changed_hosts.each do |host| - # TODO + add_simple_target!(:ems_clusters, uuid_from_target(host.ems_cluster)) + # TODO: host.hardware.networks do not have ems_ref nor ems_uid end end def infer_related_host_ems_refs_api! hosts.each do |host| - # TODO + add_simple_target!(:ems_clusters, host.cluster.id) + host.network_attachments.each do |attachement| + add_simple_target!(:networks, attachement.network.id) + end end end private def uuid_from_target(t) - URI(t.ems_ref).path.split('/').last + uuid_from_ems_ref(t.ems_ref) + end + + def uuid_from_ems_ref(ems_ref) + URI(ems_ref).path.split('/').last end def add_simple_target!(association, ems_ref) diff --git a/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb b/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb index edef428a7..92be1bf17 100644 --- a/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb +++ b/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb @@ -3,8 +3,8 @@ def parse log_header = "MIQ(#{self.class.name}.#{__method__}) Collecting data for EMS name: [#{collector.manager.name}] id: [#{collector.manager.id}]" $rhevm_log.info("#{log_header}...") + ems_clusters datacenters - clusters storagedomains hosts vms @@ -12,22 +12,24 @@ def parse $rhevm_log.info("#{log_header}...Complete") end - def clusters - collector.emsclusters.each do |cluster| + def ems_clusters + collector.ems_clusters.each do |cluster| + r_id = "#{cluster.id}_respool" + persister.resource_pools.find_or_build(r_id).assign_attributes( :name => "Default for Cluster #{cluster.name}", - :uid_ems => "#{cluster.id}_respool", + :uid_ems => r_id, :is_default => true, ) ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(cluster.href) - persister.emsclusters.find_or_build(cluster.id).assign_attributes( + persister.ems_clusters.find_or_build(ems_ref).assign_attributes( :ems_ref => ems_ref, :ems_ref_obj => ems_ref, :uid_ems => cluster.id, :name => cluster.name, - :datacenter_id => persister.datacenters.lazy_find(cluster.data_center.id).id, + :datacenter_id => cluster.data_center.id, ) end end @@ -47,11 +49,10 @@ def storagedomains used = storagedomain.try(:used).to_i total = free + used committed = storagedomain.try(:committed).to_i - uncommitted = total - committed ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(storagedomain.try(:href)) - persister.storagedomains.find_or_build(storagedomain.id).assign_attributes( + persister.storages.find_or_build(storagedomain.id).assign_attributes( :ems_ref => ems_ref, :ems_ref_obj => ems_ref, :name => storagedomain.try(:name), @@ -59,7 +60,7 @@ def storagedomains :storage_domain_type => storagedomain.dig(:type, :downcase), :total_space => total, :free_space => free, - :uncommitted => uncommitted, + :uncommitted => total - committed, :multiplehostaccess => true, :location => location, :master => storagedomain.try(:master) @@ -110,11 +111,12 @@ def hosts host_os_version = host.dig(:os, :version) ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(host_inv.href) - clusters = persister.clusters.lazy_find(host.dig(:cluster, :id)) - dc_ids = clusters.collect { |c| c[:datacenter_id] }.uniq + cluster = persister.ems_clusters.lazy_find(host.dig(:cluster, :id)) + dc_id = cluster[:datacenter_id] storage_ids = [] dcs.each do |dc| - if dc_ids.include? dc.id + if dc_id == dc.id + # TODO: check whether we could resolve this in a lazy way storage_ids << collector.collect_dc_domains(dc).to_miq_a.collect { |s| s[:id] } end end @@ -133,14 +135,14 @@ def hosts :vmm_buildnumber => (host_os_version.build if host_os_version), :connection_state => connection_state, :power_state => power_state, - :ems_cluster => clusters, + :ems_cluster => cluster, :ipmi_address => ipmi_address, :storages => storage_ids ) host_operating_systems(persister_host, host, hostname) networks = collector.collect_networks - switchs(persister_host, host, nics, networks) + switches(persister_host, host, nics, networks) host_hardware(persister_host, host, networks, nics) end end @@ -187,11 +189,7 @@ def host_guest_devices(persister_hardware, nics, networks) nics.to_miq_a.each do |nic| network = network_from_nic(nic, host, networks) - if network - switch_uid = network.id - else - switch_uid = network_name unless network_name.nil? - end + switch_uid = network.try(:id) || network_name location = nil location = $1 if nic.name =~ /(\d+)$/ @@ -203,17 +201,17 @@ def host_guest_devices(persister_hardware, nics, networks) :location => location, :present => true, :controller_type => 'ethernet', - :switch => persister.switchs.lazy_find(switch_uid), + :switch => persister.switches.lazy_find(switch_uid), :network => persister.host_nics.lazy_find(network.id) ) end end - def switchs(persister_host, host, nics, networks) + def switches(persister_host, host, nics, networks) nics.to_miq_a.each do |nic| network = network_from_nic(nic, host, networks) - persister_switch = persister.switchs.find_or_build(persister_host).assign_attributes( + persister_switch = persister.switches.find_or_build(persister_host).assign_attributes( :uid_ems => uid, :name => name, ) @@ -225,12 +223,14 @@ def switchs(persister_host, host, nics, networks) def network_for_nic(nic, host, networks) network_id = nic.dig(:network, :id) if network_id + # TODO: check to indexed_networks = networks.index_by(:id) network = networks.detect { |n| n.id == network_id } else network_name = nic.dig(:network, :name) cluster_id = host.dig(:cluster, :id) cluster = persister.clusters.lazy_find(cluster_id) datacenter_id = cluster.dig(:data_center, :id) + # TODO: get rid of detect network = networks.detect { |n| n.name == network_name && n.dig(:data_center, :id) == datacenter_id } end @@ -300,7 +300,7 @@ def vms :raw_power_state => template ? "never" : vm.status, :boot_time => vm.try(:start_time), :host => persister.hosts.lazy_find(host_id), - :ems_cluster => persister.clusters.lazy_find(vm.cluster.id), + :ems_cluster => persister.ems_clusters.lazy_find(vm.cluster.id), :storages => storages, :storage => storages.first, ) @@ -314,9 +314,9 @@ def vms def storages(vm) storages = [] - collector.attached_disks(vm).to_miq_a.each do |disk| + collector.collect_attached_disks(vm).to_miq_a.each do |disk| disk.storage_domains.to_miq_a.each do |sd| - storages << persister.storages.lazy_find(:ems_ref => sd.id) + storages << persister.storages.lazy_find(sd.id) end end storages.compact! @@ -330,8 +330,6 @@ def vm_hardware(presister_vm, vm) cpu_socks = topology.try(:sockets) || 1 cpu_cores = topology.try(:cores) || 1 - result[:memory_mb] = vm.memory / 1.megabyte - persister_hardware = persister.hardwares.find_or_build(presister_vm).assign_attributes( :guest_os => vm.dig(:os, :type), :annotation => vm.try(:description), @@ -398,13 +396,15 @@ def hardware_disks(persister_hardware, vm) :disk_type => device.sparse == true ? 'thin' : 'thick', :mode => 'persistent', :bootable => device.try(:bootable), - :storage => persister.storages.lazy_find(:ems_ref => storage_id) + :storage => persister.storages.lazy_find(storage_id) ) end end end def hardware_guest_devices(persister_hardware, vm, addresses) + network = addresses.to_a.empty? ? nil : persister.nics.lazy_find(addresses[0]) + collector.collect_nics(vm).each do |nic| persister.guest_devices.find_or_build_by( :hardware => persister_hardware, @@ -416,7 +416,7 @@ def hardware_guest_devices(persister_hardware, vm, addresses) :controller_type => 'ethernet', :address => nic.dig(:mac, :address), :lan => nic.dig(:network, :id), - :network => persister.nics.lazy_find(addresses[0]) + :network => network ) end end @@ -428,7 +428,7 @@ def snapshots(persister_vm, vm) name = description = snapshot.description name = "Active Image" if name[0, 13] == '_ActiveImage_' - persister.snapshots.find_or_build_by(persister_vm).assign_attributes( + persister.snapshots.find_or_build(persister_vm).assign_attributes( :uid_ems => snapshot.id, :uid => snapshot.id, :parent_uid => parent_id, @@ -444,7 +444,7 @@ def snapshots(persister_vm, vm) def operating_systems(persister_vm, vm) guest_os = vm.dig(:os, :type) - persister.operating_systems.find_or_build_by(persister_vm).assign_attributes( + persister.operating_systems.find_or_build(persister_vm).assign_attributes( :product_name => guest_os.blank? ? "Other" : guest_os, :system_type => vm.type ) @@ -452,10 +452,9 @@ def operating_systems(persister_vm, vm) def custom_attributes(persister_vm, vm) custom_attrs = vm.try(:custom_properties) - return result if custom_attrs.nil? - custom_attrs.each do |ca| - persister.custom_attributes.find_or_build_by(persister_vm).assign_attributes( + custom_attrs.to_a.each do |ca| + persister.custom_attributes.find_or_build(persister_vm).assign_attributes( :section => 'custom_field', :name => ca.name, :value => ca.value.try(:truncate, 255), diff --git a/app/models/manageiq/providers/redhat/inventory/persister/infra_manager.rb b/app/models/manageiq/providers/redhat/inventory/persister/infra_manager.rb index 4d153715d..c3da30ce7 100644 --- a/app/models/manageiq/providers/redhat/inventory/persister/infra_manager.rb +++ b/app/models/manageiq/providers/redhat/inventory/persister/infra_manager.rb @@ -2,7 +2,7 @@ class ManageIQ::Providers::Redhat::Inventory::Persister::InfraManager < ManageIQ def initialize_inventory_collections add_inventory_collections( infra, - %i(datacenters emsfolders emsclusters hosts resourcepools vm_or_templates vm + %i(datacenters emsfolders ems_clusters hosts resourcepools vm_or_templates vm miq_templates storages custom_attributes customization_specs disks guest_devices hardwars lans miq_scsi_luns miq_scsi_targets networks operating_systems snapshots switchs system_services) diff --git a/app/models/manageiq/providers/redhat/inventory/persister/target_collection.rb b/app/models/manageiq/providers/redhat/inventory/persister/target_collection.rb index b4fde814a..dcc8010de 100644 --- a/app/models/manageiq/providers/redhat/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/redhat/inventory/persister/target_collection.rb @@ -23,7 +23,7 @@ def initialize_inventory_collections ) add_inventory_collection( - infra.emsclusters_children( + infra.ems_clusters_children( :dependency_attributes => { :resource_pools => [collections[:resource_pools]], } @@ -35,11 +35,6 @@ def references(collection) target.manager_refs_by_association.try(:[], collection).try(:[], :ems_ref).try(:to_a) || [] end - # TODO: check whether needed - def name_references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :name).try(:to_a) || [] - end - def infra ManageIQ::Providers::Redhat::InventoryCollectionDefault::InfraManager end @@ -47,13 +42,16 @@ def infra def add_targeted_inventory_collections add_vms_inventory_collections(references(:vms)) add_resource_pools_inventory_collections(references(:resource_pools)) - add_clusters_inventory_collections(references(:emsclusters)) + add_clusters_inventory_collections(references(:ems_clusters)) add_datacenters_inventory_collections(references(:datacenters)) - - # TODO: check what needs to be added here + add_storages_inventory_collcetions(references(:storages)) + add_hosts_inventory_collections(references(:hosts)) + add_guest_devices_inventory_collections(references(:guest_devices)) + add_snapshots_inventory_collections(references(:snapshots)) + add_operating_systems_inventory_collections(references(:operating_systems)) + add_custom_attributes_inventory_collections(references(:custom_attributes)) end - # TODO: check correctness def add_vms_inventory_collections(manager_refs) return if manager_refs.blank? @@ -79,6 +77,14 @@ def add_vms_inventory_collections(manager_refs) :strategy => :local_db_find_missing_references ) ) + add_inventory_collection( + infra.hardwares( + :arel => manager.hardwares.joins(:vm_or_template).where( + 'vms' => {:ems_ref => manager_refs} + ), + :strategy => :local_db_find_missing_references + ) + ) end def add_resource_pools_inventory_collections(manager_refs) @@ -113,4 +119,78 @@ def add_datacenters_inventory_collections(manager_refs) ) ) end + + def add_storages_inventory_collcetions(manager_refs) + return if manager_refs.blank? + + add_inventory_collection( + infra.storages( + :arel => manager.storages.where(:ems_ref => manager_refs), + :strategy => :local_db_find_missing_references + ) + ) + end + + def add_hosts_inventory_collections(manager_refs) + return if manager_refs.blank? + + add_inventory_collection( + infra.storages( + :arel => manager.hosts.where(:ems_ref => manager_refs), + :strategy => :local_db_find_missing_references + ) + ) + end + + def add_guest_devices_inventory_collections(manager_refs) + return if manager_refs.blank? + + add_inventory_collection( + infra.guest_devices( + :arel => GuestDevice.joins(:hardware => :vm_or_template).where( + :hardware => {'vms' => {:ems_ref => manager_refs}} + ), + :strategy => :local_db_find_missing_references + ) + ) + end + + def add_snapshots_inventory_collections(manager_refs) + return if manager_refs.blank? + + add_inventory_collection( + infra.snapshots( + :arel => Snapshot.joins(:vm_or_template).where( + 'vms' => {:ems_ref => manager_refs} + ), + :strategy => :local_db_find_missing_references + ) + ) + end + + def add_operating_systems_inventory_collections(manager_refs) + return if manager_refs.blank? + + add_inventory_collection( + infra.operating_systems( + :arel => OperatingSystem.joins(:vm_or_template).where( + 'vms' => {:ems_ref => manager_refs} + ), + :strategy => :local_db_find_missing_references + ) + ) + end + + def add_custom_attributes_inventory_collections(manager_refs) + return if manager_refs.blank? + + add_inventory_collection( + infra.custom_attributes( + :arel => manager.ems_custom_attributes.joins(:vm_or_template).where( + 'vms' => {:ems_ref => manager_refs} + ), + :strategy => :local_db_find_missing_references + ) + ) + end end diff --git a/app/models/manageiq/providers/redhat/inventory_collection_default/infra_manager.rb b/app/models/manageiq/providers/redhat/inventory_collection_default/infra_manager.rb index 926d9e9a0..298a53763 100644 --- a/app/models/manageiq/providers/redhat/inventory_collection_default/infra_manager.rb +++ b/app/models/manageiq/providers/redhat/inventory_collection_default/infra_manager.rb @@ -2,7 +2,7 @@ class ManageIQ::Providers::Redhat::InventoryCollectionDefault::InfraManager < Ma class << self def vms(extra_attributes = {}) attributes = { - :model_class => ::ManageIQ::Providers::InfraManager::Vm, + :model_class => ::ManageIQ::Providers::Redhat::InfraManager::Vm, :inventory_object_attributes => [ :type, :ems_ref, @@ -60,6 +60,23 @@ def nics(extra_attributes = {}) super(attributes.merge!(extra_attributes)) end + def guest_devices(extra_attributes = {}) + attributes = { + :model_class => ::GuestDevice, + :inventory_object_attributes => [ + :uid_ems, + :device_name, + :device_type, + :controller_type, + :address, + :lan, + :network + ] + } + + super(attributes.merge!(extra_attributes)) + end + def hardwares(extra_attributes = {}) attributes = { :model_class => ::Hardware, @@ -76,6 +93,49 @@ def hardwares(extra_attributes = {}) super(attributes.merge!(extra_attributes)) end + def snapshots(extra_attributes = {}) + attributes = { + :model_class => ::Snapshot, + :inventory_object_attributes => [ + :uid_ems, + :uid, + :parent_uid, + :name, + :description, + :create_time, + :current, + ] + } + + super(attributes.merge!(extra_attributes)) + end + + def operating_systems(extra_attributes = {}) + attributes = { + :model_class => ::OperatingSystem, + :inventory_object_attributes => [ + :product_name, + :system_type + ] + } + + super(attributes.merge!(extra_attributes)) + end + + def custom_attributes(extra_attributes = {}) + attributes = { + :model_class => ::CustomAttribute, + :inventory_object_attributes => [ + :section, + :name, + :value, + :source, + ] + } + + super(attributes.merge!(extra_attributes)) + end + def datacenters(extra_attributes = {}) attributes = { :model_class => ::Datacenter, @@ -118,5 +178,52 @@ def ems_clusters(extra_attributes = {}) super(attributes.merge!(extra_attributes)) end + + def storages(extra_attributes = {}) + attributes = { + :model_class => ::Storage, + :inventory_object_attributes => [ + :ems_ref, + :ems_ref_obj, + :name, + :store_type, + :storage_domain_type, + :total_space, + :free_space, + :uncommitted, + :multiplehostaccess, + :location, + :master + ] + } + + super(attributes.merge!(extra_attributes)) + end + + def hosts(extra_attributes = {}) + attributes = { + :model_class => ::ManageIQ::Providers::Redhat::InfraManager::Host, + :inventory_object_attributes => [ + :type, + :ems_ref, + :ems_ref_obj, + :name, + :hostname, + :ipaddress, + :uid_ems, + :vmm_vendor, + :vmm_product, + :vmm_version, + :vmm_buildnumber, + :connection_state, + :power_state, + :ems_cluster, + :ipmi_address, + :storages + ] + } + + super(attributes.merge!(extra_attributes)) + end end end diff --git a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/disks.yml b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/disks.yml new file mode 100644 index 000000000..999e3fd3d --- /dev/null +++ b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/disks.yml @@ -0,0 +1,103 @@ +--- +- !ruby/object:OvirtSDK4::Disk + href: "/ovirt-engine/api/disks/c413aff6-e988-4830-8b24-f74af66ced5a" + comment: + description: + id: c413aff6-e988-4830-8b24-f74af66ced5a + name: new_Disk1 + instance_type: + template: + vm: + vms: + active: true + actual_size: 0 + alias_: new_Disk1 + bootable: true + disk_profile: !ruby/object:OvirtSDK4::DiskProfile + href: "/ovirt-engine/api/diskprofiles/5ea19cf2-37fa-45fd-9034-87fe4c4d1c0a" + comment: + description: + id: 5ea19cf2-37fa-45fd-9034-87fe4c4d1c0a + name: + permissions: + qos: + storage_domain: + format: raw + image_id: 7c702634-a9e5-4107-8bb1-b0c3d900096d + initial_size: + interface: virtio_scsi + logical_name: + lun_storage: + openstack_volume_type: + permissions: !ruby/array:OvirtSDK4::List + internal: [] + ivars: + :@href: "/ovirt-engine/api/disks/c413aff6-e988-4830-8b24-f74af66ced5a/permissions" + propagate_errors: false + provisioned_size: 1073741824 + quota: !ruby/object:OvirtSDK4::Quota + href: + comment: + description: + id: 58ad9d24-00d3-00c3-01e2-00000000035b + name: + cluster_hard_limit_pct: + cluster_soft_limit_pct: + data_center: + disks: + permissions: + quota_cluster_limits: + quota_storage_limits: + storage_hard_limit_pct: + storage_soft_limit_pct: + users: + vms: + read_only: + sgio: + shareable: false + snapshot: + sparse: true + statistics: !ruby/array:OvirtSDK4::List + internal: [] + ivars: + :@href: "/ovirt-engine/api/disks/c413aff6-e988-4830-8b24-f74af66ced5a/statistics" + status: ok + storage_domain: + storage_domains: !ruby/array:OvirtSDK4::List + internal: + - !ruby/object:OvirtSDK4::StorageDomain + href: "/ovirt-engine/api/storagedomains/6cc26c9d-e1a7-43ba-95d3-c744442c7500" + comment: + description: + id: 6cc26c9d-e1a7-43ba-95d3-c744442c7500 + name: + available: + committed: + critical_space_action_blocker: + data_center: + data_centers: + disk_profiles: + disk_snapshots: + disks: + external_status: + files: + host: + images: + import: + master: + permissions: + status: + storage: + storage_connections: + storage_format: + templates: + type: + used: + vms: + warning_low_space_indicator: + wipe_after_delete: + ivars: + :@href: + storage_type: image + uses_scsi_reservation: + wipe_after_delete: false diff --git a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/nics.yml b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/nics.yml new file mode 100644 index 000000000..997068af9 --- /dev/null +++ b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/nics.yml @@ -0,0 +1,123 @@ +- !ruby/object:OvirtSDK4::Nic + href: "/ovirt-engine/api/vms/3a697bd0-7cea-42a1-95ef-fd292fcee721/nics/bec92d4f-9b9e-462f-9cd4-7d6b99948a81" + comment: + description: + id: bec92d4f-9b9e-462f-9cd4-7d6b99948a81 + name: nic1 + instance_type: + template: + vm: !ruby/object:OvirtSDK4::Vm + href: "/ovirt-engine/api/vms/3a697bd0-7cea-42a1-95ef-fd292fcee721" + comment: + description: + id: 3a697bd0-7cea-42a1-95ef-fd292fcee721 + name: + bios: + cluster: + console: + cpu: + cpu_profile: + cpu_shares: + creation_time: + custom_compatibility_version: + custom_cpu_model: + custom_emulated_machine: + custom_properties: + delete_protected: + display: + domain: + high_availability: + initialization: + io: + large_icon: + memory: + memory_policy: + migration: + migration_downtime: + origin: + os: + quota: + rng_device: + serial_number: + small_icon: + soundcard_enabled: + sso: + start_paused: + stateless: + storage_domain: + time_zone: + tunnel_migration: + type: + usb: + virtio_scsi: + affinity_labels: + applications: + cdroms: + disk_attachments: + external_host_provider: + floppies: + fqdn: + graphics_consoles: + guest_operating_system: + guest_time_zone: + host: + host_devices: + instance_type: + katello_errata: + next_run_configuration_exists: + nics: + numa_nodes: + numa_tune_mode: + payloads: + permissions: + placement_policy: + reported_devices: + run_once: + sessions: + snapshots: + start_time: + statistics: + status: + status_detail: + stop_reason: + stop_time: + tags: + template: + use_latest_template_version: + vm_pool: + watchdogs: + vms: + boot_protocol: + interface: virtio + linked: true + mac: !ruby/object:OvirtSDK4::Mac + href: + address: 00:1a:4a:16:01:51 + network: + network_attachments: + network_labels: + on_boot: + plugged: true + reported_devices: !ruby/array:OvirtSDK4::List + internal: [] + ivars: + :@href: "/ovirt-engine/api/vms/3a697bd0-7cea-42a1-95ef-fd292fcee721/nics/bec92d4f-9b9e-462f-9cd4-7d6b99948a81/reporteddevices" + statistics: !ruby/array:OvirtSDK4::List + internal: [] + ivars: + :@href: "/ovirt-engine/api/vms/3a697bd0-7cea-42a1-95ef-fd292fcee721/nics/bec92d4f-9b9e-462f-9cd4-7d6b99948a81/statistics" + virtual_function_allowed_labels: + virtual_function_allowed_networks: + vnic_profile: !ruby/object:OvirtSDK4::VnicProfile + href: "/ovirt-engine/api/vnicprofiles/0000000a-000a-000a-000a-000000000398" + comment: + description: + id: 0000000a-000a-000a-000a-000000000398 + name: + custom_properties: + network: + network_filter: + pass_through: + permissions: + port_mirroring: + qos: \ No newline at end of file diff --git a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/snapshots.yml b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/snapshots.yml new file mode 100644 index 000000000..6fc96c9fc --- /dev/null +++ b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/snapshots.yml @@ -0,0 +1,85 @@ +- !ruby/object:OvirtSDK4::Snapshot + href: "/ovirt-engine/api/vms/3a697bd0-7cea-42a1-95ef-fd292fcee721/snapshots/4af35c92-7c6e-4c23-b25e-e05cb29bed49" + comment: + description: Active VM + id: 4af35c92-7c6e-4c23-b25e-e05cb29bed49 + name: + bios: + cluster: + console: + cpu: + cpu_profile: + cpu_shares: + creation_time: + custom_compatibility_version: + custom_cpu_model: + custom_emulated_machine: + custom_properties: + delete_protected: + display: + domain: + high_availability: + initialization: + io: + large_icon: + memory: + memory_policy: + migration: + migration_downtime: + origin: + os: + quota: + rng_device: + serial_number: + small_icon: + soundcard_enabled: + sso: + start_paused: + stateless: + storage_domain: + time_zone: + tunnel_migration: + type: + usb: + virtio_scsi: + affinity_labels: + applications: + cdroms: + disk_attachments: + external_host_provider: + floppies: + fqdn: + graphics_consoles: + guest_operating_system: + guest_time_zone: + host: + host_devices: + instance_type: + katello_errata: + next_run_configuration_exists: + nics: + numa_nodes: + numa_tune_mode: + payloads: + permissions: + placement_policy: + reported_devices: + run_once: + sessions: + snapshots: + start_time: + statistics: + status: + status_detail: + stop_reason: + stop_time: + tags: + template: + use_latest_template_version: + vm_pool: + watchdogs: + date: !ruby/object:DateTime 2017-02-23 15:58:23.054000000 +01:00 + persist_memorystate: false + snapshot_status: ok + snapshot_type: active + vm: \ No newline at end of file diff --git a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/vms.yml b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/vms.yml index c3e287edf..1fc0a9354 100644 --- a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/vms.yml +++ b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/target_response_yamls/vms.yml @@ -28,7 +28,26 @@ cpu: cpu_profiles: custom_scheduling_policy_properties: - data_center: + data_center: !ruby/object:OvirtSDK4::DataCenter + href: "/ovirt-engine/api/datacenters/00000001-0001-0001-0001-000000000311" + comment: + description: + id: 00000001-0001-0001-0001-000000000311 + name: + clusters: + iscsi_bonds: + local: + mac_pool: + networks: + permissions: + qoss: + quota_mode: + quotas: + status: + storage_domains: + storage_format: + supported_versions: + version: display: error_handling: fencing_policy: diff --git a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_target_vm_4_spec.rb b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_target_vm_4_spec.rb index 1777a6d03..69e6ec905 100644 --- a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_target_vm_4_spec.rb +++ b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_target_vm_4_spec.rb @@ -23,26 +23,17 @@ def load_response_mock_for(filename) end before(:each) do - inventory_wrapper_class = ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies::V4 - allow_any_instance_of(inventory_wrapper_class) - .to receive(:collect_clusters).and_return(load_response_mock_for('clusters')) - allow_any_instance_of(inventory_wrapper_class) - .to receive(:collect_datacenters).and_return(load_response_mock_for('datacenters')) - allow_any_instance_of(inventory_wrapper_class) - .to receive(:collect_vm_by_uuid).and_return(load_response_mock_for('vms')) - allow_any_instance_of(inventory_wrapper_class) - .to receive(:collect_storage).and_return(load_response_mock_for('storages')) - allow_any_instance_of(inventory_wrapper_class) - .to receive(:search_templates).and_return(load_response_mock_for('templates')) - allow_any_instance_of(inventory_wrapper_class).to receive(:api).and_return("4.2.0_master") - allow_any_instance_of(inventory_wrapper_class).to receive(:service) + @inventory_wrapper_class = ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies::V4 + allow_any_instance_of(@inventory_wrapper_class).to receive(:api).and_return("4.2.0_master") + allow_any_instance_of(@inventory_wrapper_class).to receive(:service) .and_return(OpenStruct.new(:version_string => '4.2.0_master')) @cluster = FactoryGirl.create(:ems_cluster, - :ems_ref => "/api/clusters/00000002-0002-0002-0002-00000000017a", - :uid_ems => "00000002-0002-0002-0002-00000000017a", - :ems_id => @ems.id, - :name => "Default") + :ems_ref => "/api/clusters/00000002-0002-0002-0002-00000000017a", + :uid_ems => "00000002-0002-0002-0002-00000000017a", + # :ems_id => @ems.id, + :ext_management_system => @ems, + :name => "Default") @storage = FactoryGirl.create(:storage, :ems_ref => "/api/storagedomains/6cc26c9d-e1a7-43ba-95d3-c744442c7500", @@ -65,6 +56,17 @@ def load_response_mock_for(filename) end it "should refresh a vm" do + allow_any_instance_of(@inventory_wrapper_class) + .to receive(:collect_clusters).and_return(load_response_mock_for('clusters')) + allow_any_instance_of(@inventory_wrapper_class) + .to receive(:collect_datacenters).and_return(load_response_mock_for('datacenters')) + allow_any_instance_of(@inventory_wrapper_class) + .to receive(:collect_vm_by_uuid).and_return(load_response_mock_for('vms')) + allow_any_instance_of(@inventory_wrapper_class) + .to receive(:collect_storage).and_return(load_response_mock_for('storages')) + allow_any_instance_of(@inventory_wrapper_class) + .to receive(:search_templates).and_return(load_response_mock_for('templates')) + EmsRefresh.refresh(@vm) assert_table_counts @@ -77,6 +79,39 @@ def load_response_mock_for(filename) it "should collect a vm" do allow(Settings.ems_refresh).to receive(:rhevm).and_return(:inventory_object_refresh => true) + cluster_service = double("cluster_service") + allow(cluster_service).to receive(:get).and_return(load_response_mock_for('clusters')) + allow_any_instance_of(OvirtSDK4::ClustersService).to receive(:cluster_service).and_return(cluster_service) + + data_center_service = double("data_center_service") + allow(data_center_service).to receive(:get).and_return(load_response_mock_for('datacenters')) + allow_any_instance_of(OvirtSDK4::DataCentersService).to receive(:data_center_service).and_return(data_center_service) + + storage_domain_service = double("storage_domain_service") + allow(storage_domain_service).to receive(:get).and_return(load_response_mock_for('storages')) + allow_any_instance_of(OvirtSDK4::StorageDomainsService).to receive(:storage_domain_service).and_return(storage_domain_service) + + collector_class = ManageIQ::Providers::Redhat::Inventory::Collector + allow_any_instance_of(collector_class).to receive(:collect_attached_disks).and_return(load_response_mock_for('disks')) + allow_any_instance_of(collector_class).to receive(:collect_vm_devices).and_return([]) + allow_any_instance_of(collector_class).to receive(:collect_nics).and_return(load_response_mock_for('nics')) + allow_any_instance_of(collector_class).to receive(:collect_snapshots).and_return(load_response_mock_for('snapshots')) + target_collector_class = ManageIQ::Providers::Redhat::Inventory::Collector::TargetCollection + allow_any_instance_of(target_collector_class).to receive(:templates).and_return(load_response_mock_for('templates')) + allow_any_instance_of(target_collector_class).to receive(:vms).and_return(load_response_mock_for('vms')) + + allow(@vm).to receive(:ems_cluster).and_return(@cluster) + + dc = FactoryGirl.create(:datacenter, + :ems_ref => "/ovirt-engine/api/datacenters/00000001-0001-0001-0001-000000000311", + :name => "Default", + :uid_ems => "00000001-0001-0001-0001-000000000311") + + allow(@vm).to receive(:parent_datacenter).and_return(dc) + vms = double("vms") + allow(vms).to receive(:where).and_return([@vm]) + allow(@ems).to receive(:vms).and_return(vms) + EmsRefresh.refresh(@vm) # TODO: once implemented remove comments