Sha256: a7876e43e4410f399bfb278249b884f27d82862aa3b72fad1993636d3a006614

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'uri'

module ForemanBootdisk
  class Renderer
    include ::Foreman::Renderer
    include Rails.application.routes.url_helpers
    delegate :logger, :to => :ForemanBootdisk
    include RendererMethods

    def generic_template_render(subnet = nil)
      tmpl = ProvisioningTemplate.unscoped.find_by_name(Setting[:bootdisk_generic_host_template]) || raise(::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template'))

      if subnet.present?
        # rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
        # valid host, with a token, and with a tftp proxy
        @host = Struct.new(:token, :provision_interface).new(
          Struct.new(:value).new('faketoken'),
          Struct.new(:subnet).new(subnet)
        )
      else
        @host = Struct.new(:token, :subnet).new(nil,nil)
      end
      modified_template = unattended_render(tmpl.template)
      # remove the token from subnet-level generation, since this is meant to be generic
      modified_template.gsub!(/(?<=iPXE\?)token=faketoken\&(?=mac=)/,'')
      modified_template
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_bootdisk-12.0.1 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-12.0.0 app/services/foreman_bootdisk/renderer.rb