Class: Phase::CLI::Status

Inherits:
Command
  • Object
show all
Defined in:
lib/phase/cli/status.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #options

Instance Method Summary collapse

Methods inherited from Command

#initialize

Methods included from Util::Console

#ask, #fail, #log

Constructor Details

This class inherits a constructor from Phase::CLI::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/phase/cli/status.rb', line 59

def print_servers_table
  table  = ::Terminal::Table.new(title: "Instances")
  groups = @servers.group_by {|s| s.resource.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.resource.ready? ? :green : :light_red
      subnet = @subnets.find { |s| s.resource.subnet_id == subnet_id }
      subnet_name = subnet.resource.tag_set["Name"] || subnet.resource.tag_set["name"] if subnet

      add_row(table, color, [
        server.resource.id,
        server.resource.tags["Name"] || server.resource.tags["name"],
        server.resource.flavor_id,
        server.resource.state,
        server.resource.public_ip_address,
        server.resource.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/phase/cli/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.resource.state == "available" ? :green : :light_red
    add_row(table, color, [
      vpc.resource.id,
      vpc.resource.tags["Name"] || vpc.resource.tags["name"],
      vpc.resource.state,
      vpc.resource.cidr_block,
      vpc.resource.tenancy
    ])

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

    return unless subnets.any?

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

    puts table
  end
end

#runObject



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

def run
  @vpcs    = ::Phase::Adapters::AWS::Network.all
  @subnets = ::Phase::Adapters::AWS::Subnet.all
  @servers = ::Phase::Adapters::AWS::Server.all
  @elbs    = ::Phase::Adapters::AWS::LoadBalancer.all

  print_vpc_tables
  print_servers_table
end