From 9d47f145b3404c84e97b0d768d60b66d179fdee3 Mon Sep 17 00:00:00 2001 From: Varsius <42544122+Varsius@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:03:10 +0100 Subject: [PATCH] Add liquid nova set quota endpoint --- internal/liquids/nova/liquid.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/liquids/nova/liquid.go b/internal/liquids/nova/liquid.go index e9e5fab0..b0bc6e2f 100644 --- a/internal/liquids/nova/liquid.go +++ b/internal/liquids/nova/liquid.go @@ -31,6 +31,7 @@ import ( "github.com/gophercloud/gophercloud/v2" "github.com/gophercloud/gophercloud/v2/openstack" "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/quotasets" "github.com/sapcc/go-api-declarations/liquid" ) @@ -185,9 +186,22 @@ func (l *Logic) ScanCapacity(ctx context.Context, req liquid.ServiceCapacityRequ // SetQuota implements the liquidapi.Logic interface. func (l *Logic) SetQuota(ctx context.Context, projectUUID string, req liquid.ServiceQuotaRequest, serviceInfo liquid.ServiceInfo) error { - return errors.New("TODO") + opts := make(novaQuotaUpdateOpts, len(serviceInfo.Resources)) + for resName := range serviceInfo.Resources { + opts[string(resName)] = req.Resources[resName].Quota + } + return quotasets.Update(ctx, l.NovaV2, projectUUID, opts).Err } func (l *Logic) IgnoreFlavor(flavorName string) bool { return slices.Contains(l.ignoredFlavorNames, flavorName) } + +//////////////////////////////////////////////////////////////////////////////// +// custom types for OpenStack APIs + +type novaQuotaUpdateOpts map[string]uint64 + +func (opts novaQuotaUpdateOpts) ToComputeQuotaUpdateMap() (map[string]any, error) { + return map[string]any{"quota_set": opts}, nil +}