Class: Katello::HostCollection

Inherits:
Model
  • Object
show all
Includes:
Authorization::HostCollection
Defined in:
app/models/katello/host_collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorization::HostCollection

#creatable?, #deletable?, #editable?, #readable?

Methods inherited from Model

#destroy!

Class Method Details

.lists_by_updates_needed(organizations) ⇒ Object

Retrieve the list of accessible host collections in the organization specified, returning them in the following arrays:

critical: those collections that have 1 or more security errata that need to be applied
warning: those collections that have 1 or more non-security errata that need to be applied
ok: those collections that are completely up to date


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/models/katello/host_collection.rb', line 136

def self.lists_by_updates_needed(organizations)
  host_collections_hash = {}
  host_collections = HostCollection.where(:organization_id => organizations).readable

  # determine the state (critical/warning/ok) for each host collection
  host_collections.each do |host_collection|
    host_collection_state = :ok
    unless host_collection.hosts.empty?
      host_collection.errata.each do |erratum|
        case erratum.errata_type
        when Erratum::SECURITY
          # there is a critical errata, so stop searching...
          host_collection_state = :critical
          break

        when Erratum::BUGZILLA
        when Erratum::ENHANCEMENT
          # set state to warning, but continue searching...
          host_collection_state = :warning
        end
      end
    end

    host_collections_hash[host_collection_state] ||= []
    host_collections_hash[host_collection_state] << host_collection
  end
  return host_collections_hash[:critical].to_a, host_collections_hash[:warning].to_a, host_collections_hash[:ok].to_a
end

Instance Method Details

#bugzilla_updates?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'app/models/katello/host_collection.rb', line 169

def bugzilla_updates?
  errata.any? { |erratum| erratum.errata_type == Erratum::BUGZILLA }
end

#consumer_idsObject



110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/katello/host_collection.rb', line 110

def consumer_ids
  consumer_ids = []

  self.hosts.each do |host|
    if host.content_facet
      consumer_ids.push(host.content_facet.uuid)
    end
  end

  consumer_ids
end

#enhancement_updates?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'app/models/katello/host_collection.rb', line 173

def enhancement_updates?
  errata.any? { |erratum| erratum.errata_type == Erratum::ENHANCEMENT }
end

#errata(type = nil) ⇒ Object



122
123
124
125
# File 'app/models/katello/host_collection.rb', line 122

def errata(type = nil)
  query = Erratum.joins(:content_facets).where("#{Katello::Host::ContentFacet.table_name}.host_id" => self.host_ids)
  type ? query.of_type(type) : query
end

#install_errata(errata_ids) ⇒ Object



98
99
100
101
102
103
104
# File 'app/models/katello/host_collection.rb', line 98

def install_errata(errata_ids)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.install_consumer_errata(errata_ids)
    save_job(pulp_job, :errata_install, :errata_ids, errata_ids)
  end
end

#install_package_groups(groups) ⇒ Object



74
75
76
77
78
79
80
# File 'app/models/katello/host_collection.rb', line 74

def install_package_groups(groups)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.install_package_group(groups)
    save_job(pulp_job, :package_group_install, :groups, groups)
  end
end

#install_packages(packages) ⇒ Object



49
50
51
52
53
54
55
# File 'app/models/katello/host_collection.rb', line 49

def install_packages(packages)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.install_package(packages)
    save_job(pulp_job, :package_install, :packages, packages)
  end
end

#max_hosts_checkObject



34
35
36
37
38
# File 'app/models/katello/host_collection.rb', line 34

def max_hosts_check
  if !unlimited_hosts && (hosts.length > 0 && (hosts.length.to_i > max_hosts.to_i)) && max_hosts_changed?
    errors.add :max_host, N_("may not be less than the number of hosts associated with the host collection.")
  end
end

#max_hosts_not_exceededObject



40
41
42
43
44
45
# File 'app/models/katello/host_collection.rb', line 40

def max_hosts_not_exceeded
  if !unlimited_hosts && (hosts.size.to_i > max_hosts.to_i)
    errors.add :base,  N_("You cannot have more than #{max_hosts} host(s) associated with host collection #{name}." %
                          {:max_hosts => max_hosts, :name => name})
  end
end

#refreshed_jobsObject



106
107
108
# File 'app/models/katello/host_collection.rb', line 106

def refreshed_jobs
  Job.refresh_for_owner(self)
end

#security_updates?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'app/models/katello/host_collection.rb', line 165

def security_updates?
  errata.any? { |erratum| erratum.errata_type == Erratum::SECURITY }
end

#total_hostsObject



127
128
129
# File 'app/models/katello/host_collection.rb', line 127

def total_hosts
  hosts.length
end

#uninstall_package_groups(groups) ⇒ Object



90
91
92
93
94
95
96
# File 'app/models/katello/host_collection.rb', line 90

def uninstall_package_groups(groups)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.uninstall_package_group(groups)
    save_job(pulp_job, :package_group_remove, :groups, groups)
  end
end

#uninstall_packages(packages) ⇒ Object



57
58
59
60
61
62
63
# File 'app/models/katello/host_collection.rb', line 57

def uninstall_packages(packages)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.uninstall_package(packages)
    save_job(pulp_job, :package_remove, :packages, packages)
  end
end

#update_package_groups(groups) ⇒ Object



82
83
84
85
86
87
88
# File 'app/models/katello/host_collection.rb', line 82

def update_package_groups(groups)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.install_package_group(groups)
    save_job(pulp_job, :package_group_update, :groups, groups)
  end
end

#update_packages(packages = nil) ⇒ Object



65
66
67
68
69
70
71
72
# File 'app/models/katello/host_collection.rb', line 65

def update_packages(packages = nil)
  # if no packages are provided, a full host update will be performed (e.g ''yum update' equivalent)
  fail Errors::HostCollectionEmptyException if self.hosts.empty?
  perform_group_action do |consumer_group|
    pulp_job = consumer_group.update_package(packages)
    save_job(pulp_job, :package_update, :packages, packages)
  end
end