Class: Katello::Validators::HostgroupKickstartRepositoryValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/lib/katello/validators/hostgroup_kickstart_repository_validator.rb

Instance Method Summary collapse

Instance Method Details

#content_view_in_env?(facet) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'app/lib/katello/validators/hostgroup_kickstart_repository_validator.rb', line 29

def content_view_in_env?(facet)
  cvenv = facet.content_view_environment || facet.hostgroup.content_view_environment
  return false if cvenv.blank?
  cvenv.environment.content_views.include?(cvenv.content_view)
end

#validate(facet) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/lib/katello/validators/hostgroup_kickstart_repository_validator.rb', line 4

def validate(facet)
  return unless facet.kickstart_repository_id
  if facet.content_source.blank? && facet.hostgroup.content_source.blank?
    prop = :content_source
    msg = _("Please select a content source before assigning a kickstart repository")
  elsif facet.hostgroup.operatingsystem.blank?
    prop = :base
    msg = _("Please select an operating system before assigning a kickstart repository")
  elsif !facet.hostgroup.operatingsystem.is_a?(Redhat)
    prop = :base
    msg = _("Kickstart repositories can only be assigned to hosts in the Red Hat family")
  elsif facet.hostgroup.architecture.blank?
    prop = :base
    msg = _("Please select an architecture before assigning a kickstart repository")
  elsif !content_view_in_env?(facet)
    prop = :lifecycle_environment
    msg = _("The selected/Inherited Content View is not available for this Lifecycle Environment")
  elsif !facet.hostgroup.matching_kickstart_repository?(facet)
    prop = :kickstart_repository
    msg = _("The selected kickstart repository is not part of the assigned content view, " \
            "lifecycle environment, content source, operating system, and architecture")
  end
  facet.hostgroup.errors.add(prop, msg) if msg
end