Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add network and disk filter flags #123

Merged
merged 2 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 65 additions & 44 deletions README.md

Large diffs are not rendered by default.

139 changes: 86 additions & 53 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,41 @@ const (

// Filter Flag Constants
const (
vcpus = "vcpus"
memory = "memory"
vcpusToMemoryRatio = "vcpus-to-memory-ratio"
cpuArchitecture = "cpu-architecture"
gpus = "gpus"
gpuMemoryTotal = "gpu-memory-total"
placementGroupStrategy = "placement-group-strategy"
usageClass = "usage-class"
rootDeviceType = "root-device-type"
enaSupport = "ena-support"
efaSupport = "efa-support"
hibernationSupport = "hibernation-support"
baremetal = "baremetal"
fpgaSupport = "fpga-support"
burstSupport = "burst-support"
hypervisor = "hypervisor"
availabilityZones = "availability-zones"
currentGeneration = "current-generation"
networkInterfaces = "network-interfaces"
networkPerformance = "network-performance"
allowList = "allow-list"
denyList = "deny-list"
virtualizationType = "virtualization-type"
pricePerHour = "price-per-hour"
vcpus = "vcpus"
memory = "memory"
vcpusToMemoryRatio = "vcpus-to-memory-ratio"
cpuArchitecture = "cpu-architecture"
gpus = "gpus"
gpuMemoryTotal = "gpu-memory-total"
inferenceAccelerators = "inference-accelerators"
placementGroupStrategy = "placement-group-strategy"
usageClass = "usage-class"
rootDeviceType = "root-device-type"
enaSupport = "ena-support"
efaSupport = "efa-support"
hibernationSupport = "hibernation-support"
baremetal = "baremetal"
fpgaSupport = "fpga-support"
burstSupport = "burst-support"
hypervisor = "hypervisor"
availabilityZones = "availability-zones"
currentGeneration = "current-generation"
networkInterfaces = "network-interfaces"
networkPerformance = "network-performance"
networkEncryption = "network-encryption"
ipv6 = "ipv6"
allowList = "allow-list"
denyList = "deny-list"
virtualizationType = "virtualization-type"
pricePerHour = "price-per-hour"
instanceStorage = "instance-storage"
diskType = "disk-type"
diskEncryption = "disk-encryption"
nvme = "nvme"
ebsOptimized = "ebs-optimized"
ebsOptimizedBaselineBandwidth = "ebs-optimized-baseline-bandwidth"
ebsOptimizedBaselineThroughput = "ebs-optimized-baseline-throughput"
ebsOptimizedBaselineIOPS = "ebs-optimized-baseline-iops"
)

// Aggregate Filter Flags
Expand Down Expand Up @@ -137,6 +148,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
cli.StringOptionsFlag(cpuArchitecture, cli.StringMe("a"), nil, "CPU architecture [x86_64/amd64, x86_64_mac, i386, or arm64]", []string{"x86_64", "x86_64_mac", "amd64", "i386", "arm64"})
cli.IntMinMaxRangeFlags(gpus, cli.StringMe("g"), nil, "Total Number of GPUs (Example: 4)")
cli.ByteQuantityMinMaxRangeFlags(gpuMemoryTotal, nil, nil, "Number of GPUs' total memory (Example: 4 GiB)")
cli.IntMinMaxRangeFlags(inferenceAccelerators, nil, nil, "Total Number of inference accelerators (Example: 4)")
cli.StringOptionsFlag(placementGroupStrategy, nil, nil, "Placement group strategy: [cluster, partition, spread]", []string{"cluster", "partition", "spread"})
cli.StringOptionsFlag(usageClass, cli.StringMe("u"), nil, "Usage class: [spot or on-demand]", []string{"spot", "on-demand"})
cli.StringOptionsFlag(rootDeviceType, nil, nil, "Supported root device types: [ebs or instance-store]", []string{"ebs", "instance-store"})
Expand All @@ -151,10 +163,20 @@ Full docs can be found at github.com/aws/amazon-` + binName
cli.BoolFlag(currentGeneration, nil, nil, "Current generation instance types (explicitly set this to false to not return current generation instance types)")
cli.IntMinMaxRangeFlags(networkInterfaces, nil, nil, "Number of network interfaces (ENIs) that can be attached to the instance")
cli.IntMinMaxRangeFlags(networkPerformance, nil, nil, "Bandwidth in Gib/s of network performance (Example: 100)")
cli.BoolFlag(networkEncryption, nil, nil, "Instance Types that support automatic network encryption in-transit")
cli.BoolFlag(ipv6, nil, nil, "Instance Types that support IPv6")
cli.RegexFlag(allowList, nil, nil, "List of allowed instance types to select from w/ regex syntax (Example: m[3-5]\\.*)")
cli.RegexFlag(denyList, nil, nil, "List of instance types which should be excluded w/ regex syntax (Example: m[1-2]\\.*)")
cli.StringOptionsFlag(virtualizationType, nil, nil, "Virtualization Type supported: [hvm or pv]", []string{"hvm", "paravirtual", "pv"})
cli.Float64MinMaxRangeFlags(pricePerHour, nil, nil, "Price/hour in USD (Example: 0.09)")
cli.ByteQuantityMinMaxRangeFlags(instanceStorage, nil, nil, "Amount of local instance storage (Example: 4 GiB)")
cli.StringOptionsFlag(diskType, nil, nil, "Disk Type: [hdd or ssd]", []string{"hdd", "ssd"})
cli.BoolFlag(nvme, nil, nil, "EBS or local instance storage where NVME is supported or required")
cli.BoolFlag(diskEncryption, nil, nil, "EBS or local instance storage where encryption is supported or required")
cli.BoolFlag(ebsOptimized, nil, nil, "EBS Optimized is supported or default")
cli.ByteQuantityMinMaxRangeFlags(ebsOptimizedBaselineBandwidth, nil, nil, "EBS Optimized baseline bandwidth (Example: 4 GiB)")
cli.ByteQuantityMinMaxRangeFlags(ebsOptimizedBaselineThroughput, nil, nil, "EBS Optimized baseline throughput per second (Example: 4 GiB)")
cli.IntMinMaxRangeFlags(ebsOptimizedBaselineIOPS, nil, nil, "EBS Optimized baseline IOPS per second (Example: 10000)")

// Suite Flags - higher level aggregate filters that return opinionated result

Expand Down Expand Up @@ -230,35 +252,46 @@ Full docs can be found at github.com/aws/amazon-` + binName
}

