lib/simple_deploy/stack.rb in simple_deploy-0.7.2 vs lib/simple_deploy/stack.rb in simple_deploy-0.7.3

- old
+ new

@@ -1,27 +1,39 @@ -require 'stackster' require 'simple_deploy/stack/deployment' require 'simple_deploy/stack/execute' require 'simple_deploy/stack/output_mapper' -require 'simple_deploy/stack/stack_attribute_formater' +require 'simple_deploy/stack/stack_attribute_formatter' +require 'simple_deploy/stack/stack_creator' +require 'simple_deploy/stack/stack_destroyer' +require 'simple_deploy/stack/stack_formatter' +require 'simple_deploy/stack/stack_lister' +require 'simple_deploy/stack/stack_reader' +require 'simple_deploy/stack/stack_updater' +require 'simple_deploy/stack/status' module SimpleDeploy class Stack def initialize(args) @environment = args[:environment] @name = args[:name] - @config = Config.new :logger => args[:logger] - @logger = @config.logger + @config = SimpleDeploy.config + @logger = SimpleDeploy.logger + @use_internal_ips = !!args[:internal] + @entry = Entry.new :name => @name end def create(args) - attributes = stack_attribute_formater.updated_attributes args[:attributes] - stack.create :attributes => attributes, - :template => args[:template] + attributes = stack_attribute_formatter.updated_attributes args[:attributes] + @template_file = args[:template] + + @entry.set_attributes attributes + stack_creator.create + + @entry.save end def update(args) if !deployment.clear_for_deployment? && args[:force] deployment.clear_deployment_lock true @@ -32,20 +44,42 @@ end end if deployment.clear_for_deployment? @logger.info "Updating #{@name}." - attributes = stack_attribute_formater.updated_attributes args[:attributes] - stack.update :attributes => attributes + attributes = stack_attribute_formatter.updated_attributes args[:attributes] + @template_body = template + + @entry.set_attributes attributes + stack_updater.update_stack_if_parameters_changed attributes @logger.info "Update complete for #{@name}." + + @entry.save true else @logger.info "Not clear to update." false end end + def in_progress_update(args) + if args[:caller].kind_of? Stack::Deployment::Status + @logger.info "Updating #{@name}." + attributes = stack_attribute_formatter.updated_attributes args[:attributes] + @template_body = template + + @entry.set_attributes attributes + stack_updater.update_stack_if_parameters_changed attributes + @logger.info "Update complete for #{@name}." + + @entry.save + true + else + false + end + end + def deploy(force = false) deployment.execute force end def execute(args) @@ -56,99 +90,117 @@ deployment.ssh end def destroy if attributes['protection'] != 'on' - stack.destroy + stack_destroyer.destroy + @entry.delete_attributes @logger.info "#{@name} destroyed." true else @logger.warn "#{@name} could not be destroyed because it is protected. Run the protect subcommand to unprotect it" false end end def events(limit) - stack.events limit + stack_reader.events limit end def outputs - stack.outputs + stack_reader.outputs end def resources - stack.resources + stack_reader.resources end def instances - stack.instances.map do |instance| + stack_reader.instances.map do |instance| instance['instancesSet'].map do |info| if info['vpcId'] || @use_internal_ips info['privateIpAddress'] else info['ipAddress'] end end end.flatten.compact end + def raw_instances + stack_reader.instances + end + def status - stack.status + stack_reader.status end def wait_for_stable - stack.wait_for_stable + stack_status.wait_for_stable end def exists? - stack.status + status true - rescue Stackster::Exceptions::UnknownStack + rescue Exceptions::UnknownStack false end def attributes - stack.attributes + stack_reader.attributes end def parameters - stack.parameters + stack_reader.parameters end def template - JSON.parse stack.template + stack_reader.template end private - def stack - stackster_config = @config.environment @environment - @stack ||= Stackster::Stack.new :name => @name, - :config => stackster_config, - :logger => @logger + def stack_creator + @stack_creator ||= StackCreator.new :name => @name, + :entry => @entry, + :template_file => @template_file end - - def stack_attribute_formater - @saf ||= StackAttributeFormater.new :config => @config, - :environment => @environment, - :main_attributes => attributes + + def stack_updater + @stack_updater ||= StackUpdater.new :name => @name, + :entry => @entry, + :template_body => @template_body end + def stack_reader + @stack_reader ||= StackReader.new :name => @name + end + + def stack_destroyer + @stack_destroyer ||= StackDestroyer.new :name => @name + end + + def stack_status + @status ||= Status.new :name => @name + end + + def stack_attribute_formatter + @saf ||= StackAttributeFormatter.new :main_attributes => attributes + end + def executer - @executer ||= Stack::Execute.new :config => @config, - :environment => @environment, + @executer ||= Stack::Execute.new :environment => @environment, :name => @name, - :stack => stack, + :stack => self, :instances => instances, :ssh_user => ssh_user, :ssh_key => ssh_key end def deployment - @deployment ||= Stack::Deployment.new :config => @config, - :environment => @environment, + @deployment ||= Stack::Deployment.new :environment => @environment, :name => @name, - :stack => stack, + :stack => self, :instances => instances, :ssh_user => ssh_user, :ssh_key => ssh_key end