RFC: Disable 'Build' button if host is on and provision method is bootdisk

Problem Statement

Rebuilding a host is not always possible when the host is powered on, particularly when using the bootdisk provisioning method.

A concrete example is VMware vSphere:

  • When a VM is running, the bootdisk ISO cannot be attached.

  • This limitation prevents the rebuild process from completing successfully.

Currently, foreman_bootdisk attempts to work around this by automatically restarting the host during ISO attachment. However:

  • This restart happens without explicit user warning.

  • This behavior differs from image-based or network-based provisioning, where no implicit reboot is triggered.

  • The resulting experience is inconsistent and potentially disruptive.

  • Sometimes, it still fails because of timing when the “Build” button is pressed.

Proposal

Disable the “Build” button in the UI when:

  • The host is powered on, and

  • The selected provisioning method is bootdisk.

This would:

  • Prevent users from initiating a rebuild that is likely to fail.

  • Avoid unexpected automatic restarts.

  • Make the system’s constraints more transparent and predictable.

Motivation

The goal is not to restrict functionality, but to improve usability and consistency. By preventing an invalid or disruptive workflow at the UI level, we can:

  • Reduce user confusion.

  • Avoid unintended downtime.

PRs:

In the old UI when rebuilding a host on a compute resource a checkbox was shown asking for a reboot. I would personally prefer such a behavior if possible as the user will get a concrete warning when trying to use the functionality and can still use it if wanted by checking the box for the additional action. Otherwise he would need to understand why it is not enabled and in which cases it is possible to do a rebuild which gets even more confusing if in a bigger environment you have different ways of provisioning with different restrictions.

This doesn’t solve the issue, unfortunately. Attaching the ISO image often did not work because the request was blocked on vmware.

So, the request to start the “Build” did already fail. Some time ago, a change in foreman_bootdisk tried to solve the issue by stopping the host first and then attach the iso and then start the host again. From UX this would mean, that the host is suddenly gone.

My proposal is, to disable the “Build” button on the Host Details page and add a description that the host needs to be turned off first to set the host in “Build” mode.

1 Like

Just an impression, how it may look like:

This host is running (= powered on) and was provisioned with bootdisk.

Other thoughts?

Like @Dirk said, Foreman has an option to reboot the host when entering build mode:

It may be that the new UI hasn’t ported this over, but it should be possible for the user to show the intent to act now. Though I’m quite sure the orchestration probably never sees this.

IMHO we’re running into limitations of our current orchestration model which is using ActiveRecord hooks instead of proper tasks.

What about the API? I’d like to see the API respond with a clear error first. For example, return HTTP 422 when the above conditions are met and inhibit the whole save.

IIRC the new UI uses the API to perform that action so that should help when the UI is out of sync with the real power status. For example, when the user turned off the VM and someone/something else turned it on without refreshing the Foreman UI page.

That doesn’t block your proposal though it lessens the need for it.

Thanks @ekohl for your suggestion.

API-first make sense. I added it to Fixes #39067 - rebuild only if host powered off by sbernhard ¡ Pull Request #10860 ¡ theforeman/foreman ¡ GitHub (including 2 tests)