Class: Katello::HostCollection
Defined Under Namespace
Classes: Jail
Class Method Summary
collapse
Instance Method Summary
collapse
#creatable?, #deletable?, #editable?, #readable?
Class Method Details
.humanize_class_name(_name = nil) ⇒ Object
143
144
145
|
# File 'app/models/katello/host_collection.rb', line 143
def self.humanize_class_name(_name = nil)
_("Host Collections")
end
|
.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'app/models/katello/host_collection.rb', line 114
def self.lists_by_updates_needed(organizations)
host_collections_hash = {}
host_collections = HostCollection.where(:organization_id => organizations).readable
host_collections.each do |host_collection|
host_collection_state = :ok
unless host_collection.hosts.empty?
host_collection_state = host_collection.security_updates? ? :critical : :warning
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
#add_host_ids!(requested_host_ids:, authorized_host_ids:) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/katello/host_collection.rb', line 79
def add_host_ids!(requested_host_ids:, authorized_host_ids:)
update_host_membership(requested_host_ids, authorized_host_ids) do |existing_host_ids, allowed_host_ids|
host_ids_to_add = allowed_host_ids - existing_host_ids
ensure_capacity_for!(host_ids_to_add.length)
create_host_collection_hosts(host_ids_to_add)
{
:updated_host_ids => host_ids_to_add,
:requested_existing_host_ids => existing_host_ids,
}
end
end
|
#bugzilla_updates?(installable_only: false) ⇒ Boolean
135
136
137
|
# File 'app/models/katello/host_collection.rb', line 135
def bugzilla_updates?(installable_only: false)
errata(Erratum::BUGZILLA, installable_only: installable_only).any?
end
|
#cache_key ⇒ Object
69
70
71
|
# File 'app/models/katello/host_collection.rb', line 69
def cache_key
"#{self.class.name}/#{self.id}"
end
|
#consumer_ids ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/models/katello/host_collection.rb', line 48
def consumer_ids
consumer_ids = []
self.hosts.each do |host|
if host.subscription_facet
consumer_ids.push(host.subscription_facet.uuid)
end
end
consumer_ids
end
|
#enhancement_updates?(installable_only: false) ⇒ Boolean
139
140
141
|
# File 'app/models/katello/host_collection.rb', line 139
def enhancement_updates?(installable_only: false)
errata(Erratum::ENHANCEMENT, installable_only: installable_only).any?
end
|
#errata(type = nil, installable_only: false) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'app/models/katello/host_collection.rb', line 60
def errata(type = nil, installable_only: false)
query = if installable_only
Katello::Erratum.installable_for_hosts(self.hosts)
else
Katello::Erratum.applicable_to_hosts(self.hosts)
end
type ? query.of_type(type) : query
end
|
#max_hosts_check ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'app/models/katello/host_collection.rb', line 31
def max_hosts_check
host_count = hosts.size
if !unlimited_hosts && host_count > 0 && (host_count.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_exceeded_message ⇒ Object
104
105
106
107
|
# File 'app/models/katello/host_collection.rb', line 104
def max_hosts_exceeded_message
_("You cannot have more than %{max_hosts} host(s) associated with host collection %{host_collection}.") %
{ :max_hosts => max_hosts, :host_collection => name }
end
|
#max_hosts_not_exceeded ⇒ Object
40
41
42
43
44
|
# 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, max_hosts_exceeded_message
end
end
|
#remove_host_ids!(requested_host_ids:, authorized_host_ids:) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/models/katello/host_collection.rb', line 92
def remove_host_ids!(requested_host_ids:, authorized_host_ids:)
update_host_membership(requested_host_ids, authorized_host_ids) do |existing_host_ids, allowed_host_ids|
host_ids_to_remove = existing_host_ids & allowed_host_ids
destroy_host_collection_hosts(host_ids_to_remove)
{
:updated_host_ids => host_ids_to_remove,
:requested_existing_host_ids => existing_host_ids,
}
end
end
|
#security_updates?(installable_only: false) ⇒ Boolean
131
132
133
|
# File 'app/models/katello/host_collection.rb', line 131
def security_updates?(installable_only: false)
errata(Erratum::SECURITY, installable_only: installable_only).any?
end
|
#total_hosts(cached: false) ⇒ Object
73
74
75
76
77
|
# File 'app/models/katello/host_collection.rb', line 73
def total_hosts(cached: false)
Rails.cache.fetch("#{cache_key}/total_hosts", expires_in: 1.minute, force: !cached) do
hosts.count
end
end
|