Sha256: 305e65e1c5ddaf295d81e2740994a99c85a2fcb4c982a54505eeb574f8fc00a7

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

module OpsTasks
  class Scale < OpsTasks::Deployment
    def initialize(args)
      @instance_type = args[:instance_type]
      super
    end

    def create_instance(auto_scale = false)
      args = { :stack_id => @stack_id,
               :layer_ids => [@layer_id],
               :instance_type => @instance_type }
      args[:auto_scale] = 'load' if auto_scale
      @client.create_instance(args)[:instance_id]
    end

    def start_instance(instance_id)
      @client.start_instance(
        :instance_id => instance_id
      )
    end

    def assess_status(instance_id)
      @client.describe_instances(
        :instance_ids => [instance_id]
      )[:instances].first[:status]
    end

    def deployment_failed?(instance_id)
      @client.describe_instances(
        :instance_ids => [instance_id]
      )[:instances].first[:status] == 'failed'
    end

    def poll_api_for_status(deployment_id)
      sleep 1 until assess_status(deployment_id) == 'online'
      puts assess_status(deployment_id)
    end

    def wait_for_completion(instance_id, task="create instance")
      print "#{@project}: Running... "
      announce_status(task, instance_id)
      poll_api_for_status(instance_id)
      announce_status(task, instance_id)
      announce_log(instance_id) if deployment_failed?(instance_id)
      Process.daemon if @run_in_background
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ops_tasks-0.5.4 lib/ops_tasks/scale.rb
ops_tasks-0.5.2 lib/ops_tasks/scale.rb
ops_tasks-0.5.0 lib/ops_tasks/scale.rb