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



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

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

.permission_nameObject



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

def self.permission_name
  'lifecycle_environments'
end

Instance Method Details

#add_to_default_capsuleObject



245
246
247
# File 'app/models/katello/kt_environment.rb', line 245

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

#as_json(_options = {}) ⇒ Object



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

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



174
175
176
# File 'app/models/katello/kt_environment.rb', line 174

def assert_deletable
  throw :abort unless deletable?
end

#available_productsObject



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

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.



252
253
254
# File 'app/models/katello/kt_environment.rb', line 252

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

#content_view_environmentObject



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

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



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

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

#default_content_view_versionObject



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

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)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'app/models/katello/kt_environment.rb', line 178

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



132
133
134
# File 'app/models/katello/kt_environment.rb', line 132

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


203
204
205
206
207
208
209
# File 'app/models/katello/kt_environment.rb', line 203

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/katello/kt_environment.rb', line 111

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



241
242
243
# File 'app/models/katello/kt_environment.rb', line 241

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

#library?Boolean

Returns:

  • (Boolean)


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

def library?
  self.library
end

#pathObject



158
159
160
161
162
163
164
165
166
167
# File 'app/models/katello/kt_environment.rb', line 158

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



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

def prior
  self.priors[0]
end

#prior=(env) ⇒ Object



150
151
152
153
154
155
156
# File 'app/models/katello/kt_environment.rb', line 150

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



221
222
223
# File 'app/models/katello/kt_environment.rb', line 221

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)


170
171
172
# File 'app/models/katello/kt_environment.rb', line 170

def promoting_to?
  self.promoting.exists?
end

#remove_from_pathObject



233
234
235
236
237
238
239
# File 'app/models/katello/kt_environment.rb', line 233

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



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

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



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

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

#to_sObject



136
137
138
# File 'app/models/katello/kt_environment.rb', line 136

def to_s
  display_name
end