Sha256: ac8371d49dfc1b4458b6a2c988f1c269de4f2427879f1ea00417640e59d3e266

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

kind = TemplateKind.unscoped.where(name: 'Bootdisk').first_or_create

organizations = Organization.all
locations = Location.all
created = []

ProvisioningTemplate.without_auditing do
  content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'host.erb'))
  created << 'Boot disk iPXE - host' unless ProvisioningTemplate.find_by(name: 'Boot disk iPXE - host')
  tmpl = ProvisioningTemplate.unscoped.where(name: 'Boot disk iPXE - host').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.save!(validate: false) if tmpl.changes.present?

  content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'generic_host.erb'))
  created << 'Boot disk iPXE - generic host' unless ProvisioningTemplate.find_by(name: 'Boot disk iPXE - generic host')
  tmpl = ProvisioningTemplate.unscoped.where(name: 'Boot disk iPXE - generic host').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.save!(validate: false) if tmpl.changes.present?

  ProvisioningTemplate.unscoped.where(name: created, default: true).each do |template|
    template.organizations = organizations if SETTINGS[:organizations_enabled]
    template.locations = locations if SETTINGS[:locations_enabled]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_bootdisk-15.1.0 db/seeds.d/50-bootdisk_templates.rb
foreman_bootdisk-15.0.0 db/seeds.d/50-bootdisk_templates.rb
foreman_bootdisk-14.0.0 db/seeds.d/50-bootdisk_templates.rb