Bug #14239
Creating a host via API fails with cryptic error when no primary interface is set explicitly
Description
when running
bundle exec bin/hammer host create --hostgroup=abcde --compute-resource='abcde ovirt' --name inecas-test-1 --location Default_Location \ --organization Default_Organization1 --interface='compute_name=eth0,compute_network=d3e5f222-1ece-4d77-bc18-98b0937e72bf'
which causes this params to be sent to the API host controller:
{"host"=>{"name"=>"inecas-test-1", "location_id"=>2, "organization_id"=>1, "compute_resource_id"=>3, "hostgroup_id"=>3, "build"=>true, "enabled"=>true, "managed"=>true, "compute_attributes"=>{"volumes_attributes"=>{}}, "overwrite"=>true, "host_parameters_attributes"=>{}, "interfaces_attributes"=>[{"compute_attributes"=>{"name"=>"eth0", "network"=>"d3e5f222-1ece-4d77-bc18-98b0937e72bf"}}]}, "apiv"=>"v2"}
Ends up with error `Failed to create a compute abcde ovirt (oVirt) instance inecas-test-1.inecas.ovirt.test: Network not found in cluster`
After debugging, it turns out the host is created with two interfaces, one corresponding to the params from the UI, while another one is build
by default https://github.com/theforeman/foreman/blob/1.11.0-RC2/app/models/host/base.rb#L104
A workaround is to set `primary=true` as interface like this:
bundle exec bin/hammer host create --hostgroup=abcde --compute-resource='abcde ovirt' --name inecas-test-1 --location Default_Location \ --organization Default_Organization1 --interface='compute_name=eth0,compute_network=d3e5f222-1ece-4d77-bc18-98b0937e72bf,primary=true'
Expected result:
When no primary interface is set, the first one is considered as the one (consistent with the UI)
Related issues
Associated revisions
fixes #14239 - when creating host from API, set first interface as primary if none set
(cherry picked from commit 38d9333f8e82e45fc6771ea7740e6ea625b97d3f)
History
#1
Updated by Ivan Necas almost 7 years ago
- Description updated (diff)
#2
Updated by The Foreman Bot almost 7 years ago
- Status changed from New to Ready For Testing
- Assignee set to Tom Caspy
- Pull request https://github.com/theforeman/foreman/pull/3339 added
#3
Updated by Dominic Cleal almost 7 years ago
- Has duplicate Bug #13982: API description for creating hosts incorrectly lists "interfaces_attributes"'s "primary" as optional added
#4
Updated by Tom Caspy almost 7 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 38d9333f8e82e45fc6771ea7740e6ea625b97d3f.
#5
Updated by Dominic Cleal almost 7 years ago
- Legacy Backlogs Release (now unused) set to 141
#6
Updated by Dominic Cleal almost 7 years ago
- Related to Bug #14264: Getting 500 when creating host through API and not specifying any interface attributes added
#7
Updated by Dominic Cleal almost 7 years ago
- Related to Bug #13927: Specifying provision and primary flags should not be mandatory added
fixes #14239 - when creating host from API, set first interface as primary if none set