Project

General

Profile

Actions

Bug #1370

closed

creating a machine always sets "owner = user"

Added by Jan van Eldik over 12 years ago. Updated over 12 years ago.

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

Description

When creating a machine through the API, it seems the ownership is always
set to user issues the request, even though owner_id does not correspond
to this user.

In other words, when I use my "jveldik" account to register a new
machine in Foreman, and I specify "owner_id = 1" to set ownership to
the "admin" account, Foreman sets it to "jveldik" (owner_id = 6).

From the Foreman log file:

Processing HostsController#create (for 128.141.28.9 at 2011-12-05 16:40:46) [POST]
Parameters: {"action"=>"create", "controller"=>"hosts", "host"=>{"subnet_id"=>"1", "name"=>"janvm01", "architecture_id"=>"1", "mac"=>"00:15:5D:FF:48:A7", "domain_id"=>"1", "owner_id"=>"1", "hostgroup_id"=>"3", "ptable_id"=>"1", "sp_subnet_id"=>"1", "ip"=>"128.142.194.47", "environment_id"=>"16", "model_id"=>"4", "operatingsystem_id"=>"3"}}

From https://foreman.mydomain.org/hosts/janvm01.mydomain.org?format=json

{"host":{"subnet_id":1,"serial":null,"puppetproxy_id":null,"name":"janvm01.mydomain.org","managed":true,"last_report":null,"comment":null,"architecture_id":1,"created_at":"2011-12-05T15:43:47Z","sp_mac":"","puppetmaster_name":"foreman.mydomain.org","image_file":null,"updated_at":"2011-12-05T15:43:47Z","sp_name":"","mac":"00:15:5d:ff:48:a7","installed_at":null,"domain_id":1,"use_image":null,"root_pass":"XXXXXXXXXXXXXXXXXXXXX","owner_id":6,"medium_id":6,"id":248,"hostgroup_id":3,"enabled":true,"build":false,"ptable_id":1,"sp_subnet_id":1,"puppet_status":0,"last_freshcheck":null,"ip":"128.142.194.47","environment_id":16,"source_file_id":null,"model_id":4,"environment":{"environment":{"name":"production","id":16}},"sp_ip":"","disk":null,"owner_type":"User","operatingsystem_id":3,"last_compile":null}}

100% reproducible.

cheers, Jan
Actions #1

Updated by Ohad Levy over 12 years ago

looking at the code i find it strange, and it might be related to the fact that owner is a polymorphic relationship.

can you try changing the line (around 153 in my code) from

self.owner ||= User.current

to

self.owner ||= User.current if owner_id.blank?
Actions #2

Updated by Ohad Levy over 12 years ago

  • Status changed from New to Resolved

since owner is a polymorphic attribute, i think you need to pass the owner_type as well in your API call.

Ohad

Actions #3

Updated by Jan van Eldik over 12 years ago

Hi Ohad,

OK, I will try adding the owner_type. But what should it be?
How can I find out the available types?

thanks, Jan
Actions #4

Updated by Jan van Eldik over 12 years ago

Hi,

Indeed, with "owner_type = User" the problem goes away, thanks for
the hint!

Are the owner_types enumerated somewhere?

Actions

Also available in: Atom PDF