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

Problem:
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:
1.15.6
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 172.25.50.117 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
{"network"=>"172.26.0.0",
 "network_type"=>"IPv4",
 "cidr"=>24,
 "mask"=>"255.255.255.0",
 "priority"=>nil,
 "vlanid"=>"1105",
 "gateway"=>"172.26.0.1",
 "dns_primary"=>"172.26.0.2",
 "dns_secondary"=>"172.26.0.3",
 "from"=>nil,
 "to"=>nil,
 "created_at"=>"2018-10-01 21:03:44 UTC",
 "updated_at"=>"2018-11-15 16:18:19 UTC",
 "ipam"=>"None",
 "boot_mode"=>"DHCP",
 "id"=>18,
 "name"=>"fake-subnet-mgmt",
 "network_address"=>"172.26.0.0/24",
 "dhcp_id"=>nil,
 "dhcp_name"=>nil,
 "tftp_id"=>10,
 "tftp_name"=>"foo.example.com",
 "dns_id"=>nil,
 "dhcp"=>nil,
 "tftp"=>
  {"name"=>"foo.example.com",
   "id"=>10,
   "url"=>"http://foo.example.com:9090"},
 "dns"=>nil,
 "domains"=>[],
 "interfaces"=>[],
 "parameters"=>[]}

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

HTH

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