-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnat_gateway.go
More file actions
131 lines (108 loc) · 4.1 KB
/
nat_gateway.go
File metadata and controls
131 lines (108 loc) · 4.1 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package window
import (
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
type (
NATGateway struct {
// The date and time the NAT gateway was created.
CreateTime time.Time
// The date and time the NAT gateway was deleted, if applicable.
DeleteTime time.Time
// If the NAT gateway could not be created, specifies the error code for the
// failure. (InsufficientFreeAddressesInSubnet | Gateway.NotAttached | InvalidAllocationID.NotFound
// | Resource.AlreadyAssociated | InternalError | InvalidSubnetID.NotFound)
FailureCode string
// If the NAT gateway could not be created, specifies the error message for
// the failure, that corresponds to the error code.
//
// For InsufficientFreeAddressesInSubnet: "Subnet has insufficient free addresses
// to create this NAT gateway"
//
// For Gateway.NotAttached: "Network vpc-xxxxxxxx has no Internet gateway attached"
//
// For InvalidAllocationID.NotFound: "Elastic IP address eipalloc-xxxxxxxx
// could not be associated with this NAT gateway"
//
// For Resource.AlreadyAssociated: "Elastic IP address eipalloc-xxxxxxxx is
// already associated"
//
// For InternalError: "Network interface eni-xxxxxxxx, created and used internally
// by this NAT gateway is in an invalid state. Please try again."
//
// For InvalidSubnetID.NotFound: "The specified subnet subnet-xxxxxxxx does
// not exist or could not be found."
FailureMessage string
// Information about the IP addresses and network interface associated with
// the NAT gateway.
NATGatewayAddresses []*ec2.NatGatewayAddress
// The ID of the NAT gateway.
NATGatewayId string
// Reserved. If you need to sustain traffic greater than the documented limits
// (http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html),
// contact us through the Support Center (https://console.aws.amazon.com/support/home?).
ProvisionedBandwidth *ec2.ProvisionedBandwidth
// The state of the NAT gateway.
//
// pending: The NAT gateway is being created and is not ready to process
// traffic.
//
// failed: The NAT gateway could not be created. Check the failureCode and
// failureMessage fields for the reason.
//
// available: The NAT gateway is able to process traffic. This status remains
// until you delete the NAT gateway, and does not indicate the health of the
// NAT gateway.
//
// deleting: The NAT gateway is in the process of being terminated and may
// still be processing traffic.
//
// deleted: The NAT gateway has been terminated and is no longer processing
// traffic.
State string
// The ID of the subnet in which the NAT gateway is located.
SubnetId string
// The ID of the VPC in which the NAT gateway is located.
VpcId string
Name string
Id string
Region *Region
VPC *VPC
Subnet *Subnet
}
NATGatewaysByNameAsc []*NATGateway
)
func (a NATGatewaysByNameAsc) Len() int { return len(a) }
func (a NATGatewaysByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a NATGatewaysByNameAsc) Less(i, j int) bool {
return string_less_than(a[i].Name, a[j].Name)
}
func LoadNATGateways(input *ec2.DescribeNatGatewaysInput) (map[string]*NATGateway, error) {
resp, err := EC2Client.DescribeNatGateways(input)
if err != nil {
return nil, err
}
ngs := map[string]*NATGateway{}
for _, g := range resp.NatGateways {
ng := &NATGateway{
CreateTime: aws.TimeValue(g.CreateTime),
DeleteTime: aws.TimeValue(g.DeleteTime),
FailureCode: aws.StringValue(g.FailureCode),
FailureMessage: aws.StringValue(g.FailureMessage),
NATGatewayAddresses: g.NatGatewayAddresses,
NATGatewayId: aws.StringValue(g.NatGatewayId),
ProvisionedBandwidth: g.ProvisionedBandwidth,
State: aws.StringValue(g.State),
SubnetId: aws.StringValue(g.SubnetId),
VpcId: aws.StringValue(g.VpcId),
}
ng.Name = ng.NATGatewayId
ng.Id = "nat:" + ng.NATGatewayId
ngs[ng.NATGatewayId] = ng
}
return ngs, nil
}
func (natgw *NATGateway) Inactive() bool {
return natgw.State != "available"
}