Sha256: 30572b4f861c555bf9ee99752b1f05108f8b0a2a7d6901e49cdfc443c286f5ba

Contents?: true

Size: 1.62 KB

Versions: 25

Compression:

Stored size: 1.62 KB

Contents

require_relative '../model/cloudfile'
require_relative '../model/event'

module Convection
  module Control
    ##
    # Control tour Clouds
    ##
    class Cloud
      def configure(cloudfile)
        @cloudfile = Model::Cloudfile.new(cloudfile)
      end

      def stacks
        @cloudfile.stacks
      end

      def deck
        @cloudfile.deck
      end

      def converge(to_stack, &block)
        unless to_stack.nil? || stacks.include?(to_stack)
          block.call(Model::Event.new(:error, "Stack #{ to_stack } is not defined", :error)) if block
          return
        end

        deck.each do |stack|
          block.call(Model::Event.new(:converge, "Stack #{ stack.name }", :info)) if block
          stack.apply(&block)

          if stack.error?
            block.call(Model::Event.new(:error, "Error converging stack #{ stack.name }", :error), stack.errors) if block
            break
          end

          ## Stop on converge error
          break unless stack.success?

          ## Stop here
          break if !to_stack.nil? && stack.name == to_stack
          sleep rand @cloudfile.splay || 2
        end
      end

      def diff(&block)
        @cloudfile.deck.each do |stack|
          block.call(Model::Event.new(:compare, "Compare local state of stack #{ stack.name } (#{ stack.cloud_name }) with remote template", :info))
          sleep rand @cloudfile.splay || 2

          difference = stack.diff
          next block.call(Model::Event.new(:unchanged, "Stack #{ stack.cloud_name } Has no changes", :info)) if difference.empty?

          difference.each { |diff| block.call(diff) }
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
convection-0.2.25 lib/convection/control/cloud.rb
convection-0.2.24 lib/convection/control/cloud.rb
convection-0.2.23 lib/convection/control/cloud.rb
convection-0.2.22 lib/convection/control/cloud.rb
convection-0.2.21 lib/convection/control/cloud.rb
convection-0.2.20 lib/convection/control/cloud.rb
convection-0.2.19 lib/convection/control/cloud.rb
convection-0.2.18 lib/convection/control/cloud.rb
convection-0.2.17 lib/convection/control/cloud.rb
convection-0.2.16 lib/convection/control/cloud.rb
convection-0.2.15 lib/convection/control/cloud.rb
convection-0.2.14 lib/convection/control/cloud.rb
convection-0.2.13 lib/convection/control/cloud.rb
convection-0.2.12 lib/convection/control/cloud.rb
convection-0.2.11 lib/convection/control/cloud.rb
convection-0.2.10 lib/convection/control/cloud.rb
convection-0.2.9 lib/convection/control/cloud.rb
convection-0.2.8 lib/convection/control/cloud.rb
convection-0.2.7 lib/convection/control/cloud.rb
convection-0.2.6 lib/convection/control/cloud.rb