diff --git a/cmd/metal-api/internal/metal/machine.go b/cmd/metal-api/internal/metal/machine.go index ecd246604..339e9cf85 100644 --- a/cmd/metal-api/internal/metal/machine.go +++ b/cmd/metal-api/internal/metal/machine.go @@ -187,6 +187,22 @@ func (ms Machines) WithSize(id string) Machines { return res } +func (ms Machines) WithPartition(id string) Machines { + var res Machines + + for _, m := range ms { + m := m + + if m.PartitionID != id { + continue + } + + res = append(res, m) + } + + return res +} + // MachineNetwork stores the Network details of the machine type MachineNetwork struct { NetworkID string `rethinkdb:"networkid" json:"networkid"` diff --git a/cmd/metal-api/internal/service/partition-service.go b/cmd/metal-api/internal/service/partition-service.go index 615dc95b8..ddd397f01 100644 --- a/cmd/metal-api/internal/service/partition-service.go +++ b/cmd/metal-api/internal/service/partition-service.go @@ -461,7 +461,7 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque reservation := reservation cap.Reservations += reservation.Amount - cap.UsedReservations += min(len(machinesByProject[reservation.ProjectID]), reservation.Amount) + cap.UsedReservations += min(len(machinesByProject[reservation.ProjectID].WithSize(size.ID).WithPartition(pc.ID)), reservation.Amount) } } diff --git a/cmd/metal-api/internal/service/size-service.go b/cmd/metal-api/internal/service/size-service.go index b0a1736d0..8afb0beb5 100644 --- a/cmd/metal-api/internal/service/size-service.go +++ b/cmd/metal-api/internal/service/size-service.go @@ -70,6 +70,7 @@ func (r *sizeResource) webService() *restful.WebService { Doc("get all size reservations"). Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(auditing.Exclude, true). + Reads(v1.EmptyBody{}). Writes([]v1.SizeReservationResponse{}). Returns(http.StatusOK, "OK", []v1.SizeReservationResponse{}). DefaultReturns("Error", httperrors.HTTPErrorResponse{})) @@ -454,7 +455,7 @@ func (r *sizeResource) listSizeReservations(request *restful.Request, response * for _, partitionID := range reservation.PartitionIDs { project := pointer.SafeDeref(projectsByID[reservation.ProjectID]) - allocations := len(machinesByProjectID[reservation.ProjectID].WithSize(size.ID)) + allocations := len(machinesByProjectID[reservation.ProjectID].WithPartition(partitionID).WithSize(size.ID)) result = append(result, &v1.SizeReservationResponse{ SizeID: size.ID, diff --git a/spec/metal-api.json b/spec/metal-api.json index eba6d34a2..2f26cb4ca 100644 --- a/spec/metal-api.json +++ b/spec/metal-api.json @@ -8939,6 +8939,16 @@ "application/json" ], "operationId": "listSizeReservations", + "parameters": [ + { + "in": "body", + "name": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.EmptyBody" + } + } + ], "produces": [ "application/json" ],