Sha256: 3e083b1f277c4684cf14e5cda36c7a79caff06abec14b0666e35c1cab766f970

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

# lock the host into discovery via PXE if feature is enabled in settings
module ForemanDiscovery
  module ImportHooks
    class LockTemplates < ImportHook
      def after_populate
        lock_templates if Setting['discovery_lock'] && host.subnet.tftp?
      end

      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
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foreman_discovery-25.0.0 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-24.0.2 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-23.0.2 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-24.0.1 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-24.0.0 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-23.0.1 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-23.0.0 app/services/foreman_discovery/import_hooks/lock_templates.rb
foreman_discovery-22.0.4 app/services/foreman_discovery/import_hooks/lock_templates.rb