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



119
120
121
122
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 119

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

#content_overrideObject



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

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



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

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

#destroyObject



35
36
37
38
39
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 35

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

#enabled_repositoriesObject



126
127
128
129
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 126

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

#params_to_rhsm_paramsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 63

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



89
90
91
92
# File 'app/controllers/katello/api/v2/host_subscriptions_controller.rb', line 89

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