Foreman_discovery and BMC credentials

Hi,

lately at work I’ve been working on patching an annoyance for one of the admins who is using foreman with foreman_discovery; its about automatically populating credentials for BMC interfaces. I managed to achieve working solution for discovered hosts (at the step of provisioning; I just added a few lines in HostConverter Populate default BMC credentials · Marahin/foreman_discovery@2c39e1b · GitHub) however, for manually Creating Hosts its a bit more complicated. In the creation form, there’s a request going out when I change the interface to BMC, and I assume that it gets default values and constructs the interface. It hits the app/controllers/interfaces_controller.rb#new, and I already checked, there is access to some of the host params (e.g. there’s access to host parameters defined by location), however, even though Host Group is selected in the first step of the creation form, the parameters it should provide aren’t visible in the InterfacesController#new action.

My assumption is that probably the form isn’t including the host group information with the request, but I don’t have enough understanding of both admin processes nor foreman project to determine that.

I was hoping someone could point me in the right direction on where to look and how to provide the change so eventually it would be of enough quality to make it to the upstream.

Thanks!

1 Like

Hello and welcome to the community.

This is a long-standing pain of discovery plugin. See, it was architected in a way that you usually want to provision hosts with the same NIC configuration as it was discovered. And that is totally not always the case. One of our highest-voted feature on the issue tracker is ability to configure NICs automatically when you assign a hostgroup. Initial idea was ability to have a “script” (ERB/Ruby?) that would configure NICs as needed using reported facts as the datasource.

There is some support in discovery for detecting BMC interfaces from IPMI facts, however, I don’t regularly use or test this feature and chances are it even might be broken:

Yeah, discovery plugin is kind of a hack - it monkey patches host edit form a bit and converts discovered host to managed host prior rendering the page. It is not great and for this reason, it only works if you don’t want to do NIC changes.

Well, discovery needs rearchitecting. Today, discovered host is STI of host model and it is reusing some features like fact parsing or edit host form. I think discovered host should have been a separate entity with facts stored separately etc. But these changes are huge.

We have a new plugin Foreman Webhooks which allows users to subscribe to events and get webservices or shellscript called. This is a new plugin. Perhaps if we create new event when host is discovered, then you could create a webhook that would perform discovery provisioning via API/CLI with all required changes. That should be easy to do and you could do anything with discovered hosts in your webservice or script. Should not be a big change too.

2 Likes