Bug #32501
openUsers should not have to pass image_id as part of compute_attributes when creating a host via API
Description
When doing POST /api/hosts
, one can pass the image_id
to the controller (see https://theforeman.org/api/2.4/apidoc/v2/hosts/create.html) and a user would expect that this image is used when one passes provision_method = image
But the actual deployment code looks at compute_attributes[image_id]
instead: https://github.com/theforeman/foreman/blob/2b5ff89b21f797c37ca2bd73c941ce3dc677de03/app/models/concerns/orchestration/compute.rb#L240-L262
def find_image return nil if compute_attributes.nil? image_uuid = compute_attributes[:image_id] || compute_attributes[:image_ref] return nil if image_uuid.blank? Image.find_by(:uuid => image_uuid, :compute_resource_id => compute_resource_id) end def validate_compute_provisioning return true if compute_attributes.nil? if image_build? return true if (compute_attributes[:image_id] || compute_attributes[:image_ref]).blank? img = find_image if img self.image = img else failure(_("Selected image does not belong to %s") % compute_resource) false end else # don't send the image information to the compute resource unless using the image provisioning method [:image_id, :image_ref].each { |image_key| compute_attributes.delete(image_key) } end end
Even worse, the image id it expects is actually the image uuid which is something completely different.
This is super confusing for users and results in API clients (hammer, Ansible) needing custom code to find the UUID and inject it in the right place.
This seems backwards, as we can just deduce all this from the actual image id the user (could) provide.