-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute_table.go
71 lines (54 loc) · 1.73 KB
/
route_table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package window
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
type (
RouteTable struct {
// The associations between the route table and one or more subnets.
Associations []*ec2.RouteTableAssociation
// Any virtual private gateway (VGW) propagating routes.
PropagatingVgws []*ec2.PropagatingVgw
// The ID of the route table.
RouteTableId string
// The routes in the route table.
Routes []*ec2.Route
// Any tags assigned to the route table.
Tags []*ec2.Tag
// The ID of the VPC.
VpcId string
Name string
Id string
State string
}
RouteTableByNameAsc []*RouteTable
)
func (a RouteTableByNameAsc) Len() int { return len(a) }
func (a RouteTableByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a RouteTableByNameAsc) Less(i, j int) bool {
return string_less_than(a[i].Name, a[j].Name)
}
func LoadRouteTables(input *ec2.DescribeRouteTablesInput) (map[string]*RouteTable, error) {
resp, err := EC2Client.DescribeRouteTables(input)
if err != nil {
return nil, err
}
route_tables := make(map[string]*RouteTable, len(resp.RouteTables))
for _, ec2rt := range resp.RouteTables {
route_table := &RouteTable{
Associations: ec2rt.Associations,
PropagatingVgws: ec2rt.PropagatingVgws,
RouteTableId: aws.StringValue(ec2rt.RouteTableId),
Routes: ec2rt.Routes,
Tags: ec2rt.Tags,
VpcId: aws.StringValue(ec2rt.VpcId),
}
route_table.Name = TagOrDefault(route_table.Tags, "Name", route_table.RouteTableId)
route_table.Id = "rt:" + route_table.RouteTableId
route_tables[route_table.RouteTableId] = route_table
}
return route_tables, nil
}
func (rt *RouteTable) Inactive() bool {
return len(rt.Associations) == 0
}