template validation
This commit is contained in:
parent
83cb04ab85
commit
4804effc9f
@ -1,16 +1,21 @@
|
|||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
|
require "db/mongo/models/model_with_provider"
|
||||||
|
|
||||||
module Devops
|
module Devops
|
||||||
module Model
|
module Model
|
||||||
class StackTemplateBase < MongoModel
|
class StackTemplateBase < MongoModel
|
||||||
|
|
||||||
|
include ModelWithProvider
|
||||||
|
|
||||||
attr_accessor :id, :template_body, :provider
|
attr_accessor :id, :template_body, :provider
|
||||||
|
|
||||||
types id: {type: String, empty: false},
|
types id: {type: String, empty: false},
|
||||||
provider: {type: String, empty: false},
|
provider: {type: String, empty: false},
|
||||||
template_body: {type: String, empty: false}
|
template_body: {type: String, empty: false}
|
||||||
|
|
||||||
|
set_validators ::Validators::StackTemplate::TemplateContent
|
||||||
|
|
||||||
def initialize(attrs)
|
def initialize(attrs)
|
||||||
self.id = attrs['id']
|
self.id = attrs['id']
|
||||||
self.template_body = attrs['template_body']
|
self.template_body = attrs['template_body']
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
@ -237,6 +237,11 @@ module Provider
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_stack_template template
|
||||||
|
r = cloud_formation.validate_template({'TemplateBody' => template})
|
||||||
|
pp r.body
|
||||||
|
end
|
||||||
|
|
||||||
def delete_stack(stack)
|
def delete_stack(stack)
|
||||||
cloud_formation.delete_stack(stack.name)
|
cloud_formation.delete_stack(stack.name)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -224,6 +224,11 @@ module Provider
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_stack_template template
|
||||||
|
r = orchestration.validate_template({'template' => template})
|
||||||
|
pp r.body
|
||||||
|
end
|
||||||
|
|
||||||
def delete_stack(stack)
|
def delete_stack(stack)
|
||||||
orchestration.delete_stack(Fog::Orchestration::OpenStack::Stack.new({'id' => stack.id, 'stack_name' => stack.name}))
|
orchestration.delete_stack(Fog::Orchestration::OpenStack::Stack.new({'id' => stack.id, 'stack_name' => stack.name}))
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user