38 lines
918 B
Ruby
38 lines
918 B
Ruby
require 'lib/string_helper'
|
|
require 'db/mongo/models/stack_template/stack_template_factory'
|
|
|
|
module Devops
|
|
module StackTemplatePresets
|
|
class Base
|
|
|
|
def id
|
|
StringHelper.underscore_class(self.class)
|
|
end
|
|
|
|
def to_hash
|
|
{id: id, template_preset_body: template_preset_body}
|
|
end
|
|
|
|
def create_stack_from_preset(provider, stack_id, parameters)
|
|
stack_attrs = {
|
|
'id' => stack_id,
|
|
'provider' => provider,
|
|
'parameters' => parameters,
|
|
'template_body' => template_preset_body
|
|
}
|
|
Model::StackFactory.create(provider, stack_attrs)
|
|
end
|
|
|
|
def template_preset_body
|
|
file_name = File.join("lib/stack_template_presets/#{id}.#{template_file_extension}")
|
|
File.read(file_name)
|
|
end
|
|
|
|
# some templates may be YAML files
|
|
def template_file_extension
|
|
:json
|
|
end
|
|
|
|
end
|
|
end
|
|
end |