API POST /api/subnets domain_ids does not appear to create the subnet with the domain id

When I use the API for POST (to create a subnet) or PUT (to update a subnet), the domain seems not to be updated. Other fields are affected, as observed in the web application which displays the subnets.

The example below includes the result to STDOUT of running a ruby script using the API to update the vlanid (success) and the domain (seems not to be updated) for the given subnet. The corresponding log entry is included. Visual inspection of the foreman web application indicates the vlan id is updated for the subnet but the domain is not.

Expected outcome:
I expect to create or update a subnet with the specified domain (which does exist).
Foreman and Proxy versions:
Foreman and Proxy plugin versions:
foreman_setup v5.0.0
Other relevant data:
[e.g. logs from Foreman and/or the Proxy, modified templates, commands issued, etc]
(for logs, surround with three back-ticks to get proper formatting, e.g.)

2018-11-15 11:18:19 999a013a [app] [I] Started PUT "/api/subnets/18" for at 2018-11-15 11:18:19 -0500
2018-11-15 11:18:19 999a013a [app] [I] Processing by Api::V2::SubnetsController#update as JSON
2018-11-15 11:18:19 999a013a [app] [I]   Parameters: {"domain_ids"=>[9], "vlanid"=>"1105", "apiv"=>"v2", "id"=>"18", "subnet"=>{"vlanid"=>"1105"}}
2018-11-15 11:18:19 999a013a [app] [I] Authorized user foreman_api_admin(API Admin)
2018-11-15 11:18:19 999a013a [app] [I] Current user: foreman_api_admin (administrator)
2018-11-15 11:18:20 999a013a [app] [I]   Rendered api/v2/subnets/update.json.rabl (15.6ms)
2018-11-15 11:18:20 999a013a [app] [I] Completed 200 OK in 66ms (Views: 19.3ms | ActiveRecord: 7.4ms)
ruby test_put_subnet.rb
 "created_at"=>"2018-10-01 21:03:44 UTC",
 "updated_at"=>"2018-11-15 16:18:19 UTC",

Hello @kwalker17, did you tried to put the domain_ids in the subnet hash?

{“vlanid”=>“1105”, “apiv”=>“v2”, “id”=>“18”, “subnet”=>{“vlanid”=>“1105”, “domain_ids”=>[9]}}

Based on the API docs it is expected there. Check the docs at https://<your_host>/apidoc/v2/subnets/update.html


Hello @mbacovsky, thank you for your help! I totally missed that I needed to have the parameters in a subnet hash. I like that v1.19 API documentation includes examples of usage. Best regards!

1 Like