Project

General

Profile

Actions

Bug #2345

closed

Unable to update hostgroup parameter by REST API

Added by Axel Tischer about 11 years ago. Updated almost 11 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

When I try to update hostgroup parameters via REST API I get

Started PUT "/foreman/hostgroups/102/" for 10.129.59.20 at Wed Mar 20 09:43:51 +0100 2013
Processing by HostgroupsController#update as JSON
Parameters: {"id"=>"102", "hostgroup"=>{"ancestry"=>nil, "operatingsystem_id"=>nil, "id"=>102, "label"=>"apitest", "subnet_id"=>nil, "domain_id"=>nil, "parameters"=>{"apit_appl_v
ersion"=>"0.0.1", "apit_java_version"=>"1.7.1"}, "name"=>"apitest", "environment_id"=>4, "puppetclass_ids"=>nil}}
Operation FAILED: unknown attribute: parameters
Completed 500 Internal Server Error in 4ms


Files

change_foreman_group_param.rb change_foreman_group_param.rb 1.26 KB Stefan Held, 08/12/2013 10:45 AM
Actions #1

Updated by Dominic Cleal about 11 years ago

  • Project changed from Website to Foreman
Actions #2

Updated by Dominic Cleal about 11 years ago

  • Assignee set to Joseph Magen

Is this fixed in API v2, Joseph?

Actions #3

Updated by Axel Tischer about 11 years ago

Here is my script output:
u'operatingsystem_id': None, u'environment_id': 4, u'name': u'apitest', u'parameters': {u'apit_appl_version': u'0.0.1', u'apit_java_version': u'1.6.32'}, u'subnet_id': None, u'label': u'apitest', u'ancestry': None, u'id': 102, u'puppetclass_ids': [], u'domain_id': None}
  1. orig json object: {u'operatingsystem_id': None, u'environment_id': 4, u'name': u'apitest', u'parameters': {u'apit_appl_version': u'0.0.1', u'apit_java_version': u'1.6.32'}, u'subnet_id': None, u'label': u'apitest', u'ancestry': None, u'id': 102, u'puppetclass_ids': [], u'domain_id': None}
    PARAMETER -> {u'apit_appl_version': u'0.0.1', u'apit_java_version': u'1.6.32'} {"hostgroup": {"operatingsystem_id": null, "environment_id": 4, "name": "apitest", "parameters": {"apit_appl_version": "0.0.1", "apit_java_version": "1.7.1"}, "subnet_id": null, "label": "apitest", "ancestry": null, "id": 102, "puppetclass_ids": [], "domain_id": null}}
  1. updated: <!DOCTYPE html>
    <html>
    <head>
    <title>We're sorry, but something went wrong (500)</title>
    <style type="text/css">
    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
    div.dialog {
    width: 25em;
    padding: 0 4em;
    margin: 4em auto 0 auto;
    border: 1px solid #ccc;
    border-right-color: #999;
    border-bottom-color: #999;
    }
    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
    </style>
    </head>

<body>

<div class="dialog">
<h1>We're sorry, but something went wrong.</h1>
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
</div>
</body>
</html>

Actions #4

Updated by Axel Tischer about 11 years ago

I'm using foreman 1.1

Actions #5

Updated by Axel Tischer about 11 years ago

I've also tried with API V2:

Started PUT "/foreman/hostgroups/102/" for 10.129.13.70 at Mon Mar 25 09:20:45 +0100 2013
Processing by HostgroupsController#update as JSON
Parameters: {"id"=>"102", "hostgroup"=>{"id"=>102, "operatingsystem_id"=>nil, "parameters"=>{"apit_java_version"=>"1.7.1", "apit_appl_version"=>"0.0.1"}, "label"=>"apite
st", "puppetclass_ids"=>nil, "name"=>"apitest", "environment_id"=>4,
"subnet_id"=>nil, "domain_id"=>nil, "ancestry"=>nil}}
Operation FAILED: unknown attribute: parameters
Completed 500 Internal Server Error in 12ms

ArgumentError (There was no default layout for HostgroupsController in [#<ActionView::FileSystemResolver:0x7f14081e1b08 @caching=true, @path="/srv/foreman/foreman/app/view
s", @cached={#<ActionView::LookupContext::DetailsKey:0x7f14049a6630 @hash=69861976650520>=>{"layouts"=>{"hostgroups"=>{false=>[]}, "application"=>{false=>[]}}, "layouts/ac
tion_controller"=>{"base"=>{false=>[]}}}, #<ActionView::LookupContext::DetailsKey:0x7f140451c8d0 @hash=69861974271080>=>{"home"=>{"settings"=>{true=>[app/views/home/_setti
ngs.html.erb]}, "topbar"=>{true=>[app/views/home/_topbar.rhtml]}}, "layouts"=>{"application"=>{false=>[app/views/layouts/application.html.erb]}, "dashboard"=>{false=>[]}},
"bookmarks"=>{"list"=>{true=>[app/views/bookmarks/_list.html.erb]}}, "common"=>{"searchbar"=>{true=>[app/views/common/_searchbar.erb]}}, "dashboard"=>{"index"=>{false=>[a
pp/views/dashboard/index.html.erb]}}}}>, #<ActionView::FileSystemResolver:0x7f14081f24a8 @caching=true, @path="/usr/lib64/ruby/gems/1.8/gems/apipie-rails-0.0.16/app/views"
, @cached={#<ActionView::LookupContext::DetailsKey:0x7f14049a6630 @hash=69861976650520>=>{"layouts"=>{"hostgroups"=>{false=>[]}, "application"=>{false=>[]}}, "layouts/acti
on_controller"=>{"base"=>{false=>[]}}}, #<ActionView::LookupContext::DetailsKey:0x7f140451c8d0 @hash=69861974271080>=>{"layouts"=>{"dashboard"=>{false=>[]}}}}>]):
app/controllers/application_controller.rb:291:in `generic_exception'

Actions #6

Updated by Ohad Levy about 11 years ago

  • Status changed from New to Resolved

right, thats a limitation of the current v1 api, have a look for a few examples (or wait for V2 of the api in 1.2).

https://github.com/ohadlevy/foreman-api-examples/blob/master/examples/add_paramater_to_existing_host.rb

Actions #7

Updated by Axel Tischer almost 11 years ago

Hi there

I still get the problem when trying to update hte hostgroup:

Foreman Version Version 1.2.0 © 2009-2013 Paul Kelly and Ohad Levy

curl http://myhost.myddomain/foreman/api/hostgroups/102?format=json {"hostgroup":{"operatingsystem_id":null,"subnet_id":null,"label":"apitest","puppetclass_ids":[],"environment_id":4,"ancestry":null,"name":"apitest","id":102,"parameters":{"apit_java_version":"1.9.9","apit_appl_version":"0.0.1"},"domain_id":null}}[

curl -X POST -H "Content-Type: application/json;version=2" -d '{"hostgroup":{"id":102,"ancestry":null,"puppetclass_ids":[],"sest","domain_id":null,"label":"apitest","parameters":{"apit_appl_version":"102","apit_java_version":"1.9.9"},"environment_id":4}}' http://myhost.mydomain/foreman/api/hostgroups {"error":{"message":"unknown attribute: parameters"}}

The exampe from Ohad is incorrect, parameters in hostgroups do not have an id.

Any idea ?

Regards
Axel

Actions #8

Updated by Axel Tischer almost 11 years ago

Me again

I changed my RESTClient to use PUT instead of POST. Now I get HTTP 200 and OK but nothing changed

Actions #9

Updated by Axel Tischer almost 11 years ago

Hi

I thried with curl and PUT again:

curl -X PUT -H "Content-Type: application/json;version=2" -d '{"hostgroup":{"id":102,"ancestry":null,"puppetclass_ids":[],"subnet_id":null,"operatingsystem_id":null,"name":"apitest","domain_id":null,"label":"apitest","parameters":{"apit_appl_version":"102","apit_java_version":"1.9.9"},"environment_id":4}}' http://dezulititt25.emea.porsche.biz/foreman/api/hostgroups/102/

{"error":{"message":"unknown attribute: parameters"}}

Logentry:
Processing by Api::V1::HostgroupsController#update as JSON
Parameters: {"hostgroup"=>{"parameters"=>{"apit_java_version"=>"1.9.9", "apit_appl_version"=>"102"}, "name"=>"apitest", "puppetclass_ids"=>nil, "environment_id"=>4, "subnet
_id"=>nil, "id"=>102, "domain_id"=>nil, "operatingsystem_id"=>nil, "label"=>"apitest", "ancestry"=>nil}, "id"=>"102"}
unknown attribute: parameters (ActiveRecord::UnknownAttributeError)

Actions #10

Updated by Axel Tischer almost 11 years ago

Got it !

Here my Howto:

First get the ID of the hostgroup:
curl -X GET -H "Content-Type:application/json" -H "Accept: application/json" http://myhost/foreman/api/hostgroups/apitest
Returns: {"hostgroup":{"operatingsystem_id":null,"subnet_id":null,"label":"apitest","puppetclass_ids":[],"environment_id":4,"ancestry":null,"name":"apitest",*"id":102*,"parameters":{"apit_java_version":"Blubb","apit_appl_version":"Huustegudsje"},"domain_id":null}}

Next get all parameters of hostgroup:
curl -X GET -H "Accept: application/json;version=2" -H "Content-type: application/json" http://myhost/foreman/api/hostgroups/102/parameters?format=json

{"parameters":[{"parameter":{"value":"Blubb","name":"apit_java_version","id":4529}},{"parameter":{"value":"Huustegudsje","name":"apit_appl_version","id":4530}}]}

That's what we need: the ID of the parameter

Now send back the modified parameter:
curl -X PUT -H "Accept: application/json,version=2" -H "Content-Type: application/json" -d '{"parameter":{"id":4530,"name":"apit_appl_version","value":"CHANGED !!!!"}}' http://myhost/foreman/api/hostgroups/102/parameters/*4530*?format=json

{"parameter":{"value":"CHANGED !!!!","name":"apit_appl_version","id":4530}}

You can omit the id in the json object.
curl -X PUT -H "Accept: application/json,version=2" -H "Content-Type: application/json" -d '{"parameter":{"name":"apit_appl_version","value":"CHANGED again!!!!"}}' http://myhost/foreman/api/hostgroups/102/parameters/4530?format=json

Cheers
Axel
& many thanx to Stefan

Actions #11

Updated by Stefan Held almost 11 years ago

If someone is interested, i attach a ruby example for this.

The script expects three variables if you run it.

1.) group the host belongs to
2.) parameter name
3.) the value you want to become permanent.

Actions

Also available in: Atom PDF