Sha256: 0feeeb51364ca104b9a81e93fa27070865c328a3ba05876cb66bd66b8a4a50a2

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

def read_bootdisk_template(filename)
  File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', filename))
end

def ensure_bootdisk_template(name, content)
  kind = TemplateKind.unscoped.where(name: 'Bootdisk').first_or_create
  tmpl = ProvisioningTemplate.unscoped.where(name: name).first_or_create do |template|
    template.attributes = {
      template_kind_id: kind.id,
      snippet: false,
      template: content
    }
  end
  tmpl.attributes = {
    template: content,
    default: true,
    vendor: "Foreman boot disk"
  }
  tmpl.locked = true
  tmpl.organizations = Organization.unscoped.all if SETTINGS[:organizations_enabled]
  tmpl.locations = Location.unscoped.all if SETTINGS[:locations_enabled]
  tmpl.save!(validate: false) if tmpl.changes.present?
end

ProvisioningTemplate.without_auditing do
  ensure_bootdisk_template("Boot disk iPXE - host", read_bootdisk_template("host.erb"))
  ensure_bootdisk_template("Boot disk iPXE - generic host", read_bootdisk_template("generic_host.erb"))
  ensure_bootdisk_template("Boot disk iPXE - generic static host", read_bootdisk_template("generic_static_host.erb"))
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_bootdisk-16.1.0 db/seeds.d/50-bootdisk_templates.rb
foreman_bootdisk-16.0.0 db/seeds.d/50-bootdisk_templates.rb