Sha256: 06ad1bb39a21546206e8ad182c3efa78db01c020a39f9f59d8fce46a957079a2

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

require 'uri'

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

    def generic_template_render(subnet = nil)
      tmpl = ProvisioningTemplate.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, :subnet).new(
          Struct.new(:value).new('faketoken'),
          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

    def bootdisk_chain_url(mac = '', action = 'iPXE')
      Renderer.format_bootdisk_chain_url(foreman_url(action), mac)
    end

    def self.format_bootdisk_chain_url(url, mac)
      u = URI.parse(url)
      ForemanBootdisk.logger.warn("Foreman or proxy is configured with HTTPS, probably not supported by iPXE: #{u}") if u.scheme == 'https'
      u.query = "#{u.query}&mac=#{mac}"
      u.fragment = nil
      u.to_s
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_bootdisk-8.1.0 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-8.0.2 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-8.0.1 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-7.0.1 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-8.0.0 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-7.0.0 app/services/foreman_bootdisk/renderer.rb
foreman_bootdisk-6.1.0 app/services/foreman_bootdisk/renderer.rb