Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36745 - VM is not associated upon host registration #9833

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

goarsna
Copy link
Contributor

@goarsna goarsna commented Sep 14, 2023

Upon host registration no VM is associated to the newly registered host. Therefore, no VM information is visible in the host details page (Legacy UI). IMO association of the VM should happen automatically upon registration.

With this PR I want to add some code to search for the VM that belongs to a certain host by the already present search criteria in the compute resources. If a corresponding VM is found the host will be associated to it.

@theforeman-bot
Copy link
Member

Issues: #36745

@theforeman-bot
Copy link
Member

Can one of the admins verify this patch?

2 similar comments
@theforeman-bot
Copy link
Member

Can one of the admins verify this patch?

@theforeman-bot
Copy link
Member

Can one of the admins verify this patch?

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry this may have a serious performance impact so perhaps this should be opt in, or at least provide an opt out.

@stejskalleos could you take a look?

app/models/compute_resource.rb Outdated Show resolved Hide resolved
@stejskalleos
Copy link
Contributor

ok to test

@stejskalleos stejskalleos self-assigned this Sep 19, 2023
Copy link
Contributor

@stejskalleos stejskalleos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
the PR is about Associating VMs when registering the host, but it also does some refactoring of associated_host and associated_vm methods, moving them to the compute_resource, if I understand that correctly.

I don't think it should be a part of this PR. Refactoring is always tricky, and it requires a lot of testing across all the compute resources, like Azure and Google, to make sure that it's not breaking anything.

I suggest splitting the PR into two, plus fixing rubocop and unit tests

@@ -448,9 +460,13 @@ def nested_attributes_for(type, opts)
end.compact
end

def associate_by(name, attributes)
def associate_by(name, attributes, host = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating a new method associate_by_host?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @stejskalleos,
this is exactly what my is supposed to do. And thanks for your suggestion with the new associate_by_host method. I adjusted my changes accordlingly and found out that this approach makes it all in all really simple.
IMO no refactoring is needed anymore. What do you think?

@@ -204,6 +204,10 @@ def associated_host(vm)
associate_by("ip", [vm.floating_ip_address, vm.private_ip_address].compact)
end

def associated_vm(host)
vms(:eager_loading => true).find { |vm| associate_by_host("ip", [vm.floating_ip_address, vm.private_ip_address].compact, host) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above in app/models/compute_resources/foreman/model/ec2.rb line 151, we have the same line without compact keyword. Is there a particular reason for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same query as in associated_host

@@ -457,6 +457,19 @@ 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) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this will behave - do we need/want eager loading here? I understand that we might not want to have a query for every single vm 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants