Foreman REST API - Unable to update hostgroup

Hi Ohad

this messages is gone but no data will be changed

Processing HostgroupsController#update (for 10.129.59.53 at 2013-01-09
16:06:48) [PUT]
Parameters: {"id"=>"102", "controller"=>"hostgroups", "action"=>"update",
"_json"=>"name=apitest&parameters=apit_appl_version&parameters=apit_java_version&environment=id&enviro
nment=name&label=apitest&hypervisor_id=&id=102"}
Completed in 21ms (View: 6, DB: 5) | 200 OK
[https://puppet.emea.porsche.biz/foreman/hostgroups/102/]

I got a respone HTTP/1.1 200 OK but nothing is changed

{"hostgroup":{"vcpu":null,"memory":null,"environment":{"id":4,"name":"development"},"hypervisor_id":"","parameters":{"apit_appl_version":"0.0.1","apit_java_version":"1.6.31"},"subnet_id":null,"id":102,"disk_size":null,"operatingsystem_id":null,"network_type":null,"classes":[],"domain_id":null,"interface":null,"label":"apitest","name":"apitest","storage_pool":null}}

I expect "apit_java_version":"1.7.31"

The json object looks like

{'hostgroup':
{'parameters':
{'apit_appl_version': u'0.0.1',
'apit_java_version': '1.7.1'
}
}
}

I also tried with the full hostgroup object but got the same result.
Due to I do not have any error messages in the look, I feel blind… :frowning:

··· Am Mittwoch, 9. Januar 2013 12:51:30 UTC+1 schrieb axelt: > > Hi > > I'm trying to update a hostgroup via curl, it looks like the auth > parameter are not read by foreman. I tried same with python requests and > got the same error. > > Any hint ? > > Regards > Axel > > curl -v -k -H "Content-Type: application/json" -X PUT --data @test.json -u > myuser:mypasswd -L https://puppet.mydomain.net/foreman/hostgroups/102/ > > curl ended up with > Maximum (50) redirects followed > > foreman log tells me: > > Processing HostgroupsController#update (for 10.129.59.53 at 2013-01-09 > 12:46:49) [PUT] > Parameters: {"id"=>"102", "controller"=>"hostgroups", > "action"=>"update", > "hostgroup"=>{"parameters"=>{"apit_java_version"=>"1.7.1", " > apit_appl_version"=>"u'0.0.1'"}}} > Redirected to https://puppet.mydomain.net/foreman/users/login > Filter chain halted as [:require_login] rendered_or_redirected. > Completed in 3ms (DB: 1) | 302 Found [ > https://puppet.mydomain.net/foreman/hostgroups/102/] > > Processing UsersController#update (for 10.129.59.53 at 2013-01-09 > 12:46:37) [PUT] > Parameters: {"id"=>"login", "controller"=>"users", "action"=>"update"} > Redirected to https://puppet.mydomain.net/foreman/users/login > Filter chain halted as [:require_login] rendered_or_redirected. > Completed in 2ms (DB: 1) | 302 Found [ > https://puppet.mydomain.net/foreman/users/login] > ...... > > > >

Looking at how rails parse your request seems wrong

Processing HostgroupsController#update (for 10.129.59.53 at 2013-01-09
> 16:06:48) [PUT]
> Parameters: {"id"=>"102", "controller"=>"hostgroups",
> "action"=>"update",
> "_json"=>"name=apitest&parameters=apit_appl_version&parameters=apit_java_version&environment=id&enviro
> nment=name&label=apitest&hypervisor_id=&id=102"}
> Completed in 21ms (View: 6, DB: 5) | 200 OK [
> https://puppet.emea.porsche.biz/foreman/hostgroups/102/]
>

it looks like you send a _json variable with json, instead of accepting it
into the hostgroups hash.

my guess your json format is wrong, how about takign the existing json
response and keep only the values you need and send it back?

Ohad

··· On Wed, Jan 9, 2013 at 5:19 PM, axelt wrote:

Hi Ohad

You're right.

I modified the original json object and now I face

Processing HostgroupsController#update (for 10.129.59.53 at 2013-01-10
08:21:26) [PUT]
Parameters: {"id"=>"102", "controller"=>"hostgroups", "action"=>"update",
"hostgroup"=>{"disk_size"=>nil, "memory"=>nil, "id"=>102, "interface"=>nil,
"classes"=>[], "subnet_id"
=>nil, "environment"=>{"id"=>4, "name"=>"development"},
"parameters"=>{"apit_java_version"=>"1.7.1", "apit_appl_version"=>"0.0.1"},
"operatingsystem_id"=>nil, "label"=>"apitest",
"network_type"=>nil, "hypervisor_id"=>"", "domain_id"=>nil,
"storage_pool"=>nil, "vcpu"=>nil, "name"=>"apitest"}}
unknown attribute: parameters
/srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2918:in
assign_attributes' /srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2914:ineach'
/srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2914:in
assign_attributes' /srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2787:inattributes='
/srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2671:in
update_attributes_inside_transaction' /srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:229:insend'
/srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in
with_transaction_returning_status' /srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:intransaction'
/srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in
transaction' /srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:228:inwith_transaction_returning_status'
/srv/puppet/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2667:in
update_attributes' /srv/puppet/foreman/app/controllers/hostgroups_controller.rb:72:inupdate'
Rendering template within layouts/application

The original json object ( python json object) is

orig json object: {u'operatingsystem_id': None, u'disk_size': None,

u'name': u'apitest', u'parameters': {u'apit_appl_version': u'0.0.1',
u'apit_java_version': u'1.6.31'}, u'vcpu': None, u'network_type': None,
u'environment': {u'id': 4, u'name': u'development'}, u'subnet_id': None,
u'classes': [], u'storage_pool': None, u'domain_id': None, u'memory': None,
u'interface': None, u'label': u'apitest', u'hypervisor_id': u'', u'id': 102}

parameters should be a valid attribute…

··· Am Mittwoch, 9. Januar 2013 16:25:45 UTC+1 schrieb ohad: > > > > On Wed, Jan 9, 2013 at 5:19 PM, axelt <axel.t...@t-online.de > > wrote: > > Looking at how rails parse your request seems wrong > > Processing HostgroupsController#update (for 10.129.59.53 at 2013-01-09 >> 16:06:48) [PUT] >> Parameters: {"id"=>"102", "controller"=>"hostgroups", >> "action"=>"update", >> "_json"=>"name=apitest&parameters=apit_appl_version&parameters=apit_java_version&environment=id&enviro >> nment=name&label=apitest&hypervisor_id=&id=102"} >> Completed in 21ms (View: 6, DB: 5) | 200 OK [ >> https://puppet.emea.porsche.biz/foreman/hostgroups/102/] >> > > it looks like you send a _json variable with json, instead of accepting it > into the hostgroups hash. > > my guess your json format is wrong, how about takign the existing json > response and keep only the values you need and send it back? > > Ohad >