@@ -86,10 +86,16 @@ type configRoot struct {
86
86
type cache struct {
87
87
CacheDir string
88
88
Instances []* compute.Instance
89
- InstanceGroups []* compute. InstanceGroup
89
+ InstanceGroups []* instanceGroupExt
90
90
Projects []* cloudresourcemanager.Project
91
91
}
92
92
93
+ type instanceGroupExt struct {
94
+ InstanceGroup * compute.InstanceGroup
95
+ Project * cloudresourcemanager.Project
96
+ Members []* compute.Instance
97
+ }
98
+
93
99
func loadCache () (* cache , error ) {
94
100
cachedir , err := homedir .Expand ("~/.cache/geco/" )
95
101
if err != nil {
@@ -271,11 +277,11 @@ func doCache(cliCtx *cli.Context) {
271
277
}
272
278
273
279
// gcloud compute instance-groups list (in parallel)
274
- instanceGroupNotify := make (chan []* compute. InstanceGroup )
280
+ instanceGroupNotify := make (chan []* instanceGroupExt )
275
281
for _ , project := range c .Projects {
276
- go func (project * cloudresourcemanager.Project , notify chan <- []* compute. InstanceGroup ) {
282
+ go func (project * cloudresourcemanager.Project , notify chan <- []* instanceGroupExt ) {
277
283
semaphore <- 0
278
- var instanceGroups []* compute. InstanceGroup
284
+ var ret []* instanceGroupExt
279
285
280
286
log .Printf ("loading instance groups in %s (%s)...\n " , project .Name , project .ProjectId )
281
287
service , err := compute .New (client )
@@ -298,7 +304,12 @@ func doCache(cliCtx *cli.Context) {
298
304
}
299
305
300
306
for _ , instanceGroupsScopedList := range res .Items {
301
- instanceGroups = append (instanceGroups , instanceGroupsScopedList .InstanceGroups ... )
307
+ for _ , instanceGroup := range instanceGroupsScopedList .InstanceGroups {
308
+ ret = append (ret , & instanceGroupExt {
309
+ InstanceGroup : instanceGroup ,
310
+ Project : project ,
311
+ })
312
+ }
302
313
}
303
314
304
315
if res .NextPageToken != "" {
@@ -310,9 +321,9 @@ func doCache(cliCtx *cli.Context) {
310
321
}
311
322
312
323
<- semaphore
313
- notify <- instanceGroups
324
+ notify <- ret
314
325
315
- log .Printf ("loaded instances in %s (%s), %d instances found.\n " , project .Name , project .ProjectId , len (instanceGroups ))
326
+ log .Printf ("loaded instance groups in %s (%s), %d instances found.\n " , project .Name , project .ProjectId , len (ret ))
316
327
}(project , instanceGroupNotify )
317
328
}
318
329
for _ = range c .Projects {
@@ -322,16 +333,13 @@ func doCache(cliCtx *cli.Context) {
322
333
}
323
334
}
324
335
325
- // sort projects, instances, instance-groups
336
+ // sort projects, instances
326
337
sort .Slice (c .Projects , func (i , j int ) bool {
327
338
return c .Projects [i ].ProjectId < c .Projects [j ].ProjectId
328
339
})
329
340
sort .Slice (c .Instances , func (i , j int ) bool {
330
341
return c .Instances [i ].SelfLink < c .Instances [j ].SelfLink
331
342
})
332
- sort .Slice (c .InstanceGroups , func (i , j int ) bool {
333
- return c .InstanceGroups [i ].SelfLink < c .InstanceGroups [j ].SelfLink
334
- })
335
343
336
344
saveCache (c )
337
345
log .Println ("saved cache." )
0 commit comments