class Opsicle::ListInstances

Attributes

client[R]

Public Class Methods

new(environment) click to toggle source
# File lib/opsicle/commands/list_instances.rb, line 7
def initialize(environment)
  @client = Client.new(environment)
  @stack = Stack.new(@client)
end

Public Instance Methods

execute(options={}) click to toggle source
# File lib/opsicle/commands/list_instances.rb, line 12
def execute(options={})
  print(get_instances)
end
get_instances() click to toggle source
# File lib/opsicle/commands/list_instances.rb, line 16
def get_instances
  Opsicle::Instances.new(client).data
end
instance_data(instances) click to toggle source
# File lib/opsicle/commands/list_instances.rb, line 35
def instance_data(instances)
  instances
    .sort { |a,b| a[:hostname] <=> b[:hostname] }
    .map do |instance|
      [
        instance[:hostname],
        instance[:instance_type],
        layer_names(instance),
        instance[:status],
        Opsicle::Instances::pretty_ip(instance),
        Opsicle::Instances::private_ip(instance),
        instance[:availability_zone]
      ]
    end
end
layer_names(instance) click to toggle source
# File lib/opsicle/commands/list_instances.rb, line 51
def layer_names(instance)
  instance[:layer_ids].map{ |layer_id| @stack.layer_name(layer_id) }.join(" | ")
end
print(instances) click to toggle source