@@ -186,17 +186,32 @@ func matchEC2ZonesPrintRunE(cmd *cobra.Command, args []string) error {
186
186
}
187
187
types := strings .Split (args [0 ], "," )
188
188
zones := strings .Split (args [1 ], "," )
189
- matches , err := matchEC2Zones (types , zones )
189
+ matches , misses , err := matchEC2Zones (types , zones )
190
190
if err != nil {
191
191
return err
192
192
}
193
+ if len (matches ) > 0 {
194
+ fmt .Println ("Instancs available in all zones:" )
195
+ }
193
196
for k := range matches {
194
197
fmt .Println (k )
195
198
}
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
+ }
196
210
return nil
197
211
}
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 ) {
199
213
validTypes := map [string ]* instanceType {}
214
+ invalidTypes := map [string ]* instanceType {}
200
215
201
216
awsTypes := aws .StringSlice (types )
202
217
awsZones := aws .StringSlice (zones )
@@ -219,12 +234,12 @@ func matchEC2Zones(types []string, zones []string) (map[string]*instanceType, er
219
234
}
220
235
err := offeringInput .Validate ()
221
236
if err != nil {
222
- return validTypes , err
237
+ return validTypes , invalidTypes , err
223
238
}
224
239
225
240
typesInZones , err := filterInstanceTypeOfferings (offeringInput , ec2Client )
226
241
if err != nil {
227
- return validTypes , err
242
+ return validTypes , invalidTypes , err
228
243
}
229
244
230
245
// Populate map of valid instanceTypes
@@ -240,13 +255,14 @@ func matchEC2Zones(types []string, zones []string) (map[string]*instanceType, er
240
255
}
241
256
}
242
257
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
244
259
for k , v := range validTypes {
245
260
if ! compareUnsortedStringSlice (zones , v .Locations ) {
246
261
delete (validTypes , k )
262
+ invalidTypes [k ] = v
247
263
}
248
264
}
249
- return validTypes , nil
265
+ return validTypes , invalidTypes , nil
250
266
}
251
267
252
268
func newEC2PriceMatcherCommand () * cobra.Command {
0 commit comments