2016-01-28 18:15:06 +03:00
|
|
|
require 'securerandom'
|
|
|
|
|
|
2015-03-06 12:20:30 +03:00
|
|
|
module Devops
|
|
|
|
|
module Model
|
|
|
|
|
class StackTemplateEc2 < StackTemplateBase
|
2015-02-12 13:01:05 +03:00
|
|
|
|
2015-04-16 17:54:40 +03:00
|
|
|
# In Amazon Cloudformation the template file must be stored on an Amazon S3 bucket.
|
|
|
|
|
attr_accessor :template_url
|
|
|
|
|
|
|
|
|
|
def initialize(attrs)
|
|
|
|
|
self.template_url = attrs['template_url']
|
|
|
|
|
super(attrs)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def to_hash_without_id
|
|
|
|
|
super.merge(template_url: template_url)
|
|
|
|
|
end
|
|
|
|
|
|
2016-01-28 18:15:06 +03:00
|
|
|
def update_template_url
|
|
|
|
|
uniq_filename = "#{id}-#{SecureRandom.hex}.template"
|
|
|
|
|
s3_file = provider_instance.store_stack_template(uniq_filename, template_body)
|
|
|
|
|
self.template_url = s3_file['url']
|
2015-03-06 12:20:30 +03:00
|
|
|
end
|
|
|
|
|
|
2016-01-28 18:15:06 +03:00
|
|
|
def parse_parameters
|
|
|
|
|
template_hash = JSON.parse(template_body)
|
|
|
|
|
return {} unless template_hash['Parameters']
|
|
|
|
|
|
|
|
|
|
parameters = {}
|
|
|
|
|
template_hash['Parameters'].each do |param_name, param_info|
|
|
|
|
|
# use String always for now
|
|
|
|
|
parameters[param_name] = {'type' => 'String', 'description' => param_info['Description']}
|
|
|
|
|
end
|
|
|
|
|
parameters
|
|
|
|
|
rescue
|
|
|
|
|
{}
|
2016-01-27 15:44:59 +03:00
|
|
|
end
|
2016-01-21 20:10:36 +03:00
|
|
|
|
2016-01-27 15:44:59 +03:00
|
|
|
class << self
|
2015-04-16 17:54:40 +03:00
|
|
|
def create(attrs)
|
2016-01-27 15:44:59 +03:00
|
|
|
model = super(attrs)
|
|
|
|
|
model.update_template_url
|
|
|
|
|
model
|
2015-04-16 17:54:40 +03:00
|
|
|
end
|
2016-01-27 15:44:59 +03:00
|
|
|
end
|
2015-04-16 17:54:40 +03:00
|
|
|
|
2015-02-12 13:01:05 +03:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|