@@ -446,52 +446,61 @@ func (g *GceInfoer) GetVirtualMachines(region string) ([]types.VMInfo, error) {
446446 logger := log .WithFields (g .log , map [string ]interface {}{"region" : region })
447447 logger .Debug ("retrieving product information" )
448448 var vmsMap = make (map [string ]types.VMInfo )
449+ vmZones := make (map [string ][]string )
449450 var ntwPerf uint
450451
451452 zones , err := g .GetZones (region )
452453 if err != nil {
453454 return nil , err
454455 }
455- err = g .computeSvc .MachineTypes .List (g .projectId , zones [0 ]).Pages (context .TODO (), func (allMts * compute.MachineTypeList ) error {
456- for _ , mt := range allMts .Items {
457- if _ , ok := vmsMap [mt .Name ]; ! ok {
458- switch {
459- case mt .GuestCpus < 1 :
460- // minimum 1 Gbps network performance for each virtual machine
461- ntwPerf = 1
462- case mt .GuestCpus > 8 :
463- // theoretical maximum of 16 Gbps for each virtual machine
464- ntwPerf = 16
465- default :
466- // each vCPU has a 2 Gbps egress cap for peak performance
467- ntwPerf = uint (mt .GuestCpus * 2 )
468- }
469- ntwMapper := newGceNetworkMapper ()
470- ntwPerfCat , err := ntwMapper .MapNetworkPerf (fmt .Sprint (ntwPerf , " Gbit/s" ))
471- if err != nil {
472- logger .Debug (emperror .Wrap (err , "failed to get network performance category" ).Error (),
473- map [string ]interface {}{"instanceType" : mt .Name })
474- }
475- vmsMap [mt .Name ] = types.VMInfo {
476- Category : g .getCategory (mt .Name ),
477- Series : g .mapSeries (mt .Name ),
478- Type : mt .Name ,
479- Cpus : float64 (mt .GuestCpus ),
480- Mem : float64 (mt .MemoryMb ) / 1024 ,
481- NtwPerf : fmt .Sprintf ("%d Gbit/s" , ntwPerf ),
482- NtwPerfCat : ntwPerfCat ,
483- Zones : zones ,
484- Attributes : cloudinfo .Attributes (fmt .Sprint (mt .GuestCpus ), fmt .Sprint (float64 (mt .MemoryMb )/ 1024 ), ntwPerfCat , g .getCategory (mt .Name )),
456+ for _ , zone := range zones {
457+ err = g .computeSvc .MachineTypes .List (g .projectId , zone ).Pages (context .TODO (), func (allMts * compute.MachineTypeList ) error {
458+ for _ , mt := range allMts .Items {
459+ vmZones [mt .Name ] = append (vmZones [mt .Name ], zone )
460+ if _ , ok := vmsMap [mt .Name ]; ! ok {
461+ switch {
462+ case mt .GuestCpus < 1 :
463+ // minimum 1 Gbps network performance for each virtual machine
464+ ntwPerf = 1
465+ case mt .GuestCpus > 8 :
466+ // theoretical maximum of 16 Gbps for each virtual machine
467+ ntwPerf = 16
468+ default :
469+ // each vCPU has a 2 Gbps egress cap for peak performance
470+ ntwPerf = uint (mt .GuestCpus * 2 )
471+ }
472+ ntwMapper := newGceNetworkMapper ()
473+ ntwPerfCat , err := ntwMapper .MapNetworkPerf (fmt .Sprint (ntwPerf , " Gbit/s" ))
474+ if err != nil {
475+ logger .Debug (emperror .Wrap (err , "failed to get network performance category" ).Error (),
476+ map [string ]interface {}{"instanceType" : mt .Name })
477+ }
478+ var gpus float64
479+ for _ , acc := range mt .Accelerators {
480+ gpus += float64 (acc .GuestAcceleratorCount )
481+ }
482+ vmsMap [mt .Name ] = types.VMInfo {
483+ Category : g .getCategory (mt .Name ),
484+ Series : g .mapSeries (mt .Name ),
485+ Type : mt .Name ,
486+ Cpus : float64 (mt .GuestCpus ),
487+ Mem : float64 (mt .MemoryMb ) / 1024 ,
488+ Gpus : gpus ,
489+ NtwPerf : fmt .Sprintf ("%d Gbit/s" , ntwPerf ),
490+ NtwPerfCat : ntwPerfCat ,
491+ Attributes : cloudinfo .Attributes (fmt .Sprint (mt .GuestCpus ), fmt .Sprint (float64 (mt .MemoryMb )/ 1024 ), ntwPerfCat , g .getCategory (mt .Name )),
492+ }
485493 }
486494 }
495+ return nil
496+ })
497+ if err != nil {
498+ return nil , err
487499 }
488- return nil
489- })
490- if err != nil {
491- return nil , err
492500 }
493501 var vms []types.VMInfo
494- for _ , vm := range vmsMap {
502+ for name , vm := range vmsMap {
503+ vm .Zones = vmZones [name ]
495504 vms = append (vms , vm )
496505 }
497506 logger .Debug ("found virtual machines" , map [string ]interface {}{"vms" : len (vms )})
@@ -504,6 +513,8 @@ func (g *GceInfoer) getCategory(name string) string {
504513 return types .CategoryMemory
505514 case strings .Contains (name , "highcpu" ):
506515 return types .CategoryCompute
516+ case strings .Contains (name , "highgpu" ):
517+ return types .CategoryGpu
507518 default :
508519 return types .CategoryGeneral
509520 }
0 commit comments