filters := selector.Filters{
VCpusRange: cli.IntRangeMe(flags[vcpus]),
MemoryRange: cli.ByteQuantityRangeMe(flags[memory]),
VCpusToMemoryRatio: cli.Float64Me(flags[vcpusToMemoryRatio]),
CPUArchitecture: cli.StringMe(flags[cpuArchitecture]),
GpusRange: cli.IntRangeMe(flags[gpus]),
GpuMemoryRange: cli.ByteQuantityRangeMe(flags[gpuMemoryTotal]),
PlacementGroupStrategy: cli.StringMe(flags[placementGroupStrategy]),
UsageClass: cli.StringMe(flags[usageClass]),
RootDeviceType: cli.StringMe(flags[rootDeviceType]),
EnaSupport: cli.BoolMe(flags[enaSupport]),
EfaSupport: cli.BoolMe(flags[efaSupport]),
HibernationSupported: cli.BoolMe(flags[hibernationSupport]),
Hypervisor: cli.StringMe(flags[hypervisor]),
BareMetal: cli.BoolMe(flags[baremetal]),
Fpga: cli.BoolMe(flags[fpgaSupport]),
Burstable: cli.BoolMe(flags[burstSupport]),
Region: cli.StringMe(flags[region]),
AvailabilityZones: cli.StringSliceMe(flags[availabilityZones]),
CurrentGeneration: cli.BoolMe(flags[currentGeneration]),
MaxResults: cli.IntMe(flags[maxResults]),
NetworkInterfaces: cli.IntRangeMe(flags[networkInterfaces]),
NetworkPerformance: cli.IntRangeMe(flags[networkPerformance]),
AllowList: cli.RegexMe(flags[allowList]),
DenyList: cli.RegexMe(flags[denyList]),
InstanceTypeBase: cli.StringMe(flags[instanceTypeBase]),
Flexible: cli.BoolMe(flags[flexible]),
Service: cli.StringMe(flags[service]),
VirtualizationType: cli.StringMe(flags[virtualizationType]),
PricePerHour: cli.Float64RangeMe(flags[pricePerHour]),
VCpusRange: cli.IntRangeMe(flags[vcpus]),
MemoryRange: cli.ByteQuantityRangeMe(flags[memory]),
VCpusToMemoryRatio: cli.Float64Me(flags[vcpusToMemoryRatio]),
CPUArchitecture: cli.StringMe(flags[cpuArchitecture]),
GpusRange: cli.IntRangeMe(flags[gpus]),
GpuMemoryRange: cli.ByteQuantityRangeMe(flags[gpuMemoryTotal]),
InferenceAcceleratorsRange: cli.IntRangeMe(flags[inferenceAccelerators]),
PlacementGroupStrategy: cli.StringMe(flags[placementGroupStrategy]),
UsageClass: cli.StringMe(flags[usageClass]),
RootDeviceType: cli.StringMe(flags[rootDeviceType]),
EnaSupport: cli.BoolMe(flags[enaSupport]),
EfaSupport: cli.BoolMe(flags[efaSupport]),
HibernationSupported: cli.BoolMe(flags[hibernationSupport]),
Hypervisor: cli.StringMe(flags[hypervisor]),
BareMetal: cli.BoolMe(flags[baremetal]),
Fpga: cli.BoolMe(flags[fpgaSupport]),
Burstable: cli.BoolMe(flags[burstSupport]),
Region: cli.StringMe(flags[region]),
AvailabilityZones: cli.StringSliceMe(flags[availabilityZones]),
CurrentGeneration: cli.BoolMe(flags[currentGeneration]),
MaxResults: cli.IntMe(flags[maxResults]),
NetworkInterfaces: cli.IntRangeMe(flags[networkInterfaces]),
NetworkPerformance: cli.IntRangeMe(flags[networkPerformance]),
NetworkEncryption: cli.BoolMe(flags[networkEncryption]),
IPv6: cli.BoolMe(flags[ipv6]),
AllowList: cli.RegexMe(flags[allowList]),
DenyList: cli.RegexMe(flags[denyList]),
InstanceTypeBase: cli.StringMe(flags[instanceTypeBase]),
Flexible: cli.BoolMe(flags[flexible]),
Service: cli.StringMe(flags[service]),
VirtualizationType: cli.StringMe(flags[virtualizationType]),
PricePerHour: cli.Float64RangeMe(flags[pricePerHour]),
InstanceStorageRange: cli.ByteQuantityRangeMe(flags[instanceStorage]),
DiskType: cli.StringMe(flags[diskType]),
DiskEncryption: cli.BoolMe(flags[diskEncryption]),
NVME: cli.BoolMe(flags[nvme]),
EBSOptimized: cli.BoolMe(flags[ebsOptimized]),
EBSOptimizedBaselineBandwidth: cli.ByteQuantityRangeMe(flags[ebsOptimizedBaselineBandwidth]),
EBSOptimizedBaselineThroughput: cli.ByteQuantityRangeMe(flags[ebsOptimizedBaselineThroughput]),
EBSOptimizedBaselineIOPS: cli.IntRangeMe(flags[ebsOptimizedBaselineIOPS]),
}

