Class: Katello::KTEnvironment

Inherits:
Model
  • Object
show all
Includes:
ForemanTasks::Concerns::ActionSubject, Authorization::LifecycleEnvironment, Ext::LabelFromName
Defined in:
app/models/katello/kt_environment.rb

Constant Summary collapse

ERROR_CLASS_NAME =
"Environment"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ext::LabelFromName

included, #label_not_changed, #setup_label_from_name

Methods included from Authorization::LifecycleEnvironment

#creatable?, #editable?, #promotable_or_removable?, #readable?

Methods inherited from Model

#destroy!

Class Method Details

.humanize_class_nameObject



265
266
267
# File 'app/models/katello/kt_environment.rb', line 265

def self.humanize_class_name
  _("Lifecycle Environment")
end

.permission_nameObject



269
270
271
# File 'app/models/katello/kt_environment.rb', line 269

def self.permission_name
  'lifecycle_environments'
end

Instance Method Details

#add_to_default_capsuleObject



254
255
256
# File 'app/models/katello/kt_environment.rb', line 254

def add_to_default_capsule
  CapsuleContent.default_capsule.try(:add_lifecycle_environment, self)
end

#as_json(_options = {}) ⇒ Object



199
200
201
202
203
204
205
# File 'app/models/katello/kt_environment.rb', line 199

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

#available_productsObject



181
182
183
184
185
186
187
188
189
# File 'app/models/katello/kt_environment.rb', line 181

def available_products
  if self.prior.library
    # if there is no prior, then the prior is the Library, which has all products
    prior_products = self.organization.library.products
  else
    prior_products = self.prior.products
  end
  return prior_products - self.products
end

#available_releasesObject

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.



261
262
263
# File 'app/models/katello/kt_environment.rb', line 261

def available_releases
  self.repositories.map(&:minor).compact.uniq.sort
end

#content_view_environmentObject



95
96
97
98
# File 'app/models/katello/kt_environment.rb', line 95

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_viewObject



86
87
88
# File 'app/models/katello/kt_environment.rb', line 86

def default_content_view
  self.default_content_view_version.try(:content_view, nil)
end

#default_content_view_versionObject



90
91
92
93
# File 'app/models/katello/kt_environment.rb', line 90

def default_content_view_version
  return nil unless self.organization.default_content_view
  self.organization.default_content_view.version(self)
end

#deletable?Boolean

Returns:

  • (Boolean)


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/models/katello/kt_environment.rb', line 146

def deletable?
  return true if self.organization.nil? || self.organization.being_deleted?

  if library?
    errors.add :base, _("Library lifecycle environments may not be deleted.")
  elsif !successor.nil?
    errors.add :base, _("Lifecycle Environment %s has a successor.  Only the last lifecycle environment on a path can be deleted") % self.name
  end

  if systems.any?
    errors.add(:base,
       _("Lifecycle Environment %s has associated Content Hosts." \
          " Please unregister or move the associated Content 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

  return errors.empty?
end

#display_nameObject



105
106
107
# File 'app/models/katello/kt_environment.rb', line 105

def display_name
  self.name
end

#find_packages_by_name(name) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'app/models/katello/kt_environment.rb', line 227

def find_packages_by_name(name)
  products = self.products.collect do |prod|
    prod.find_packages_by_name(self, name).collect do |p|
      p[:product_id] = prod.cp_id
      p
    end
  end
  products.flatten(1)
end

#find_packages_by_nvre(name, version, release, epoch) ⇒ Object



237
238
239
240
241
242
243
244
245
# File 'app/models/katello/kt_environment.rb', line 237

def find_packages_by_nvre(name, version, release, epoch)
  products = self.products.collect do |prod|
    prod.find_packages_by_nvre(self, name, version, release, epoch).collect do |p|
      p[:product_id] = prod.cp_id
      p
    end
  end
  products.flatten(1)
end

#full_pathObject

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


173
174
175
176
177
178
179
# File 'app/models/katello/kt_environment.rb', line 173

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

#get_distribution(id) ⇒ Object



247
248
249
250
251
252
# File 'app/models/katello/kt_environment.rb', line 247

def get_distribution(id)
  distribution = self.products.collect do |prod|
    prod.get_distribution(self, id)
  end
  distribution.flatten(1)
end

#key_for(item) ⇒ Object



207
208
209
# File 'app/models/katello/kt_environment.rb', line 207

def key_for(item)
  "environment_#{id}_#{item}"
end

#library?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/models/katello/kt_environment.rb', line 82

def library?
  self.library
end

#package_group_categories(search_args = {}) ⇒ Object



219
220
221
222
223
224
225
# File 'app/models/katello/kt_environment.rb', line 219

def package_group_categories(search_args = {})
  categories = []
  self.products.each do |prod|
    categories << prod.package_group_categories(self, search_args)
  end
  categories.flatten(1)
end

#package_groups(search_args = {}) ⇒ Object



211
212
213
214
215
216
217
# File 'app/models/katello/kt_environment.rb', line 211

def package_groups(search_args = {})
  groups = []
  self.products.each do |prod|
    groups << prod.package_groups(self, search_args)
  end
  groups.flatten(1)
end

#pathObject



130
131
132
133
134
135
136
137
138
139
# File 'app/models/katello/kt_environment.rb', line 130

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

#priorObject



119
120
121
# File 'app/models/katello/kt_environment.rb', line 119

def prior
  self.priors[0]
end

#prior=(env_id) ⇒ Object



123
124
125
126
127
128
# File 'app/models/katello/kt_environment.rb', line 123

def prior=(env_id)
  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

#productsObject



191
192
193
# File 'app/models/katello/kt_environment.rb', line 191

def products
  self.library? ? Product.in_org(self.organization) : Product.where(id: repositories.map(&:product_id))
end

#promoting_to?Boolean

is the environment currently being promoted to

Returns:

  • (Boolean)


142
143
144
# File 'app/models/katello/kt_environment.rb', line 142

def promoting_to?
  self.promoting.exists?
end

#puppet_repositoriesObject



195
196
197
# File 'app/models/katello/kt_environment.rb', line 195

def puppet_repositories
  self.repositories.readable.where(:content_type => Katello::Repository::PUPPET_TYPE)
end

#successorObject



100
101
102
103
# File 'app/models/katello/kt_environment.rb', line 100

def successor
  return self.successors[0] unless self.library?
  self.organization.promotion_paths[0][0] unless self.organization.promotion_paths.empty?
end

#to_labelObject

for multiselect helper in foreman



114
115
116
117
# File 'app/models/katello/kt_environment.rb', line 114

def to_label
  return "#{name} (#{organization.title})" if organization && ::Organization.current.nil?
  name
end

#to_sObject



109
110
111
# File 'app/models/katello/kt_environment.rb', line 109

def to_s
  display_name
end