Class: Stax::Cmd::Rds

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

Constant Summary collapse

COLORS =
{
  available: :green,
  Complete:  :green,
  Active:    :green,
}

Instance Method Summary collapse

Methods inherited from SubCommand

#info, stax_info, stax_info_tasks

Instance Method Details

#clustersObject



46
47
48
49
50
51
# File 'lib/stax/mixin/rds.rb', line 46

def clusters
  debug("RDS DB clusters for #{my.stack_name}")
  print_table stack_rds_clusters.map { |c|
    [c.db_cluster_identifier, c.engine, c.engine_version, color(c.status, COLORS), c.cluster_create_time]
  }
end

#endpointsObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/stax/mixin/rds.rb', line 73

def endpoints
  stack_rds_clusters.each do |c|
    debug("RDS DB endpoints for cluster #{c.db_cluster_identifier}")
    print_table [
      ['writer', c.endpoint,        c.port, c.hosted_zone_id],
      ['reader', c.reader_endpoint, c.port, c.hosted_zone_id],
    ]
  end

  debug("RDS DB instance endpoints for #{my.stack_name}")
  print_table stack_rds_instances.map { |i|
    [i.db_instance_identifier, i.endpoint&.address, i.endpoint&.port, i.endpoint&.hosted_zone_id]
  }
end

#instancesObject



65
66
67
68
69
70
# File 'lib/stax/mixin/rds.rb', line 65

def instances
  debug("RDS DB instances for #{my.stack_name}")
  print_table stack_rds_instances.map { |i|
    [i.db_instance_identifier, i.engine, i.engine_version, color(i.db_instance_status, COLORS), i.db_instance_class, i.db_subnet_group&.vpc_id, i.availability_zone]
  }
end

#membersObject



54
55
56
57
58
59
60
61
62
# File 'lib/stax/mixin/rds.rb', line 54

def members
  stack_rds_clusters.each do |c|
    debug("RDS DB members for cluster #{c.db_cluster_identifier}")
    print_table c.db_cluster_members.map { |m|
      role = m.is_cluster_writer ? 'writer' : 'reader'
      [m.db_instance_identifier, role, m.db_cluster_parameter_group_status]
    }
  end
end

#subnetsObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/stax/mixin/rds.rb', line 89

def subnets
  stack_db_subnet_groups.map do |r|
    Aws::Rds.subnet_groups(db_subnet_group_name: r.physical_resource_id)
  end.flatten.each do |g|
    debug("Subnets for group #{g.db_subnet_group_name}")
    print_table g.subnets.map { |s|
      [s&.subnet_availability_zone&.name, s&.subnet_identifier, color(s&.subnet_status, COLORS)]
    }
  end
end