Class: Katello::KTEnvironment
Defined Under Namespace
Classes: Jail
Constant Summary
collapse
- ERROR_CLASS_NAME =
"Environment".freeze
Class Method Summary
collapse
Instance Method Summary
collapse
included, #label_not_changed, #setup_label_from_name
#creatable?, #editable?, #promotable_or_removable?, #readable?
Methods inherited from Model
#destroy!
Class Method Details
.humanize_class_name ⇒ Object
284
285
286
|
# File 'app/models/katello/kt_environment.rb', line 284
def self.humanize_class_name
_("Lifecycle Environment")
end
|
.permission_name ⇒ Object
288
289
290
|
# File 'app/models/katello/kt_environment.rb', line 288
def self.permission_name
'lifecycle_environments'
end
|
Instance Method Details
#add_to_default_capsule ⇒ Object
265
266
267
|
# File 'app/models/katello/kt_environment.rb', line 265
def add_to_default_capsule
SmartProxy.pulp_primary.try(:add_lifecycle_environment, self)
end
|
#as_json(_options = {}) ⇒ Object
245
246
247
248
249
250
251
|
# File 'app/models/katello/kt_environment.rb', line 245
def as_json(_options = {})
to_ret = self.attributes
to_ret['prior'] = self.prior && self.prior.name
to_ret['prior_id'] = self.prior && self.prior.id
to_ret['organization'] = self.organization && self.organization.name
to_ret
end
|
#assert_deletable ⇒ Object
188
189
190
|
# File 'app/models/katello/kt_environment.rb', line 188
def assert_deletable
throw :abort unless deletable?
end
|
#available_products ⇒ Object
231
232
233
234
235
236
237
238
239
|
# File 'app/models/katello/kt_environment.rb', line 231
def available_products
if self.prior.library
prior_products = self.organization.library.products
else
prior_products = self.prior.products
end
return prior_products - self.products
end
|
#available_releases ⇒ Object
Katello, which understands repository content and promotion, provides release versions based upon enabled repos. Headpin, which does not traverse products to the repo level, exposes all release versions in the manifest.
272
273
274
|
# File 'app/models/katello/kt_environment.rb', line 272
def available_releases
self.repositories.map(&:minor).compact.uniq.sort
end
|
#content_source_associated?(capsule) ⇒ Boolean
141
142
143
144
|
# File 'app/models/katello/kt_environment.rb', line 141
def content_source_associated?(capsule)
return false if capsule.blank?
capsule.pulp_primary? || self.content_sources.ids.include?(capsule.id)
end
|
#content_view_environment ⇒ Object
109
110
111
112
|
# File 'app/models/katello/kt_environment.rb', line 109
def content_view_environment
return nil unless self.default_content_view
self.default_content_view.content_view_environments.where(:environment_id => self.id).first
end
|
#default_content_view ⇒ Object
100
101
102
|
# File 'app/models/katello/kt_environment.rb', line 100
def default_content_view
self.default_content_view_version.try(:content_view)
end
|
#default_content_view_version ⇒ Object
104
105
106
107
|
# File 'app/models/katello/kt_environment.rb', line 104
def default_content_view_version
return nil unless self.organization.default_content_view
self.organization.default_content_view.version(self)
end
|
#deletable? ⇒ Boolean
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'app/models/katello/kt_environment.rb', line 192
def deletable?
return true if self.organization.nil? || self.organization.being_deleted?
if library?
errors.add :base, _("Library lifecycle environments may not be deleted.")
end
if content_facets.any?
errors.add(:base,
_("Lifecycle Environment %s has associated Hosts." \
" Please unregister or move the associated Hosts before trying to delete this lifecycle environment.") % self.name)
end
if activation_keys.any?
errors.add(:base,
_("Lifecycle Environment %s has associated Activation Keys." \
" Please change or remove the associated Activation Keys before trying to delete this lifecycle environment.") % self.name)
end
if hostgroup_content_facets.any?
errors.add(:base,
_("Lifecycle environment %s has associated host groups." \
" Please change or remove the associated host groups before trying to delete this lifecycle environment.") % self.name)
end
return errors.empty?
end
|
#delete_host_and_hostgroup_associations ⇒ Object
276
277
278
279
280
281
282
|
# File 'app/models/katello/kt_environment.rb', line 276
def delete_host_and_hostgroup_associations
hgcf_ids = hostgroup_content_facets.ids
::Katello::Hostgroup::ContentFacet.where(id: hgcf_ids).destroy_all
host_ids = hosts.ids
::Katello::Host::ContentFacet.where(:host_id => host_ids).destroy_all
::Katello::Host::SubscriptionFacet.where(:host_id => host_ids).destroy_all
end
|
#display_name ⇒ Object
146
147
148
|
# File 'app/models/katello/kt_environment.rb', line 146
def display_name
self.name
end
|
#full_path ⇒ Object
Unlike path which only gives the path from this environment going forward
Get the full path, that is go to the HEAD of the path this environment is on
and then give me that entire path
223
224
225
226
227
228
229
|
# File 'app/models/katello/kt_environment.rb', line 223
def full_path
p = self
until p.prior.nil? || p.prior.library
p = p.prior
end
p.prior.nil? ? p.path : [p.prior] + p.path
end
|
#insert_successor(create_params, path) ⇒ Object
creates new env from create_params with self as a prior
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'app/models/katello/kt_environment.rb', line 120
def insert_successor(create_params, path)
self.class.transaction do
new_successor = self.class.create!(create_params)
if library?
if path
old_successor = path.first
old_successor.prior = new_successor
end
save_successor new_successor
elsif successor.nil?
save_successor new_successor
else
old_successor = successor
old_successor.prior = new_successor
save_successor new_successor
end
fail HttpErrors::UnprocessableEntity, _('An environment is missing a prior') unless all_have_prior?
new_successor
end
end
|
#key_for(item) ⇒ Object
261
262
263
|
# File 'app/models/katello/kt_environment.rb', line 261
def key_for(item)
"environment_#{id}_#{item}"
end
|
#library? ⇒ Boolean
96
97
98
|
# File 'app/models/katello/kt_environment.rb', line 96
def library?
self.library
end
|
#path ⇒ Object
172
173
174
175
176
177
178
179
180
181
|
# File 'app/models/katello/kt_environment.rb', line 172
def path
s = self.successor
ret = [self]
until s.nil?
fail "Environment path has duplicates!!. #{self}. Duplicate => #{ret}. Path => #{s}" if ret.include? s
ret << s
s = s.successor
end
ret
end
|
#prior ⇒ Object
160
161
162
|
# File 'app/models/katello/kt_environment.rb', line 160
def prior
self.priors[0]
end
|
#prior=(env) ⇒ Object
164
165
166
167
168
169
170
|
# File 'app/models/katello/kt_environment.rb', line 164
def prior=(env)
env_id = env.is_a?(ActiveRecord::Base) ? env.id : env
self.priors.clear
return if env_id.nil? || env_id == ""
prior_env = KTEnvironment.find env_id
self.priors << prior_env unless prior_env.nil?
end
|
#products ⇒ Object
241
242
243
|
# File 'app/models/katello/kt_environment.rb', line 241
def products
self.library? ? Product.in_org(self.organization) : Product.where(id: repositories.map(&:product_id))
end
|
is the environment currently being promoted to
184
185
186
|
# File 'app/models/katello/kt_environment.rb', line 184
def promoting_to?
self.promoting.exists?
end
|
#remove_from_path ⇒ Object
253
254
255
256
257
258
259
|
# File 'app/models/katello/kt_environment.rb', line 253
def remove_from_path
if self.successor && self.prior
prior_env = self.prior
self.env_priors.destroy_all
self.successor.env_priors.first.update!(:prior_id => prior_env.id)
end
end
|
#successor ⇒ Object
114
115
116
117
|
# File 'app/models/katello/kt_environment.rb', line 114
def successor
return self.successors[0] unless self.library?
self.organization.promotion_paths[0][0] unless self.organization.promotion_paths.empty?
end
|
#to_label ⇒ Object
for multiselect helper in foreman
155
156
157
158
|
# File 'app/models/katello/kt_environment.rb', line 155
def to_label
return "#{name} (#{organization.title})" if organization && ::Organization.current.nil?
name
end
|
#to_s ⇒ Object
150
151
152
|
# File 'app/models/katello/kt_environment.rb', line 150
def to_s
display_name
end
|