Class: ForemanDiscovery::ImportHooks::LockTemplates

Inherits:
ForemanDiscovery::ImportHook show all
Defined in:
app/services/foreman_discovery/import_hooks/lock_templates.rb

Instance Attribute Summary

Attributes inherited from ForemanDiscovery::ImportHook

#facts, #host

Instance Method Summary collapse

Methods inherited from ForemanDiscovery::ImportHook

#initialize

Constructor Details

This class inherits a constructor from ForemanDiscovery::ImportHook

Instance Method Details

#after_populateObject



5
6
7
# File 'app/services/foreman_discovery/import_hooks/lock_templates.rb', line 5

def after_populate
  lock_templates if Setting['discovery_lock'] && host.subnet.tftp?
end

#lock_templatesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/foreman_discovery/import_hooks/lock_templates.rb', line 9

def lock_templates
  TemplateKind::PXE.each do |kind|
    setting = "discovery_#{kind.downcase}_lock_template"
    template_name = Setting[setting]
    logger.info "Locking discovered host #{host.mac} in subnet #{host.subnet} via #{template_name} template"
    template = ::ProvisioningTemplate.unscoped.find_by_name(template_name)
    if template.nil?
      logger.warn "Template '#{template_name}' provided by setting '#{setting}' does not exist, not locking"
      next
    end
    rendered_template = host.render_template(template: template, params: { host: host })
    host.subnet.tftp_proxy.set(kind, host.mac, pxeconfig: rendered_template)
  end
rescue ::Foreman::Exception => e
  ::Foreman::Logging.exception('Could not set tftp_proxy from proxy', e)
end