From 8dbfff0d7a2f1e4ff97cccb9b5e66f192708d4da Mon Sep 17 00:00:00 2001 From: Nadja Heitmann Date: Thu, 16 May 2024 10:38:33 +0000 Subject: [PATCH] Refs #36745 - VM is not associated upon host registration --- app/models/compute_resource.rb | 4 ++++ app/models/compute_resources/foreman/model/libvirt.rb | 4 ---- app/models/compute_resources/foreman/model/ovirt.rb | 4 ---- app/models/compute_resources/foreman/model/vmware.rb | 4 ---- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/models/compute_resource.rb b/app/models/compute_resource.rb index 32765ba5daa..bb6a9472eb6 100644 --- a/app/models/compute_resource.rb +++ b/app/models/compute_resource.rb @@ -457,6 +457,10 @@ def associate_by(name, attributes) first end + def associated_vm(host) + vms(:eager_loading => true).find { |vm| associate_by_host("mac", vm.interfaces.map(&:mac), host) } + end + def associate_by_host(name, attributes, host) attributes = Array.wrap(attributes).map { |mac| Net::Validations.normalize_mac(mac) } if name == 'mac' Host.authorized(:view_hosts, Host).where(:id => host.id).joins(:primary_interface). diff --git a/app/models/compute_resources/foreman/model/libvirt.rb b/app/models/compute_resources/foreman/model/libvirt.rb index 295a0841e54..ee2cbc38fec 100644 --- a/app/models/compute_resources/foreman/model/libvirt.rb +++ b/app/models/compute_resources/foreman/model/libvirt.rb @@ -200,10 +200,6 @@ def associated_host(vm) associate_by("mac", vm.interfaces.map(&:mac)) end - def associated_vm(host) - vms(:eager_loading => true).find { |vm| associate_by_host("mac", vm.interfaces.map(&:mac), host) } - end - def vm_compute_attributes_for(uuid) vm_attrs = super if vm_attrs[:memory_size].nil? diff --git a/app/models/compute_resources/foreman/model/ovirt.rb b/app/models/compute_resources/foreman/model/ovirt.rb index a30ad96b1bf..c6fb3db9f59 100644 --- a/app/models/compute_resources/foreman/model/ovirt.rb +++ b/app/models/compute_resources/foreman/model/ovirt.rb @@ -412,10 +412,6 @@ def associated_host(vm) associate_by("mac", vm.interfaces.map(&:mac)) end - def associated_vm(host) - vms(:eager_loading => true).find { |vm| associate_by_host("mac", vm.interfaces.map(&:mac), host) } - end - def self.provider_friendly_name "oVirt" end diff --git a/app/models/compute_resources/foreman/model/vmware.rb b/app/models/compute_resources/foreman/model/vmware.rb index 4e68ec89aa3..ea56a432e81 100644 --- a/app/models/compute_resources/foreman/model/vmware.rb +++ b/app/models/compute_resources/foreman/model/vmware.rb @@ -661,10 +661,6 @@ def associated_host(vm) associate_by("mac", vm.interfaces.map(&:mac)) end - def associated_vm(host) - vms(:eager_loading => true).find { |vm| associate_by_host("mac", vm.interfaces.map(&:mac), host) } - end - def display_type attrs[:display] || 'vmrc' end