Class: Awry::Vpc
Constant Summary collapse
- COLORS =
{ active: :green, available: :green, deleted: :red, expired: :red, failed: :red, rejected: :red, }
Instance Method Summary collapse
- #delete(vpc_id) ⇒ Object
- #ls(prefix = nil) ⇒ Object
- #peers ⇒ Object
- #sg ⇒ Object
- #subnets(prefix = nil) ⇒ Object
Instance Method Details
#delete(vpc_id) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/awry/vpc.rb', line 66 def delete(vpc_id) if yes?("Really delete vpc #{vpc_id}?", :yellow) p client.delete_vpc(vpc_id: vpc_id) end rescue Aws::EC2::Errors::DependencyViolation => e error(e.) rescue Aws::EC2::Errors::InvalidVpcIDNotFound => e error(e.) end |
#ls(prefix = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/awry/vpc.rb', line 22 def ls(prefix = nil) client.describe_vpcs.map(&:vpcs).flatten.map do |v| [ tag_name(v, '-'), v.vpc_id, color(v.state), v.cidr_block ] end.tap do |list| list.select! { |l| l.first.start_with?(prefix) } if prefix end.tap do |list| print_table list.sort end end |
#peers ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/awry/vpc.rb', line 44 def peers client.describe_vpc_peering_connections.map(&:vpc_peering_connections).flatten.map do |p| [ tag_name(p, '-'), p.vpc_peering_connection_id, color(p.status.code), p.requester_vpc_info.vpc_id, p.accepter_vpc_info.vpc_id, p.requester_vpc_info.cidr_block, p.accepter_vpc_info.cidr_block, ] end.tap do |list| print_table list.sort end end |
#sg ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/awry/vpc.rb', line 57 def sg client.describe_security_groups.map(&:security_groups).flatten.map do |s| [ s.group_name, s.group_id, s.vpc_id, '→'+s..count.to_s, s..count.to_s+'→' ] end.tap do |list| print_table list.sort end end |
#subnets(prefix = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/awry/vpc.rb', line 33 def subnets(prefix = nil) client.describe_subnets.map(&:subnets).flatten.map do |s| [ tag_name(s, '') , s.subnet_id, color(s.state), s.vpc_id, s.cidr_block, s.availability_zone, s.availability_zone_id ] end.tap do |list| list.select! { |l| l.first.start_with?(prefix) } if prefix end.tap do |list| print_table list.sort end end |