Class: Awful::Vpc
Constant Summary
collapse
- COLORS =
{
active: :green,
available: :green,
deleted: :red,
expired: :red,
failed: :red,
rejected: :red,
}
Instance Method Summary
collapse
Methods inherited from Cli
#initialize, #ll, #version
Constructor Details
This class inherits a constructor from Awful::Cli
Instance Method Details
#delete(vpc_id) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/awful/vpc.rb', line 37
def delete(vpc_id)
if yes?("Really delete vpc #{vpc_id}?", :yellow)
p ec2.delete_vpc(vpc_id: vpc_id)
end
rescue Aws::EC2::Errors::DependencyViolation => e
error(e.message)
rescue Aws::EC2::Errors::InvalidVpcIDNotFound => e
error(e.message)
end
|
#dump(name) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/awful/vpc.rb', line 28
def dump(name)
ec2.describe_vpcs.map(&:vpcs).flatten.find do |vpc|
vpc.vpc_id == name or vpc.tags.any? { |tag| tag.value == name }
end.tap do |vpc|
puts YAML.dump(stringify_keys(vpc.to_hash))
end
end
|
#ls(name = /./) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/awful/vpc.rb', line 14
def ls(name = /./)
fields = options[:long] ?
->(v) { [tag_name(v), v.vpc_id, color(v.state), v.cidr_block] } :
->(v) { [v.vpc_id] }
ec2.describe_vpcs.map(&:vpcs).flatten.select do |vpc|
vpc.tags.any? { |tag| tag.value.match(name) }
end.map do |vpc|
fields.call(vpc)
end.tap do |list|
print_table list
end
end
|
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/awful/vpc.rb', line 48
def peers
ec2.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
|