Project

General

Profile

Download (2.37 KB) Statistics
| Branch: | Tag: | Revision:
cab0d8c6 Ohad Levy
class AddDefaultTemplates < ActiveRecord::Migration
def self.up
TemplateKind.all.each do |kind|
case kind.name
when /provision/
ConfigTemplate.create(
:name => "Kickstart Default",
:template_kind_id => kind.id,
:operatingsystem_ids => Redhat.all.map(&:id),
1603b08d Ohad Levy
:template => File.read("#{Rails.root}/app/views/unattended/kickstart.rhtml"))
cab0d8c6 Ohad Levy
ConfigTemplate.create(
:name => "Preseed Default",
:template_kind_id => kind.id,
:operatingsystem_ids => Debian.all.map(&:id),
1603b08d Ohad Levy
:template => File.read("#{Rails.root}/app/views/unattended/preseed.rhtml"))
cab0d8c6 Ohad Levy
when /finish/
ConfigTemplate.create(
:name => "Preseed Default Finish",
:template_kind_id => kind.id,
:operatingsystem_ids => Debian.all.map(&:id),
1603b08d Ohad Levy
:template => File.read("#{Rails.root}/app/views/unattended/preseed_finish.rhtml"))
cab0d8c6 Ohad Levy
when /pxelinux/i
ConfigTemplate.create(
:name => "Kickstart default PXElinux",
:template_kind_id => kind.id,
:operatingsystem_ids => Redhat.all.map(&:id),
1603b08d Ohad Levy
:template => File.read("#{Rails.root}/app/views/unattended/pxe_kickstart_config.erb"))
cab0d8c6 Ohad Levy
ConfigTemplate.create(
:name => "Preseed default PXElinux",
:template_kind_id => kind.id,
:operatingsystem_ids => Debian.all.map(&:id),
1603b08d Ohad Levy
:template => File.read("#{Rails.root}/app/views/unattended/pxe_debian_config.erb"))
cab0d8c6 Ohad Levy
when /gpxe/i
ConfigTemplate.create(
:name => "Kickstart default gPXE",
:template_kind_id => kind.id,
:operatingsystem_ids => Redhat.all.map(&:id),
1603b08d Ohad Levy
:template => File.read("#{Rails.root}/app/views/unattended/gpxe_kickstart_config.erb"))
cab0d8c6 Ohad Levy
end

end
1603b08d Ohad Levy
Dir["#{Rails.root}/app/views/unattended/snippets/*"].each do |snippet|
cab0d8c6 Ohad Levy
ConfigTemplate.create(
05c8a270 David Swift
:name => snippet.gsub(/.*\/_/,"").gsub(".erb",""),
cab0d8c6 Ohad Levy
:template => File.read(snippet),
:snippet => true)
end
rescue Exception => e
# something bad happened, but we don't want to break the migration process
90bd4eb6 Ohad Levy
Rails.logger.warn "Failed to migrate #{e}"
cab0d8c6 Ohad Levy
return true
end

def self.down
end
end