Revision e83f4d7f
Added by Tom Caspy about 8 years ago
app/controllers/api/v2/hosts_controller.rb | ||
---|---|---|
params[:interfaces_attributes] = params[:interfaces_attributes].map do |nic_attr|
|
||
interface_attributes(nic_attr)
|
||
end
|
||
#if no primary interface set explicitly, set first one as primary
|
||
unless params[:interfaces_attributes].any?{|i| i[:primary]}
|
||
params[:interfaces_attributes].first[:primary] = true
|
||
end
|
||
end
|
||
params = host.apply_inherited_attributes(params) if host
|
||
params
|
test/functional/api/v2/hosts_controller_test.rb | ||
---|---|---|
assert_response :unprocessable_entity
|
||
end
|
||
|
||
test "when no primary interface is set, defaulting to first one" do
|
||
disable_orchestration
|
||
nics = nics_attrs
|
||
nics.each do |nic|
|
||
nic.delete(:primary)
|
||
end
|
||
post :create, { :host => basic_attrs.merge!(:interfaces_attributes => nics) }
|
||
|
||
assert_response :created
|
||
end
|
||
|
||
test 'when ":restrict_registered_smart_proxies" is false, HTTP requests should be able to import facts' do
|
||
User.current = users(:one) #use an unprivileged user, not apiadmin
|
||
Setting[:restrict_registered_smart_proxies] = false
|
Also available in: Unified diff
fixes #14239 - when creating host from API, set first interface as primary if none set
(cherry picked from commit 38d9333f8e82e45fc6771ea7740e6ea625b97d3f)