Module: Katello::Concerns::HostManagedExtensions::Overrides

Defined in:
app/models/katello/concerns/host_managed_extensions.rb

Instance Method Summary collapse

Instance Method Details

#apply_inherited_attributes(attributes, initialized = true) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 43

def apply_inherited_attributes(attributes, initialized = true)
  attributes = super(attributes, initialized)
  facet_attrs = attributes['content_facet_attributes']
  return attributes if facet_attrs.blank?
  cv_id = facet_attrs['content_view_id']
  lce_id = facet_attrs['lifecycle_environment_id']
  if initialized && (cv_id.blank? || lce_id.blank?)
    if cv_id.blank?
      Rails.logger.info "Hostgroup has no content view assigned; using host's existing content view"
      facet_attrs['content_view_id'] = content_facet&.single_content_view&.id
    end
    if lce_id.blank?
      Rails.logger.info "Hostgroup has no lifecycle environment assigned; using host's existing lifecycle environment"
      facet_attrs['lifecycle_environment_id'] = content_facet&.single_lifecycle_environment&.id
    end
    attributes['content_facet_attributes'] = facet_attrs
  else
    Rails.logger.info "Hostgroup has content view and lifecycle environment assigned; using those"
  end
  attributes
end

#attributes=(attrs) ⇒ Object



22
23
24
25
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 22

def attributes=(attrs)
  check_cve_attributes(attrs)
  super
end

#check_cve_attributes(attrs) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 9

def check_cve_attributes(attrs)
  if attrs[:content_facet_attributes]
    cv_id = attrs[:content_facet_attributes].delete(:content_view_id)
    lce_id = attrs[:content_facet_attributes].delete(:lifecycle_environment_id)
    if cv_id && lce_id
      content_facet.assign_single_environment(content_view_id: cv_id, lifecycle_environment_id: lce_id)
    end
    if (cv_id.present? && lce_id.blank?) || (cv_id.blank? && lce_id.present?)
      fail "content_view_id and lifecycle_environment_id must be provided together"
    end
  end
end

#inherited_attributesObject



37
38
39
40
41
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 37

def inherited_attributes
  inherited_attrs = super
  inherited_attrs.delete('medium_id') if content_facet && !content_facet.kickstart_repository.blank?
  inherited_attrs
end

#remote_execution_proxies(provider, *_rest) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 84

def remote_execution_proxies(provider, *_rest)
  proxies = super
  if (name = subscription_facet&.registered_through)
    registered_through = SmartProxy.with_features(provider)
                                   .authorized
                                   .where(name: name)
  end
  proxies[:registered_through] = registered_through || []
  proxies
end

#smart_proxy_idsObject



65
66
67
68
69
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 65

def smart_proxy_ids
  ids = super
  ids << content_source_id
  ids.uniq.compact
end

#update(attrs) ⇒ Object



27
28
29
30
31
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 27

def update(attrs)
  return super if self.content_facet.blank?
  check_cve_attributes(attrs)
  super
end

#update_os_from_factsObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 71

def update_os_from_facts
  super

  # If facts causes the OS to change, our kickstart repo might not be
  # valid anymore. Let's reset it, either to nil or a valid one
  ks_repo = content_facet&.kickstart_repository
  valid_repos = operatingsystem.respond_to?(:kickstart_repos) ? (operatingsystem.kickstart_repos(self)&.pluck(:id) || []) : []

  if ks_repo && valid_repos.exclude?(ks_repo.id)
    content_facet.kickstart_repository_id = valid_repos.first
  end
end

#validate_media?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/katello/concerns/host_managed_extensions.rb', line 33

def validate_media?
  (content_source_id.blank? || (content_facet && content_facet.kickstart_repository.blank?)) && super
end