Class: Katello::Api::V2::HostSubscriptionsController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::Api::V2::ContentOverridesController
Defined in:
app/controllers/katello/api/v2/host_subscriptions_controller.rb

Instance Method Summary collapse

Methods inherited from ApiController

#empty_search_query?, #full_result_response, #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

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#available_release_versionsObject



139
140
141
142
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 139

def available_release_versions
  releases = @host.content_facet.try(:available_releases) || []
  respond_for_index :collection => full_result_response(releases)
end

#content_overrideObject



129
130
131
132
133
134
135
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 129

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(!params.dig(:content_overrides_search, :search).nil? && Foreman::Cast.to_bool(params.dig(:content_overrides_search, :limit_to_env)))
end

#createObject



72
73
74
75
76
77
78
79
80
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 72

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, :full_template => 'katello/api/v2/hosts/show')
end

#deprecate_entitlement_mode_endpointObject



33
34
35
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 33

def deprecate_entitlement_mode_endpoint
  ::Foreman::Deprecation.api_deprecation_warning(N_("This endpoint is deprecated and will be removed in an upcoming release. Simple Content Access is the only supported content access mode."))
end

#destroyObject



54
55
56
57
58
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 54

def destroy
  Katello::RegistrationManager.unregister_host(@host, :unregistering => true)
  @host.reload
  respond_for_destroy(:resource => @host)
end

#enabled_repositoriesObject



146
147
148
149
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 146

def enabled_repositories
  repositories = @host.content_facet.try(:bound_repositories) || []
  respond_with_template_collection "index", 'repositories', :collection => full_result_response(repositories)
end

#indexObject



39
40
41
42
43
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 39

def index
  deprecate_entitlement_mode_endpoint
  @collection = index_response
  respond_for_index :collection => @collection
end

#index_response(reload_host: false) ⇒ Object



45
46
47
48
49
50
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 45

def index_response(reload_host: false)
  # Host needs to be reloaded because of lazy accessor
  @host.reload if reload_host
  presenter = ::Katello::HostSubscriptionsPresenter.new(@host)
  full_result_response(presenter.subscriptions)
end

#params_to_rhsm_paramsObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 82

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[: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'] #convert api installed_product to candlepin params
    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_contentObject



109
110
111
112
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 109

def product_content
  # NOTE: this is just there as a placeholder for apipie.
  # The routing would automatically redirect it to repository_sets#index
end