diff --git a/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb b/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb index 7bcc572eb..6a820b0c4 100644 --- a/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb +++ b/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb @@ -26,7 +26,10 @@ def initialize_inventory_collections add_collection(infra, :ems_licenses) add_collection(infra, :ext_management_system) add_collection(infra, :guest_devices, :parent_inventory_collections => %i[vms_and_templates]) - add_collection(infra, :hardwares, :parent_inventory_collections => %i[vms_and_templates]) + add_collection(infra, :hardwares, :parent_inventory_collections => %i[vms_and_templates]) do |builder| + builder.add_properties(:track_record_changes => %i[cpu_sockets memory_mb cpu_cores_per_socket cpu_total_cores]) + end + add_collection(infra, :hosts) do |builder| builder.add_properties(:custom_reconnect_block => hosts_reconnect_block) end @@ -60,6 +63,7 @@ def initialize_inventory_collections add_collection(infra, :root_folder_relationship) add_collection(infra, :orchestration_templates) vms_and_templates_assign_created_on if ::Settings.ems_refresh.capture_vm_created_on_date + track_vm_cpu_memory_changes end def vim_class_to_collection(managed_object) @@ -79,6 +83,23 @@ def vim_class_to_collection(managed_object) private + def track_vm_cpu_memory_changes + custom_save_block = lambda do |ems, inventory_collection| + hardwares = inventory_collection.dependency_attributes[:hardwares]&.first + return if hardwares.nil? + return if hardwares.record_changes.blank? + + # TODO raise an event + end + + settings = {:without_model_class => true, :auto_inventory_attributes => false} + + add_collection(infra, :track_vm_cpu_memory_changes, {}, settings) do |builder| + builder.add_custom_save_block(custom_save_block) + builder.add_dependency_attributes(:hardwares => ->(persister) { [persister.hardwares] }) + end + end + def vms_and_templates_assign_created_on custom_save_block = lambda do |ems, inventory_collection| vms_and_templates = inventory_collection.dependency_attributes[:vms_and_templates]&.first diff --git a/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb b/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb index d0003a200..a075f6d65 100644 --- a/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb @@ -367,6 +367,12 @@ expect(prev_respool.reload.children).not_to include(vm) end + it "changing the cpu and memory" do + vm = ems.vms.find_by(:ems_ref => "vm-107") + + run_targeted_refresh(targeted_update_set(vm_change_cpu_memory)) + end + it "skip disconnected vms" do run_targeted_refresh(targeted_update_set(vm_disconnected_object_updates)) @@ -770,6 +776,33 @@ def vm_new_folder_object_updates end end + def vm_change_cpu_memory + [ + RbVmomi::VIM.ObjectUpdate( + :kind => "modify", + :obj => RbVmomi::VIM.VirtualMachine(vim, "vm-107"), + :changeSet => [ + RbVmomi::VIM.PropertyChange( + :name => "summary.config.memorySizeMB", + :op => "assign", + :val => 1024 + ), + RbVmomi::VIM.PropertyChange( + :name => "summary.config.numCpu", + :op => "assign", + :val => 4 + ), + RbVmomi::VIM.PropertyChange( + :name => "config.hardware.numCoresPerSocket", + :op => "assign", + :val => 2 + ), + ], + :missingSet => [] + ) + ] + end + def vm_create_snapshot_object_update RbVmomi::VIM.ObjectUpdate( :kind => "modify",