Class: Katello::Api::V2::HostPackagesController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/host_packages_controller.rb

Constant Summary collapse

UPGRADABLE =
"upgradable".freeze
UP_TO_DATE =
"up-to-date".freeze
VERSION_STATUSES =
[UPGRADABLE, UP_TO_DATE].freeze

Constants included from Concerns::FilteredAutoCompleteSearch

Concerns::FilteredAutoCompleteSearch::PAGE_SIZE

Instance Method Summary collapse

Methods included from Concerns::FilteredAutoCompleteSearch

#auto_complete_search

Methods inherited from ApiController

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

#indexObject



31
32
33
34
35
36
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 31

def index
  validate_index_params!
  collection = scoped_search(index_relation, :name, :asc, :resource_class => ::Katello::InstalledPackage)
  collection[:results] = HostPackagePresenter.with_latest(collection[:results], @host) if ::Foreman::Cast.to_bool(params[:include_latest_upgradable])
  respond_for_index(:collection => collection)
end

#index_relationObject



92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 92

def index_relation
  packages = @host.installed_packages
  upgradable_packages = ::Katello::Rpm.installable_for_hosts([@host]).select(:name)
  if params[:status].present?
    packages = case params[:status]
               when 'up-to-date' then packages.where.not(name: upgradable_packages)
               when 'upgradable' then packages.where(name: upgradable_packages)
               end
  end
  packages
end

#installObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 41

def install
  if params[:packages]
    packages = validate_package_list_format(params[:packages])
    task     = async_task(::Actions::Katello::Host::Package::Install, @host, content: packages)
    respond_for_async :resource => task
    return
  end

  if params[:groups]
    groups = extract_group_names(params[:groups])
    task   = async_task(::Actions::Katello::Host::PackageGroup::Install, @host, content: groups)
    respond_for_async :resource => task
  end
end

#removeObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 77

def remove
  if params[:packages]
    packages = validate_package_list_format(params[:packages])
    task     = async_task(::Actions::Katello::Host::Package::Remove, @host, content: packages)
    respond_for_async :resource => task
    return
  end

  if params[:groups]
    groups = extract_group_names(params[:groups])
    task   = async_task(::Actions::Katello::Host::PackageGroup::Remove, @host, content: groups)
    respond_for_async :resource => task
  end
end

#resource_classObject



104
105
106
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 104

def resource_class
  Katello::InstalledPackage
end

#upgradeObject



59
60
61
62
63
64
65
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 59

def upgrade
  if params[:packages]
    packages = validate_package_list_format(params[:packages])
    task     = async_task(::Actions::Katello::Host::Package::Update, @host, content: packages)
    respond_for_async :resource => task
  end
end

#upgrade_allObject



69
70
71
72
# File 'app/controllers/katello/api/v2/host_packages_controller.rb', line 69

def upgrade_all
  task = async_task(::Actions::Katello::Host::Package::Update, @host, content: [])
  respond_for_async :resource => task
end