Class: Katello::KTEnvironment

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

Defined Under Namespace

Classes: Jail

Constant Summary collapse

ERROR_CLASS_NAME =
"Environment".freeze

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



271
272
273
# File 'app/models/katello/kt_environment.rb', line 271

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

.permission_nameObject



275
276
277
# File 'app/models/katello/kt_environment.rb', line 275

def self.permission_name
  'lifecycle_environments'
end

Instance Method Details

#add_to_default_capsuleObject



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

def add_to_default_capsule
  SmartProxy.pulp_primary.try(:add_lifecycle_environment, self)
end

#as_json(_options = {}) ⇒ Object



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

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_deletableObject



189
190
191
# File 'app/models/katello/kt_environment.rb', line 189

def assert_deletable
  throw :abort unless deletable?
end

#available_productsObject



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

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.



267
268
269
# File 'app/models/katello/kt_environment.rb', line 267

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

#content_source_associated?(capsule) ⇒ Boolean

Returns:

  • (Boolean)


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

def content_source_associated?(capsule)
  return false if capsule.blank?
  capsule.pulp_primary? || self.content_sources.ids.include?(capsule.id)
end

#content_view_environmentObject



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

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



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

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

#default_content_view_versionObject



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

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)


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'app/models/katello/kt_environment.rb', line 193

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

  return errors.empty?
end

#display_nameObject



147
148
149
# File 'app/models/katello/kt_environment.rb', line 147

def display_name
  self.name
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


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

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



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/models/katello/kt_environment.rb', line 121

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



256
257
258
# File 'app/models/katello/kt_environment.rb', line 256

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

#library?Boolean

Returns:

  • (Boolean)


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

def library?
  self.library
end

#pathObject



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

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



161
162
163
# File 'app/models/katello/kt_environment.rb', line 161

def prior
  self.priors[0]
end

#prior=(env) ⇒ Object



165
166
167
168
169
170
171
# File 'app/models/katello/kt_environment.rb', line 165

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

#productsObject



236
237
238
# File 'app/models/katello/kt_environment.rb', line 236

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)


185
186
187
# File 'app/models/katello/kt_environment.rb', line 185

def promoting_to?
  self.promoting.exists?
end

#remove_from_pathObject



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

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

#successorObject



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

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



156
157
158
159
# File 'app/models/katello/kt_environment.rb', line 156

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

#to_sObject



151
152
153
# File 'app/models/katello/kt_environment.rb', line 151

def to_s
  display_name
end