if flags[verbose] != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aws/amazon-ec2-instance-selector/v2
go 1.17

require (
github.com/aws/aws-sdk-go v1.38.27
github.com/aws/aws-sdk-go v1.43.31
github.com/blang/semver/v4 v4.0.0
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/hcl v1.0.0
Expand Down
15 changes: 7 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aws/aws-sdk-go v1.38.27 h1:jQAUnMGWH33STZ7djdeSlNlXZf/Jhuij9172x7U5/HE=
github.com/aws/aws-sdk-go v1.38.27/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.43.31 h1:yJZIr8nMV1hXjAvvOLUFqZRJcHV7udPQBfhJqawDzI0=
github.com/aws/aws-sdk-go v1.43.31/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
Expand Down Expand Up @@ -125,16 +125,14 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -144,10 +142,11 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
70 changes: 68 additions & 2 deletions pkg/selector/comparators.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ func isSupportedWithBool(instanceTypeValue *bool, target *bool) bool {

// Helper functions for aggregating data parsed from AWS API calls

func getTotalAcceleratorsCount(acceleratorInfo *ec2.InferenceAcceleratorInfo) *int64 {
if acceleratorInfo == nil {
return nil
}
total := aws.Int64(0)
for _, accel := range acceleratorInfo.Accelerators {
total = aws.Int64(*total + *accel.Count)
}
return total
}

func getTotalGpusCount(gpusInfo *ec2.GpuInfo) *int64 {
if gpusInfo == nil {
return nil
Expand Down Expand Up @@ -153,13 +164,68 @@ func getNetworkPerformance(networkPerformance *string) *int {
return aws.Int(bandwidthNumber)
}

// supportSyntaxToBool takes an instance spec field that uses ["unsupported", "supported", or "required"]
func getInstanceStorage(instanceStorageInfo *ec2.InstanceStorageInfo) *int64 {
if instanceStorageInfo == nil {
return aws.Int64(0)
}
return aws.Int64(*instanceStorageInfo.TotalSizeInGB * 1024)
}

func getDiskType(instanceStorageInfo *ec2.InstanceStorageInfo) *string {
if instanceStorageInfo == nil || len(instanceStorageInfo.Disks) == 0 {
return nil
}
return instanceStorageInfo.Disks[0].Type
}

func getNVMESupport(instanceStorageInfo *ec2.InstanceStorageInfo, ebsInfo *ec2.EbsInfo) *bool {
if instanceStorageInfo != nil {
return supportSyntaxToBool(instanceStorageInfo.NvmeSupport)
}
if ebsInfo != nil {
return supportSyntaxToBool(ebsInfo.EbsOptimizedSupport)
}
return aws.Bool(false)
}

func getDiskEncryptionSupport(instanceStorageInfo *ec2.InstanceStorageInfo, ebsInfo *ec2.EbsInfo) *bool {
if instanceStorageInfo != nil {
return supportSyntaxToBool(instanceStorageInfo.EncryptionSupport)
}
if ebsInfo != nil {
return supportSyntaxToBool(ebsInfo.EncryptionSupport)
}
return aws.Bool(false)
}

func getEBSOptimizedBaselineBandwidth(ebsInfo *ec2.EbsInfo) *int64 {
if ebsInfo == nil || ebsInfo.EbsOptimizedInfo == nil {
return nil
}
return ebsInfo.EbsOptimizedInfo.BaselineBandwidthInMbps
}

func getEBSOptimizedBaselineThroughput(ebsInfo *ec2.EbsInfo) *float64 {
if ebsInfo == nil || ebsInfo.EbsOptimizedInfo == nil {
return nil
}
return ebsInfo.EbsOptimizedInfo.BaselineThroughputInMBps
}

func getEBSOptimizedBaselineIOPS(ebsInfo *ec2.EbsInfo) *int64 {
if ebsInfo == nil || ebsInfo.EbsOptimizedInfo == nil {
return nil
}
return ebsInfo.EbsOptimizedInfo.BaselineIops
}

// supportSyntaxToBool takes an instance spec field that uses ["unsupported", "supported", "required", or "default"]
// and transforms it to a *bool to use in filter execution
func supportSyntaxToBool(instanceTypeSupport *string) *bool {
if instanceTypeSupport == nil {
return nil
}
if strings.ToLower(*instanceTypeSupport) == required || strings.ToLower(*instanceTypeSupport) == supported {
if strings.ToLower(*instanceTypeSupport) == required || strings.ToLower(*instanceTypeSupport) == supported || strings.ToLower(*instanceTypeSupport) == "default" {
return aws.Bool(true)
}
return aws.Bool(false)
Expand Down
Loading