Class: Katello::Api::V2::HostSubscriptionsController
- Inherits:
-
ApiController
- Object
- Api::V2::BaseController
- ApiController
- Katello::Api::V2::HostSubscriptionsController
show all
- Includes:
- Concerns::Api::V2::ContentOverridesController
- Defined in:
- app/controllers/katello/api/v2/host_subscriptions_controller.rb
Instance Method Summary
collapse
#check_katello_agent_not_disabled, #deprecate_katello_agent, #empty_search_query?, #full_result_response, #katello_agent_removal_release, #resource_class, #scoped_search, #skip_session
Methods included from Rendering
#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template
#api_version
Instance Method Details
#add_subscriptions ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 138
def add_subscriptions
if @host.organization.simple_content_access?
fail ::Katello::HttpErrors::BadRequest, _("This host's organization is in Simple Content Access mode. Attaching subscriptions is disabled.")
end
pools_with_quantities = params.require(:subscriptions).map do |sub_params|
PoolWithQuantities.new(Pool.with_identifier(sub_params['id']), sub_params['quantity'].to_i)
end
sync_task(::Actions::Katello::Host::AttachSubscriptions, @host, pools_with_quantities)
respond_for_index(:collection => index_response(reload_host: true), :template => "index")
end
|
#auto_attach ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 52
def auto_attach
if @host.organization.simple_content_access?
fail ::Katello::HttpErrors::BadRequest, _("This host's organization is in Simple Content Access mode. Auto-attach is disabled")
end
sync_task(::Actions::Katello::Host::AutoAttachSubscriptions, @host)
respond_for_index(:collection => index_response(reload_host: true), :template => "index")
end
|
#available_release_versions ⇒ Object
185
186
187
188
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 185
def available_release_versions
releases = @host.content_facet.try(:available_releases) || []
respond_for_index :collection => full_result_response(releases)
end
|
#content_override ⇒ Object
175
176
177
178
179
180
181
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 175
def content_override
content_override_values = @content_overrides.map do |override_params|
validate_content_overrides_enabled(override_params)
end
sync_task(::Actions::Katello::Host::UpdateContentOverrides, @host, content_override_values, false)
fetch_product_content
end
|
#create ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 81
def create
rhsm_params = params_to_rhsm_params
host = Katello::RegistrationManager.process_registration(rhsm_params, @content_view_environment)
host.reload
::Katello::Host::SubscriptionFacet.update_facts(host, rhsm_params[:facts]) unless rhsm_params[:facts].blank?
respond_for_show(:resource => host, :template => '../../../api/v2/hosts/show')
end
|
#destroy ⇒ Object
63
64
65
66
67
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 63
def destroy
Katello::RegistrationManager.unregister_host(@host, :unregistering => true)
@host.reload
respond_for_destroy(:resource => @host)
end
|
#enabled_repositories ⇒ Object
192
193
194
195
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 192
def enabled_repositories
repositories = @host.content_facet.try(:bound_repositories) || []
respond_with_template_collection "index", 'repositories', :collection => full_result_response(repositories)
end
|
#index ⇒ Object
38
39
40
41
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 38
def index
@collection = index_response
respond_for_index :collection => @collection
end
|
#index_response(reload_host: false) ⇒ Object
43
44
45
46
47
48
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 43
def index_response(reload_host: false)
@host.reload if reload_host
presenter = ::Katello::HostSubscriptionsPresenter.new(@host)
full_result_response(presenter.subscriptions)
end
|
#params_to_rhsm_params ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 91
def params_to_rhsm_params
rhsm_params = params.slice(:facts, :uuid, :name).to_unsafe_h
rhsm_params[:releaseVer] = params['release_version'] if params['release_version']
rhsm_params[:usage] = params['purpose_usage'] if params['purpose_usage']
rhsm_params[:role] = params['purpose_role'] if params['purpose_role']
rhsm_params[:addOns] = params['purpose_addons'] if params['purpose_addons']
rhsm_params[:serviceLevel] = params['service_level'] if params['service_level']
rhsm_params[:guestIds] = params['hypervisor_guest_uuids'] if params[:hypervisor_guest_uuids]
rhsm_params[:type] = Katello::Candlepin::Consumer::SYSTEM
rhsm_params[:facts] ||= {}
rhsm_params[:facts]['network.hostname'] ||= rhsm_params[:name]
if params['installed_products']
rhsm_params[:installedProducts] = params['installed_products'].map do |product|
product_params = { :productId => product['product_id'], :productName => product['product_name'] }
product_params[:arch] = product['arch'] if product['arch']
product_params[:version] = product['version'] if product['version']
product_params
end
end
rhsm_params
end
|
#product_content ⇒ Object
156
157
158
159
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 156
def product_content
end
|
#remove_subscriptions ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 120
def remove_subscriptions
pool_id_quantities = params.require(:subscriptions).inject({}) do |new_hash, subscription|
new_hash[subscription['id']] ||= PoolWithQuantities.new(Pool.with_identifier(subscription['id']))
new_hash[subscription['id']].quantities << subscription['quantity']
new_hash
end
sync_task(::Actions::Katello::Host::RemoveSubscriptions, @host, pool_id_quantities.values)
respond_for_index(:collection => index_response(reload_host: true), :template => "index")
end
|