Sha256: 6943361db6e251a40774dcdb0e671f3cc5467494d98806047079c76a4aa0709a

Contents?: true

Size: 1.89 KB

Versions: 4

Compression:

Stored size: 1.89 KB

Contents

require 'aws-sdk'
require 'colorize'
require 'opsworks_rolling_deploy/clients'

module OpsworksRollingDeploy
  module Services
    class DescribeService
      include OpsworksRollingDeploy::Clients

      def describe(stack_name, app_name, layer_name)
        ops_client.describe_stacks.stacks.each do |stack|
          next if stack_name and stack_name != stack.name
          puts "STACK = #{stack.name.green} #{stack.stack_id}"
          describe_stack_apps(stack, app_name)
          describe_stack_layers(stack, layer_name)
        end
        true
      end

      protected

      def describe_stack_apps(stack, app_name)
        puts " APPS:" 
        ops_client.describe_apps(stack_id: stack.stack_id).apps.each do |app|
          next if app_name and app_name != app.name
          puts "   APP: #{app.name.cyan} #{app.app_id} #{app.type}@#{app.app_source[:revision].to_s.magenta}"
        end
      end

      def describe_stack_layers(stack, layer_name)
        puts " LAYERS:"
        ops_client.describe_layers(stack_id: stack.stack_id).layers.each do |layer|
          next if layer_name and layer_name != layer.name
          describe_layer(layer)
        end
      end

      def describe_layer(layer)
        puts "   layer: #{layer.name.blue} #{layer.layer_id}"
        ops_client.describe_elastic_load_balancers(layer_ids:  [layer.layer_id]).elastic_load_balancers.each do |elb|
          puts "      ELB: #{elb.elastic_load_balancer_name.red} "
          describe_instance_health(elb) if elb.ec2_instance_ids.any?
        end
      end

      def describe_instance_health(elb)
        elb_client(elb.region).describe_instance_health({
          load_balancer_name: elb.elastic_load_balancer_name,
          instances: elb.ec2_instance_ids.map{ |id| {instance_id: id} }
          }).instance_states.each do |state|
          puts "      #{state.instance_id}: #{state.state}"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opsworks_rolling_deploy-0.2.0 lib/opsworks_rolling_deploy/services/describe_service.rb
opsworks_rolling_deploy-0.1.5 lib/opsworks_rolling_deploy/services/describe_service.rb
opsworks_rolling_deploy-0.1.4 lib/opsworks_rolling_deploy/services/describe_service.rb
opsworks_rolling_deploy-0.1.3 lib/opsworks_rolling_deploy/services/describe_service.rb