Skip to content

Commit c4ee0d7

Browse files
authoredMay 27, 2020
Merge pull request #3 from whwalter/Zones_improve_zone_output
Zones improve zone output
2 parents a5090e6 + 3ab88d0 commit c4ee0d7

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed
 

‎README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ Use "ec2matcher [command] --help" for more information about a command.
5454
Vcpus: 48
5555

5656

57-
### Get a list of types that are available in all of the given availability zones
58-
./ec2matcher zones m5dn.large,m5ad.large us-east-1a,us-east-1b,us-east-1c
59-
m5dn.large
60-
m5ad.large
57+
### Get types' availability in a list of zones
58+
./ec2matcher zones m4.large,m5dn.large,m5ad.large us-east-1a,us-east-1b,us-east-1c,us-east-1e,us-east-1f
59+
Instancs available in all zones:
60+
m4.large
61+
Instances with limited availability:
62+
m5dn.large: [us-east-1a us-east-1f us-east-1c us-east-1b]
63+
m5ad.large: [us-east-1a us-east-1c us-east-1f us-east-1b]
6164

6265
### Get prices for a list of types
6366
./ec2matcher prices m5dn.large,m5ad.large,m5d.large,t3.large,t2.large,m4.large,m5n.large,m6g.large,t3a.large,m5.large,m5a.large

‎main.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,32 @@ func matchEC2ZonesPrintRunE(cmd *cobra.Command, args []string) error {
186186
}
187187
types := strings.Split(args[0], ",")
188188
zones := strings.Split(args[1], ",")
189-
matches, err := matchEC2Zones(types, zones)
189+
matches, misses, err := matchEC2Zones(types, zones)
190190
if err != nil {
191191
return err
192192
}
193+
if len(matches) > 0 {
194+
fmt.Println("Instancs available in all zones:")
195+
}
193196
for k := range matches {
194197
fmt.Println(k)
195198
}
199+
200+
if len(misses) > 0 {
201+
fmt.Println("Instances with limited availability:")
202+
}
203+
for k, v := range misses {
204+
fmt.Printf("%s: %v\n", k, v.Locations)
205+
}
206+
207+
if len(matches) == 0 && len(misses) == 0 {
208+
fmt.Println("No types matched any zones")
209+
}
196210
return nil
197211
}
198-
func matchEC2Zones(types []string, zones []string) (map[string]*instanceType, error) {
212+
func matchEC2Zones(types []string, zones []string) (valid, invalid map[string]*instanceType, e error) {
199213
validTypes := map[string]*instanceType{}
214+
invalidTypes := map[string]*instanceType{}
200215

201216
awsTypes := aws.StringSlice(types)
202217
awsZones := aws.StringSlice(zones)
@@ -219,12 +234,12 @@ func matchEC2Zones(types []string, zones []string) (map[string]*instanceType, er
219234
}
220235
err := offeringInput.Validate()
221236
if err != nil {
222-
return validTypes, err
237+
return validTypes, invalidTypes, err
223238
}
224239

225240
typesInZones, err := filterInstanceTypeOfferings(offeringInput, ec2Client)
226241
if err != nil {
227-
return validTypes, err
242+
return validTypes, invalidTypes, err
228243
}
229244

230245
// Populate map of valid instanceTypes
@@ -240,13 +255,14 @@ func matchEC2Zones(types []string, zones []string) (map[string]*instanceType, er
240255
}
241256
}
242257

243-
// If a type isn't available in all desired zones, remove it from the list of options
258+
// If a type isn't available in all locations, add it to invalidTypes and remove it from validTypes
244259
for k, v := range validTypes {
245260
if !compareUnsortedStringSlice(zones, v.Locations) {
246261
delete(validTypes, k)
262+
invalidTypes[k] = v
247263
}
248264
}
249-
return validTypes, nil
265+
return validTypes, invalidTypes, nil
250266
}
251267

252268
func newEC2PriceMatcherCommand() *cobra.Command {

0 commit comments

Comments
 (0)
Please sign in to comment.