Class: Stax::Cmd::Ec2

Inherits:
SubCommand show all
Defined in:
lib/stax/mixin/ec2.rb

Constant Summary collapse

COLORS =
{
  ## instances
  running:    :green,
  stopped:    :yellow,
  terminated: :red,
  ## images
  available: :green,
  pending:   :yellow,
  failed:    :red,
}

Instance Method Summary collapse

Methods inherited from SubCommand

#info, stax_info, stax_info_tasks

Instance Method Details

#lsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stax/mixin/ec2.rb', line 27

def ls
  debug("EC2 instances for #{my.stack_name}")
  print_table Aws::Ec2.instances(my.stack_name).map { |i|
    name = i.tags.find { |t| t.key == 'Name' }&.value
    [
      name,
      i.instance_id,
      i.instance_type,
      i.placement.availability_zone,
      color(i.state.name, COLORS),
      i.private_ip_address,
      i.public_ip_address
    ]
  }
end