Bug #2989
closedid field missing in host_parameters of hosts. (API v1 and v2)
Description
Issue in Foreman 1.2.0
In Foreman 1.0 it was possible to update a hosts, host_parameter name or value by using its id in a put request.
host_parameter example after get request for an host in foreman 1.0: (full details in attachment foreman-1.0.txt)
"host": {
"name": "cjiblx3211.example.nl",
....
....
"host_parameters": [
{
"host_parameter": {
"created_at": "2013-02-22T10:01:15Z",
"id": 399,
"name": "c_omgeving",
"priority": 4,
"reference_id": 132,
"updated_at": "2013-02-22T10:01:15Z",
"value": "o999"
}
},
But with foreman 1.2 api (v1 and v2) we have less values and and no id is in the result. (full details in attachment foreman-1.2.0.txt)
"host": {
"name": "cjiblx3211.example.nl",
....
....
"host_parameters": [
{
"host_parameter": {
"name": "c_omgeving",
"value": "o999"
}
},
Because we now have no id field we tried to use the host_parameters name to update its value but it results in an error. (name already taken, if I remember well)
It seems the current api has no options available to update an host_parameter name or value with the api of foreman 1.2.
Files
Updated by Dominic Cleal over 11 years ago
- Category set to API
- Assignee set to Joseph Magen
In APIv2, there's a separate parameters controller which produces routes such as /hosts/example.com/parameters and appears to show both id, name and value. Might be worth exploring?
Updated by Ronny M over 11 years ago
Our foreman 1.2.0 has been upgraded twice. (1.0 => 1.1 => 1.2)
After some further testing I see that a fresh foreman 1.2 install does have the id and other fields if I ad a new parameter.
"host": {
"owner_type": "User",
"medium_id": 1,
"owner_id": 1,
"compute_resource_id": null,
"puppet_proxy_id": null,
"image_id": null,
"architecture_id": 1,
"host_parameters": [
{
"host_parameter": {
"reference_id": 1,
"priority": 4,
"created_at": "2013-08-29T18:04:55Z",
"value": "test",
"updated_at": "2013-08-29T18:04:55Z",
"name": "test",
"id": 1
}
}
],
Updated by Ronny M over 11 years ago
@Dominic, ok thanks ill try that with the v2 api.
Updated by Ronny M over 11 years ago
Oeps, Sorry
It seems the difference is caused by using /api or not in the url when using/calling the api
curl -H "Content-Type:application/json" -s -H "Accept:application/json" -k -u admin:changeme https://foreman/api/hosts/cjiblx3211 | prettify_json.rb
"host_parameter": {
"value": "o999",
"name": "c_omgeving"
}
curl -H "Content-Type:application/json" -s -H "Accept:application/json" -k -u admin:changeme https://foreman/hosts/cjiblx3211 | prettify_json.rb
"host_parameter": {
"value": "o999",
"name": "c_omgeving",
"id": 399,
"updated_at": "2013-02-22T10:01:15Z",
"reference_id": 132,
"created_at": "2013-02-22T10:01:15Z",
"priority": 4
}
Probably not a bug then. I assume it can be closed?
Updated by Ronny M over 11 years ago
Did some more testing:
The issue is not only the /api. Included Parameters via inheritance (or because of foreman 1.0 => 1.1 => 1.2 upgrade?) don't have the id and the other missing values.
As soon as I override an inherited parameter it will become an global host parameter and will then have the missing fields.
Updated by Ronny M over 11 years ago
After some more testing I think this one really can be closed.
Updated by Ronny M over 11 years ago
- File with-api.txt with-api.txt added
- File without-api.txt without-api.txt added
Apparently I haven't been reading well enough. I thought /api was deprecated but instead we now have to use /api. If this is true then I am missing the id's in de new api that I need along with other values.
with /api my result is 105 rows (atttachement: with-api.txt)
and without api only 60 rows (attachement: without-api.txt)
Updated by Ronny M over 11 years ago
Sorry mixed the numbers arround (with /api should be 60 en without api should be 105.)
Updated by Joseph Magen over 11 years ago
- Status changed from New to Ready For Testing
Ronny,
PR submitted https://github.com/theforeman/foreman/pull/863
There goal of API v1 under /api/ was to be the same response as you would get with no /api/. The response should now be the same for /api/hosts/:id and /hosts/:id. I also noticed that interfaces: [] was not included in /api/hosts but it was in /hosts so I also added that.
Also, as you found out that no /api is going away, here is the PR to remove the json response from no /api/ https://github.com/theforeman/foreman/pull/855
Updated by Joseph Magen over 11 years ago
The reason for the difference in results count is that /api/ uses pagination and without /api/ does not. If you page ?per_page=100000 in the URL, then it will show all the results in one call.
Updated by Ronny M over 11 years ago
Joseph,
Ok thanks,
I'll merge both pulls to my test environment and will test them then.
Afterwards I will update this ticket with the results.
Updated by Ronny M over 11 years ago
Joseph
Tested pull 863 on Foreman 1.2.1. There where still some parameters/values missing but probably for an reason.
To be sure the list of missing or extra parameters/values is shown bellow:
- no api (in no api but not in with api):
"host_id":1 # (under "interfaces")
"location_id":null
"organization_id":null
"last_compile":"2013-09-03T15:01:39Z"
"last_freshcheck":null
"serial":null
"source_file_id":null
"puppet_status":100663296
"root_pass":"xybxa6JUkz63w" # (Security reasons?)
- with api: (in with api but not in no api): # (The following is New/Extra so shouldn't be an issue)
- New/Extra
"interface": # (interface detail now listed under interface: instead interfaces:)
"sp_ip":"192.168.88.50"
"sp_mac":"00:00:00:00:00:01"
"sp_name":"bmc1"
"sp_subnet_id":1
"type":"Nic::BMC" or "type":"Nic::Managed"
- Listed twice (For obvious reasons, explained by you to domcleal (comment: didn't remove :attrs for the same reason above not to break any current API v1 consumers that we use :attrs.))
"username":"a"
"password":"b"
"provider":"IPMI"
Updated by Ronny M over 11 years ago
I hope the differences are not caused by the per_page option, but the following commands with different per_page values had the same result. So I might be doing something wrong.
curl -H "Content-Type:application/json" -s -H "Accept:application/json" -k -u admin:changeme https://foreman/api/hosts/foreman.localdomain?per_page=50 | prettify_json.rb | wc -l
97
curl -H "Content-Type:application/json" -s -H "Accept:application/json" -k -u admin:changeme https://foreman/api/hosts/foreman.localdomain?per_page=10000 | prettify_json.rb | wc -l
97
Updated by Ronny M over 11 years ago
For facts api/hosts/:id/facts the per_page option does work, but appears to do nothing with api/hosts/:id
Updated by Joseph Magen over 11 years ago
Ronny,
I updated the pull request per your comments. Thanks. I included all your comments except adding "host_id":1 # (under "interfaces") since it's redundant as the api call is on hosts/1
As you found out, the :per_page attribute only works on a collection of objects (ex. /facts, /hosts, etc). It does not work on a single object (ex. hosts/:id)
Updated by Dominic Cleal over 11 years ago
- Target version set to 1.3.0
Thanks for your feedback Ronny, much appreciated.
Updated by Joseph Magen over 11 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 06bcca2d025924085b11c2490737071586dc65d6.
Updated by Dominic Cleal over 11 years ago
Lukas Zapletal wrote:
Is this going into the 1.3?
It's already in.