Skip to content

Commit

Permalink
Merge pull request #641 from sapcc/consume-liquid-utils-from-go-bits
Browse files Browse the repository at this point in the history
consume helper methods that have moved to go-bits from there
  • Loading branch information
majewsky authored Jan 9, 2025
2 parents 2aa1cc5 + 415a998 commit 280b2d3
Show file tree
Hide file tree
Showing 29 changed files with 351 additions and 335 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/prometheus/common v0.61.0
github.com/rs/cors v1.11.1
github.com/sapcc/go-api-declarations v1.13.2
github.com/sapcc/go-bits v0.0.0-20250101161453-7169321dc311
github.com/sapcc/go-bits v0.0.0-20250108104100-5bc9c24d5c51
go.uber.org/automaxprocs v1.6.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/sapcc/go-api-declarations v1.13.2 h1:dPYYsjwKGObSAm6+K+dYCiLQWunYuWkywlZnuXfjsmk=
github.com/sapcc/go-api-declarations v1.13.2/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI=
github.com/sapcc/go-bits v0.0.0-20250101161453-7169321dc311 h1:V55251w5oFB40UBoT13nDY00sDfwMEu0THgUYlooad0=
github.com/sapcc/go-bits v0.0.0-20250101161453-7169321dc311/go.mod h1:O90mzPqtXgvzkPHFEzO0p3XTknccPxZQH5w1fAd20pM=
github.com/sapcc/go-bits v0.0.0-20250108104100-5bc9c24d5c51 h1:C2FrgHdKL2f1R+G2RpIgkXIMkeyzjlhH6HasMwoorVo=
github.com/sapcc/go-bits v0.0.0-20250108104100-5bc9c24d5c51/go.mod h1:krZL5JHF0Wok9p0fK/o9gjxegWr1eOGWe8LgCjp5zxQ=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down Expand Up @@ -190,8 +190,8 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
10 changes: 5 additions & 5 deletions internal/datamodel/apply_computed_project_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"github.com/go-gorp/gorp/v3"
"github.com/sapcc/go-api-declarations/limes"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"
"github.com/sapcc/go-bits/sqlext"

"github.com/sapcc/limes/internal/core"
"github.com/sapcc/limes/internal/db"
"github.com/sapcc/limes/internal/util"
)

