Class: Exos::Commands::Status

Inherits:
Command
  • Object
show all
Defined in:
lib/exos/commands/status.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #options

Instance Method Summary collapse

Methods inherited from Command

#initialize

Constructor Details

This class inherits a constructor from Exos::Commands::Command

Instance Method Details



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/exos/commands/status.rb', line 59

def print_servers_table
  table  = ::Terminal::Table.new(title: "Instances")
  groups = @servers.group_by(&:subnet_id)

  add_section_headers(table, ["ID", "Name", "Type", "State", "Public IP", "Private IP", "Subnet Name"])

  groups.each_pair do |subnet_id, servers|
    servers.each do |server|
      color = server.ready? ? :green : :light_red
      subnet = @subnets.find { |s| s.subnet_id == subnet_id }
      subnet_name = subnet.tag_set["Name"] || subnet.tag_set["name"] if subnet

      add_row(table, color, [
        server.id,
        server.tags["Name"] || server.tags["name"],
        server.flavor_id,
        server.state,
        server.public_ip_address,
        server.private_ip_address,
        subnet_name
      ])
    end
  end

  puts table
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/exos/commands/status.rb', line 23

def print_vpc_tables
  @vpcs.each do |vpc|
    table = ::Terminal::Table.new(title: "VPC Status")

    add_section_headers(table, ["VPC ID", "Name", "State", "CIDR Block", "Tenancy"])
    color = vpc.state == "available" ? :green : :light_red
    add_row(table, color, [
      vpc.id,
      vpc.tags["Name"] || vpc.tags["name"],
      vpc.state,
      vpc.cidr_block,
      vpc.tenancy
    ])

    subnets = @subnets.select do |subnet|
      subnet.vpc_id == vpc.id
    end

    return unless subnets.any?

    add_section_headers(table, ["Subnet ID", "Name", "State", "CIDR Block", "Availability Zone"])
    subnets.each do |subnet|
      color = subnet.ready? ? :green : :light_red
      add_row(table, color, [
        subnet.subnet_id,
        subnet.tag_set["Name"] || subnet.tag_set["name"],
        subnet.state,
        subnet.cidr_block,
        subnet.availability_zone
      ])
    end

    puts table
  end
end

#runObject



13
14
15
16
17
18
19
20
21
# File 'lib/exos/commands/status.rb', line 13

def run
  @vpcs    = ec2.vpcs
  @subnets = ec2.subnets
  @servers = ec2.servers
  @elbs    = elb.load_balancers

  print_vpc_tables
  print_servers_table
end