Sha256: fcdb3e42572f860e02c38b46bc0dd5bbe053855ff1585ba344144fd731722cf9

Contents?: true

Size: 1023 Bytes

Versions: 11

Compression:

Stored size: 1023 Bytes

Contents

require 'terminal-table'

module Opsicle
  class ListInstances
    attr_reader :client, :layers

    def initialize(environment)
      @client = Client.new(environment)
    end

    def execute(options={})
      get_layers
      print(get_instances)
    end

    def get_layers
      @layers = client.api_call('describe_layers', stack_id: @client.config.opsworks_config[:stack_id])[:layers]
    end

    def get_instances
      Opsicle::Instances.new(client).data
    end

    def print(instances)
      puts Terminal::Table.new headings: ['Hostname', 'Layers', 'Status', 'Instance ID'], rows: instance_data(instances)
    end

    def instance_data(instances)
      instances.map{|instance| [instance[:hostname], layer_names(instance), instance[:status], instance[:instance_id]] }
    end

    def layer_names(instance)
      instance[:layer_ids].map{ |layer_id| layer_name(layer_id) }.join(" | ")
    end

    def layer_name(layer_id)
      layers.detect{ |layer| layer[:layer_id] == layer_id }[:name]
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
opsicle-0.11.0 lib/opsicle/commands/list_instances.rb
opsicle-0.10.0 lib/opsicle/commands/list_instances.rb
opsicle-0.9.0 lib/opsicle/commands/list_instances.rb
opsicle-0.8.2 lib/opsicle/commands/list_instances.rb
opsicle-0.8.1 lib/opsicle/commands/list_instances.rb
opsicle-0.8.0 lib/opsicle/commands/list_instances.rb
opsicle-0.7.1 lib/opsicle/commands/list_instances.rb
opsicle-0.7.0 lib/opsicle/commands/list_instances.rb
opsicle-0.6.0 lib/opsicle/commands/list_instances.rb
opsicle-0.5.1 lib/opsicle/commands/list_instances.rb
opsicle-0.5.0 lib/opsicle/commands/list_instances.rb