Hi Ivan,
For Katello, we have a need to add attributes to the Foreman hostgroups
controller and have those attributes added as part of the apipie
documentation/bindings. For example, content_source_id, content_view_id
and lifecyle_environment_id.
I have tried a few different things, but have not had any luck. Can you
advise on what the proper way is to accomplish this?
The following are a couple of scenarios that I tried, but neither works:
file:
katello/app/controllers/katello/concerns/api/v2/hostgroups_controller_extensions.rb
Code scenario 1:
···
---------------------- Issue: The attributes appear to get added to the apipie resource; however, this approach overwrites the create/update on the base controller, but we only want to add attributes to the interface and allow the base controller to be called.module Katello
module Concerns
module Api::V2::HostgroupsControllerExtensions
extend ActiveSupport::Concern
included do
def_param_group :hostgroup_modified do
param :hostgroup, Hash, :required => true, :action_aware =>
true do
param :name, String, :required => true
param :parent_id, :number
param :environment_id, :number
param :operatingsystem_id, :number
param :architecture_id, :number
param :medium_id, :number
param :ptable_id, :number
param :puppet_ca_proxy_id, :number
param :subnet_id, :number
param :domain_id, :number
param :realm_id, :number
param :puppet_proxy_id, :number
param :content_source_id, :number
param :content_view_id, :number
param :lifecycle_environment_id, :number
param_group :taxonomies, ::Api::V2::BaseController
end
end
api :POST, "/hostgroups/", N_("Create a host group")
param_group :hostgroup_modified, :as => :create
def create
super
end
api :PUT, "/hostgroups/:id/", N_("Update a host group")
param :id, :identifier, :required => true
param_group :hostgroup_modified
def update
super
end
end
end
end
end
Code scenario 2:
Issue: The apipie resource does not seem to recognize/list the
additional attributes for the create/update actions.
module Katello
module Concerns
module Api::V2::HostgroupsControllerExtensions
extend ActiveSupport::Concern
included do
alias_method_chain :create, :katello_attributes
alias_method_chain :update, :katello_attributes
def_param_group :hostgroup_modified do
param :hostgroup, Hash, :required => true, :action_aware =>
true do
param :name, String, :required => true
param :parent_id, :number
param :environment_id, :number
param :operatingsystem_id, :number
param :architecture_id, :number
param :medium_id, :number
param :ptable_id, :number
param :puppet_ca_proxy_id, :number
param :subnet_id, :number
param :domain_id, :number
param :realm_id, :number
param :puppet_proxy_id, :number
param :content_source_id, :number
param :content_view_id, :number
param :lifecycle_environment_id, :number
param_group :taxonomies, ::Api::V2::BaseController
end
end
api :POST, "/hostgroups/", N_("Create a host group")
param_group :hostgroup_modified, :as => :create
api :PUT, "/hostgroups/:id/", N_("Update a host group")
param :id, :identifier, :required => true
param_group :hostgroup_modified
end
def create_with_katello_attributes
super
end
def update_with_katello_attributes
super
end
end
end
end
thanks in advance,
Brad