// NOTE: Most private functions in this file have the name prefix "acpq"
Expand Down Expand Up @@ -432,7 +432,7 @@ func (target acpqGlobalTarget) EnforceConstraints(constraints map[db.ProjectReso
totalAllocated += t.Allocated
desireScalePerAZ[az] = *c.MinQuota * max(1, subtractOrZero(t.Desired, t.Allocated))
}
extraAllocatedPerAZ := util.DistributeFairly(subtractOrZero(*c.MinQuota, totalAllocated), desireScalePerAZ)
extraAllocatedPerAZ := liquidapi.DistributeFairly(subtractOrZero(*c.MinQuota, totalAllocated), desireScalePerAZ)
for _, az := range allAZs {
if az == limes.AvailabilityZoneAny && isAZAware {
continue
Expand All @@ -453,7 +453,7 @@ func (target acpqGlobalTarget) EnforceConstraints(constraints map[db.ProjectReso
extraDesiredPerAZ[az] = subtractOrZero(t.Desired, t.Allocated)
}
if totalDesired > *c.MaxQuota {
extraDesiredPerAZ = util.DistributeFairly(subtractOrZero(*c.MaxQuota, totalAllocated), extraDesiredPerAZ)
extraDesiredPerAZ = liquidapi.DistributeFairly(subtractOrZero(*c.MaxQuota, totalAllocated), extraDesiredPerAZ)
for _, az := range allAZs {
t := target[az][resourceID]
t.Desired = t.Allocated + extraDesiredPerAZ[az]
Expand Down Expand Up @@ -481,7 +481,7 @@ func (target acpqGlobalTarget) TryFulfillDesired(stats map[limes.AvailabilityZon
}
availableCapacity := subtractOrZero(stats[az].Capacity, azTarget.SumAllocated())
if availableCapacity > 0 {
granted := util.DistributeFairly(availableCapacity, azTarget.Requested())
granted := liquidapi.DistributeFairly(availableCapacity, azTarget.Requested())
azTarget.AddGranted(granted)
}
}
Expand All @@ -493,7 +493,7 @@ func (target acpqGlobalTarget) TryFulfillDesired(stats map[limes.AvailabilityZon
}
if totalAvailable > 0 {
anyTarget := target[limes.AvailabilityZoneAny]
granted := util.DistributeFairly(totalAvailable, anyTarget.Requested())
granted := liquidapi.DistributeFairly(totalAvailable, anyTarget.Requested())
anyTarget.AddGranted(granted)
}
}
8 changes: 4 additions & 4 deletions internal/liquids/cinder/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/schedulerstats"
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/services"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"

"github.com/sapcc/limes/internal/liquids"
"github.com/sapcc/limes/internal/util"
)

// ScanCapacity implements the liquidapi.Logic interface.
Expand Down Expand Up @@ -103,7 +103,7 @@ func (l *Logic) ScanCapacity(ctx context.Context, req liquid.ServiceCapacityRequ
Resources: make(map[liquid.ResourceName]*liquid.ResourceCapacityReport),
}
for info, volumeTypes := range volumeTypesByInfo {
relevantPools := liquids.RestrictToKnownAZs(sortedPools[info], req.AllAZs)
relevantPools := liquidapi.RestrictToKnownAZs(sortedPools[info], req.AllAZs)
relevantDemands := make(map[VolumeType]liquid.ResourceDemand)
for _, volumeType := range volumeTypes {
relevantDemands[volumeType] = req.DemandByResource[volumeType.CapacityResourceName()]
Expand Down Expand Up @@ -198,9 +198,9 @@ func (l *Logic) buildAZCapacityReportForPoolSet(pools []StoragePool, rawDemands
balance[volumeType] = 1.0
}
logg.Debug("distributing for AZ %q: capacity = %d between volume types %v", az, totalCapacityGiB, balance)
distributedCapacityGiB := util.DistributeDemandFairly(totalCapacityGiB, rawDemands, balance)
distributedCapacityGiB := liquidapi.DistributeDemandFairly(totalCapacityGiB, rawDemands, balance)
logg.Debug("distributing for AZ %q: usage = %d between volume types %v", az, totalUsageGiB, balance)
distributedUsageGiB := util.DistributeDemandFairly(totalUsageGiB, rawDemands, balance)
distributedUsageGiB := liquidapi.DistributeDemandFairly(totalUsageGiB, rawDemands, balance)

result := make(map[VolumeType]*liquid.AZResourceCapacityReport, len(rawDemands))
for volumeType := range rawDemands {
Expand Down
5 changes: 2 additions & 3 deletions internal/liquids/cinder/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack"
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumetypes"
"github.com/sapcc/go-api-declarations/liquid"

"github.com/sapcc/limes/internal/liquids"
"github.com/sapcc/go-bits/liquidapi"
)

type Logic struct {
Expand All @@ -40,7 +39,7 @@ type Logic struct {
// connections
CinderV3 *gophercloud.ServiceClient `json:"-"`
// state
VolumeTypes liquids.State[map[VolumeType]VolumeTypeInfo] `json:"-"`
VolumeTypes liquidapi.State[map[VolumeType]VolumeTypeInfo] `json:"-"`
}

// VolumeType is a type with convenience functions for deriving resource names.
Expand Down
15 changes: 7 additions & 8 deletions internal/liquids/cinder/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes"
"github.com/gophercloud/gophercloud/v2/pagination"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"

"github.com/sapcc/limes/internal/liquids"
)

// ScanUsage implements the liquidapi.Logic interface.
Expand Down Expand Up @@ -111,12 +110,12 @@ func (l *Logic) collectVolumeSubresources(ctx context.Context, projectUUID strin

if !isKnownVolumeType[vt] {
logg.Info("volume %s in project %s has unknown volume type %q", volume.ID, projectUUID, volume.VolumeType)
metrics.UnknownVolumeType.VolumeSizeGiB += liquids.AtLeastZero(volume.Size)
metrics.UnknownVolumeType.VolumeSizeGiB += liquidapi.AtLeastZero(volume.Size)
continue
}

if az != liquid.AvailabilityZoneUnknown {
resources[vt.CapacityResourceName()].AddLocalizedUsage(az, liquids.AtLeastZero(volume.Size))
resources[vt.CapacityResourceName()].AddLocalizedUsage(az, liquidapi.AtLeastZero(volume.Size))
resources[vt.VolumesResourceName()].AddLocalizedUsage(az, 1)
}

Expand All @@ -125,7 +124,7 @@ func (l *Logic) collectVolumeSubresources(ctx context.Context, projectUUID strin
ID: volume.ID,
Name: volume.Name,
Attributes: VolumeAttributes{
SizeGiB: liquids.AtLeastZero(volume.Size),
SizeGiB: liquidapi.AtLeastZero(volume.Size),
Status: volume.Status,
},
}.Finalize()
Expand Down Expand Up @@ -175,13 +174,13 @@ func (l *Logic) collectSnapshotSubresources(ctx context.Context, projectUUID str
if !isKnownVolumeType[vt] {
logg.Info("volume %s that owns snapshot %s in project %s has unknown volume type %q",
snapshot.VolumeID, snapshot.ID, projectUUID, vt)
metrics.UnknownVolumeType.SnapshotSizeGiB += liquids.AtLeastZero(snapshot.Size)
metrics.UnknownVolumeType.SnapshotSizeGiB += liquidapi.AtLeastZero(snapshot.Size)
continue
}

az := placement.AvailabilityZone
if az != liquid.AvailabilityZoneUnknown {
resources[vt.CapacityResourceName()].AddLocalizedUsage(az, liquids.AtLeastZero(snapshot.Size))
resources[vt.CapacityResourceName()].AddLocalizedUsage(az, liquidapi.AtLeastZero(snapshot.Size))
resources[vt.SnapshotsResourceName()].AddLocalizedUsage(az, 1)
}

Expand All @@ -190,7 +189,7 @@ func (l *Logic) collectSnapshotSubresources(ctx context.Context, projectUUID str
ID: snapshot.ID,
Name: snapshot.Name,
Attributes: SnapshotAttributes{
SizeGiB: liquids.AtLeastZero(snapshot.Size),
SizeGiB: liquidapi.AtLeastZero(snapshot.Size),
Status: snapshot.Status,
VolumeID: snapshot.VolumeID,
},
Expand Down
8 changes: 4 additions & 4 deletions internal/liquids/ironic/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"

"github.com/sapcc/limes/internal/liquids"
"github.com/sapcc/limes/internal/liquids/nova"
)

Expand Down Expand Up @@ -101,9 +101,9 @@ func (l *Logic) BuildServiceInfo(ctx context.Context) (liquid.ServiceInfo, error
}

buf, err := json.Marshal(FlavorAttributes{
Cores: liquids.AtLeastZero(flavor.VCPUs),
MemoryMiB: liquids.AtLeastZero(flavor.RAM),
DiskGiB: liquids.AtLeastZero(flavor.Disk),
Cores: liquidapi.AtLeastZero(flavor.VCPUs),
MemoryMiB: liquidapi.AtLeastZero(flavor.RAM),
DiskGiB: liquidapi.AtLeastZero(flavor.Disk),
})
if err != nil {
return liquid.ServiceInfo{}, fmt.Errorf("while serializing FlavorAttributes: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions internal/liquids/manila/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/schedulerstats"
"github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/services"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"

"github.com/sapcc/limes/internal/liquids"
"github.com/sapcc/limes/internal/util"
)

// ScanCapacity implements the liquidapi.Logic interface.
Expand Down Expand Up @@ -190,13 +190,13 @@ func (l *Logic) scanCapacityForShareTypeAndAZ(vst VirtualShareType, azCount uint
"snapmirrors": 0,
}
logg.Debug("distributing capacity for share_type %q, AZ %q", vst.Name, az)
distributedCapacityGiB := util.DistributeDemandFairly(uint64(totalCapacityGB), map[string]liquid.ResourceDemandInAZ{
distributedCapacityGiB := liquidapi.DistributeDemandFairly(uint64(totalCapacityGB), map[string]liquid.ResourceDemandInAZ{
"shares": shareCapacityDemand,
"snapshots": snapshotCapacityDemand,
"snapmirrors": snapmirrorCapacityDemand,
}, balance)
logg.Debug("distributing usage for share_type %q, AZ %q", vst.Name, az)
distributedUsageGiB := util.DistributeDemandFairly(uint64(allocatedCapacityGB), map[string]liquid.ResourceDemandInAZ{
distributedUsageGiB := liquidapi.DistributeDemandFairly(uint64(allocatedCapacityGB), map[string]liquid.ResourceDemandInAZ{
"shares": {Usage: shareCapacityDemand.Usage},
"snapshots": {Usage: snapshotCapacityDemand.Usage},
"snapmirrors": {Usage: snapmirrorCapacityDemand.Usage},
Expand All @@ -206,7 +206,7 @@ func (l *Logic) scanCapacityForShareTypeAndAZ(vst VirtualShareType, azCount uint
params := l.CapacityCalculation
var result azCapacityForShareType
result.Shares = liquid.AZResourceCapacityReport{
Capacity: liquids.SaturatingSub(params.SharesPerPool*poolCount, params.ShareNetworks/azCount),
Capacity: liquidapi.SaturatingSub(params.SharesPerPool*poolCount, params.ShareNetworks/azCount),
}
result.Snapshots = liquid.AZResourceCapacityReport{
Capacity: result.Shares.Capacity * params.SnapshotsPerShare,
Expand Down
5 changes: 2 additions & 3 deletions internal/liquids/manila/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/sharetypes"
"github.com/prometheus/common/model"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/promquery"

"github.com/sapcc/limes/internal/liquids"
)

type Logic struct {
Expand All @@ -55,7 +54,7 @@ type Logic struct {
AZMetrics *promquery.BulkQueryCache[azMetricsKey, azMetrics] `json:"-"`
NetappMetrics *promquery.BulkQueryCache[netappMetricsKey, netappMetrics] `json:"-"`
// caches
ShareTypeIDByName liquids.State[map[RealShareType]string] `json:"-"`
ShareTypeIDByName liquidapi.State[map[RealShareType]string] `json:"-"`
}

// Init implements the liquidapi.Logic interface.
Expand Down
5 changes: 2 additions & 3 deletions internal/liquids/neutron/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/quotas"
"github.com/sapcc/go-api-declarations/liquid"

"github.com/sapcc/limes/internal/liquids"
"github.com/sapcc/go-bits/gophercloudext"
)

type Logic struct {
Expand Down Expand Up @@ -61,7 +60,7 @@ func (l *Logic) Init(ctx context.Context, provider *gophercloud.ProviderClient,
if err != nil {
return fmt.Errorf("cannot initialize Neutron v2 client: %w", err)
}
l.OwnProjectID, err = liquids.GetProjectIDFromTokenScope(provider)
l.OwnProjectID, err = gophercloudext.GetProjectIDFromTokenScope(provider)
if err != nil {
return fmt.Errorf("cannot find project scope of own token: %w", err)
}
Expand Down
15 changes: 7 additions & 8 deletions internal/liquids/nova/binpack_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"math"
"strings"

"github.com/sapcc/limes/internal/liquids"

"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors"
"github.com/gophercloud/gophercloud/v2/openstack/placement/v1/resourceproviders"
"github.com/sapcc/go-api-declarations/limes"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"
)

Expand Down Expand Up @@ -124,14 +123,14 @@ func PrepareHypervisorForBinpacking(h MatchingHypervisor) (BinpackHypervisor, er
// break down capacity into equal-sized nodes
nodeTemplate := BinpackNode{
Capacity: BinpackVector[uint64]{
VCPUs: liquids.AtLeastZero(h.Inventories["VCPU"].MaxUnit),
MemoryMB: liquids.AtLeastZero(h.Inventories["MEMORY_MB"].MaxUnit),
VCPUs: liquidapi.AtLeastZero(h.Inventories["VCPU"].MaxUnit),
MemoryMB: liquidapi.AtLeastZero(h.Inventories["MEMORY_MB"].MaxUnit),
// We do not use `h.Inventories["DISK_GB"].MaxUnit` because it appears to describe the max root
// disk size for a single instance, rather than the actual available disk size. Maybe this is
// because the root disks are stored on nearby NFS filers, so MaxUnit is actually the max
// volume size instead of the total capacity per node. Since we have a good nodeCount number
// now, we can divide up the total disk space for all nodes.
LocalGB: liquids.SaturatingSub(h.Inventories["DISK_GB"].Total, h.Inventories["DISK_GB"].Reserved) / nodeCount,
LocalGB: liquidapi.SaturatingSub(h.Inventories["DISK_GB"].Total, h.Inventories["DISK_GB"].Reserved) / nodeCount,
},
}
result := BinpackHypervisor{
Expand Down Expand Up @@ -189,9 +188,9 @@ func (hh BinpackHypervisors) PlaceOneInstance(flavor flavors.Flavor, reason stri
// [Mayank]: https://www.it.iitb.ac.in/~sahoo/papers/cloud2011_mayank.pdf

vmSize := BinpackVector[uint64]{
VCPUs: coresOvercommitFactor.ApplyInReverseTo(liquids.AtLeastZero(flavor.VCPUs)),
MemoryMB: liquids.AtLeastZero(flavor.RAM),
LocalGB: liquids.AtLeastZero(flavor.Disk),
VCPUs: coresOvercommitFactor.ApplyInReverseTo(liquidapi.AtLeastZero(flavor.VCPUs)),
MemoryMB: liquidapi.AtLeastZero(flavor.RAM),
LocalGB: liquidapi.AtLeastZero(flavor.Disk),
}

// ensure that placing this instance does not encroach on the overall blocked capacity
Expand Down
7 changes: 3 additions & 4 deletions internal/liquids/nova/hypervisor_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import (
"slices"
"strings"

"github.com/sapcc/limes/internal/liquids"

"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/aggregates"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/hypervisors"
"github.com/gophercloud/gophercloud/v2/openstack/placement/v1/resourceproviders"
"github.com/sapcc/go-api-declarations/limes"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"
"github.com/sapcc/go-bits/regexpext"
)
Expand Down Expand Up @@ -239,8 +238,8 @@ func (h MatchingHypervisor) CheckTopology() bool {
func (h MatchingHypervisor) PartialCapacity() PartialCapacity {
makeMetric := func(metric string) PartialCapacityMetric {
return PartialCapacityMetric{
Capacity: liquids.SaturatingSub(h.Inventories[metric].Total, h.Inventories[metric].Reserved),
Usage: liquids.AtLeastZero(h.Usages[metric]),
Capacity: liquidapi.SaturatingSub(h.Inventories[metric].Total, h.Inventories[metric].Reserved),
Usage: liquidapi.AtLeastZero(h.Usages[metric]),
}
}
return PartialCapacity{
Expand Down
9 changes: 4 additions & 5 deletions internal/liquids/nova/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import (
"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"

"github.com/sapcc/limes/internal/liquids"
"github.com/sapcc/go-bits/liquidapi"
)

type Logic struct {
Expand All @@ -45,9 +44,9 @@ type Logic struct {
OSTypeProber *OSTypeProber `json:"-"`
ServerGroupProber *ServerGroupProber `json:"-"`
// computed state
ignoredFlavorNames liquids.State[[]string] `json:"-"`
hasPooledResource liquids.State[map[string]map[liquid.ResourceName]bool] `json:"-"`
hwVersionResources liquids.State[[]liquid.ResourceName] `json:"-"`
ignoredFlavorNames liquidapi.State[[]string] `json:"-"`
hasPooledResource liquidapi.State[map[string]map[liquid.ResourceName]bool] `json:"-"`
hwVersionResources liquidapi.State[[]liquid.ResourceName] `json:"-"`
}

// Init implements the liquidapi.Logic interface.
Expand Down
Loading

0 comments on commit 280b2d3

Please sign in to comment.