fluke/devops-service/db/mongo/models/stack_template/stack_template_ec2.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

2015-03-06 12:20:30 +03:00
module Devops
module Model
class StackTemplateEc2 < StackTemplateBase
2015-02-12 13:01:05 +03:00
# In Amazon Cloudformation the template file must be stored on an Amazon S3 bucket.
attr_accessor :template_url
2015-11-03 11:46:54 +03:00
# types template_url: {type: String, empty: false}
def initialize(attrs)
self.template_url = attrs['template_url']
super(attrs)
end
def to_hash_without_id
super.merge(template_url: template_url)
end
2015-03-06 12:20:30 +03:00
def delete_template_file_from_storage
raise 'Implement me'
end
2015-12-15 18:56:14 +03:00
def update_template_url
self.template_url = generate_template_file_and_upload_to_storage(id, template_body)
end
2015-12-15 18:56:14 +03:00
class << self
def create(attrs)
2015-12-15 19:36:33 +03:00
model = super(attrs)
model.update_template_url
model
end
2015-12-15 18:56:14 +03:00
end
2015-12-15 18:56:14 +03:00
private
2015-02-12 13:01:05 +03:00
def generate_template_file_and_upload_to_storage(id, json)
2015-12-15 18:56:14 +03:00
uniq_filename = "#{id}-#{SecureRandom.hex}.template"
provider_instance.store_stack_template(uniq_filename, json)['url']
2015-03-06 12:20:30 +03:00
end
2015-02-12 13:01:05 +03:00
end
end
end