in scripts/gen_vpc_ip_limits.go [133:196]
func describeInstanceTypes(ctx context.Context, cfg aws.Config, region string, eniLimitMap map[string]vpc.InstanceTypeLimits) {
log.Infof("Describing instance types in region=%s", region)
cfg.Region = region
client := ec2.NewFromConfig(cfg)
paginator := ec2.NewDescribeInstanceTypesPaginator(client, &ec2.DescribeInstanceTypesInput{})
// Iterate through all pages
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
log.Fatalf("Failed to call EC2 DescribeInstanceTypes: %v", err)
}
// We just want the type name, ENI and IP limits
for _, info := range output.InstanceTypes {
// Ignore any missing values
instanceType := string(info.InstanceType)
// only one network card is supported, so use the MaximumNetworkInterfaces from the default card if more than one are present
var eniLimit int
if len(info.NetworkInfo.NetworkCards) > 1 {
eniLimit = int(*info.NetworkInfo.NetworkCards[*info.NetworkInfo.DefaultNetworkCardIndex].MaximumNetworkInterfaces)
} else {
eniLimit = int(*info.NetworkInfo.MaximumNetworkInterfaces)
}
ipv4Limit := int(*info.NetworkInfo.Ipv4AddressesPerInterface)
isBareMetalInstance := *info.BareMetal
hypervisorType := string(info.Hypervisor)
if hypervisorType == "" {
hypervisorType = "unknown"
}
networkCards := make([]vpc.NetworkCard, *info.NetworkInfo.MaximumNetworkCards)
defaultNetworkCardIndex := int(*info.NetworkInfo.DefaultNetworkCardIndex)
for idx := 0; idx < len(networkCards); idx++ {
networkCards[idx] = vpc.NetworkCard{
MaximumNetworkInterfaces: int64(*info.NetworkInfo.NetworkCards[idx].MaximumNetworkInterfaces),
NetworkCardIndex: int64(*info.NetworkInfo.NetworkCards[idx].NetworkCardIndex),
}
}
if instanceType != "" && eniLimit > 0 && ipv4Limit > 0 {
limits := vpc.InstanceTypeLimits{
ENILimit: eniLimit,
IPv4Limit: ipv4Limit,
NetworkCards: networkCards,
HypervisorType: strconv.Quote(hypervisorType),
IsBareMetal: isBareMetalInstance,
DefaultNetworkCardIndex: defaultNetworkCardIndex,
}
if existingLimits, contains := eniLimitMap[instanceType]; contains && !reflect.DeepEqual(existingLimits, limits) {
// this should never happen
log.Fatalf("A previous region has different limits for instanceType=%s than region=%s", instanceType, region)
}
eniLimitMap[instanceType] = limits
}
}
}
}