template validation

This commit is contained in:
Anton Martynov 2015-08-21 19:03:53 +03:00
parent 83cb04ab85
commit 4804effc9f
4 changed files with 30 additions and 0 deletions

View File

@ -1,16 +1,21 @@
require 'tempfile'
require 'securerandom'
require "db/mongo/models/model_with_provider"
module Devops
module Model
class StackTemplateBase < MongoModel
include ModelWithProvider
attr_accessor :id, :template_body, :provider
types id: {type: String, empty: false},
provider: {type: String, empty: false},
template_body: {type: String, empty: false}
set_validators ::Validators::StackTemplate::TemplateContent
def initialize(attrs)
self.id = attrs['id']
self.template_body = attrs['template_body']

View File

@ -0,0 +1,15 @@
module Validators
class StackTemplate::TemplateContent < Base
def valid?
@model.provider_instance.validate_template(@model.template_body)
true
end
def message
"Invalid groups '#{@invalid_groups.join("', '")}'."
end
end
end

View File

@ -237,6 +237,11 @@ module Provider
end
end
def validate_stack_template template
r = cloud_formation.validate_template({'TemplateBody' => template})
pp r.body
end
def delete_stack(stack)
cloud_formation.delete_stack(stack.name)
end

View File

@ -224,6 +224,11 @@ module Provider
end
end
def validate_stack_template template
r = orchestration.validate_template({'template' => template})
pp r.body
end
def delete_stack(stack)
orchestration.delete_stack(Fog::Orchestration::OpenStack::Stack.new({'id' => stack.id, 'stack_name' => stack.name}))
end