Sha256: 33261e4c2d43e74fa65f8b518cffd163e8e37d012aa68da70b1924dc40c0b377

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

module ForemanBootdisk
  module TemplateHelpers
    extend ApipieDSL::Class

    apipie :class, 'Macros related to provisioning via boot disk' do
      name 'Bootdisk'
      sections only: %w[all provisioning]
    end

    apipie :method, 'Generates URL for boot chain' do
      optional :mac, String, 'MAC address of the host', default: 'MAC address of the current host'
      optional :action, String, 'Bootloader to use', default: 'iPXE'
      returns String, desc: 'URL for boot chain'
      example 'bootdisk_chain_url #=> "http://foreman.example.com/unattended/iPXE?mac=00%3A11%3A22%3A33%3A44%3A55"'
      example 'bootdisk_chain_url("00:11:22:33:44:55") #=> "http://foreman.example.com/unattended/iPXE?mac=00%3A11%3A22%3A33%3A44%3A55"'
    end
    def bootdisk_chain_url(mac = host.try(:mac), action = 'iPXE')
      url = foreman_url(action)
      u = URI.parse(url)
      new_query_data = URI.decode_www_form(u.query || '') << ['mac', mac || '']
      new_querystring = URI.encode_www_form(new_query_data)
      u.query = nil
      u.query = new_querystring if new_querystring.present?
      u.fragment = nil
      u.to_s
    end

    apipie :method, 'Always raises an error with a description provided as an argument' do
      desc 'This method is useful for aborting script execution if some of the conditions are not met'
      list :args, desc: 'Description for the error'
      raises error: ::Foreman::Exception, desc: 'The error is always being raised'
      returns nil, desc: "Doesn't return anything"
      example "<%
        interface = @host.provision_interface #=> interface = nil
        bootdisk_raise(N_('Host has no provisioning interface defined')) unless interface #=> Foreman::Exception is raised and the execution of the script is aborted
      %>"
    end
    def bootdisk_raise(*args)
      raise ::Foreman::Exception.new(*args)
    end

    def template_name
      "Foreman Bootdisk"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_bootdisk-22.0.1 app/lib/foreman_bootdisk/template_helpers.rb