Add FetchReservations to GCE Autoscaling client

This commit is contained in:
Artur Żyliński 2023-04-06 15:27:09 +02:00
parent ad86bdd641
commit b6c887c8b7
2 changed files with 17 additions and 0 deletions

View File

@ -77,6 +77,7 @@ type AutoscalingGceClient interface {
FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error)
FetchZones(region string) ([]string, error)
FetchAvailableCpuPlatforms() (map[string][]string, error)
FetchReservations() ([]*gce.Reservation, error)
// modifying resources
ResizeMig(GceRef, int64) error
@ -508,3 +509,15 @@ func (client *autoscalingGceClientV1) FetchMigsWithName(zone string, name *regex
}
return links, nil
}
func (client *autoscalingGceClientV1) FetchReservations() ([]*gce.Reservation, error) {
reservations := make([]*gce.Reservation, 0)
call := client.gceService.Reservations.AggregatedList(client.projectId)
err := call.Pages(context.TODO(), func(ls *gce.ReservationAggregatedList) error {
for _, items := range ls.Items {
reservations = append(reservations, items.Reservations...)
}
return nil
})
return reservations, err
}

View File

@ -100,6 +100,10 @@ func (client *mockAutoscalingGceClient) FetchAvailableCpuPlatforms() (map[string
return nil, nil
}
func (client *mockAutoscalingGceClient) FetchReservations() ([]*gce.Reservation, error) {
return nil, nil
}
func (client *mockAutoscalingGceClient) ResizeMig(_ GceRef, _ int64) error {
return nil
}