From 2f05f0aa13161e863a44eb5e2e6e21e4cb066cbd Mon Sep 17 00:00:00 2001 From: Gerrit91 Date: Mon, 8 Jan 2024 11:12:47 +0100 Subject: [PATCH] Size reservations. --- Makefile | 4 +- api/models/v1_server_capacity.go | 34 +++++++++ api/models/v1_size_create_request.go | 65 ++++++++++++++++ api/models/v1_size_reservation.go | 108 +++++++++++++++++++++++++++ api/models/v1_size_response.go | 79 ++++++++++++++++++++ api/models/v1_size_update_request.go | 65 ++++++++++++++++ metal-api.json | 88 +++++++++++++++++++++- 7 files changed, 439 insertions(+), 4 deletions(-) create mode 100644 api/models/v1_size_reservation.go diff --git a/Makefile b/Makefile index 2c043ab9..5fb64fe8 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,8 @@ generate-client: .PHONY: generate-client-local generate-client-local: - yq e -ij ".info.version=\"${METAL_API_VERSION}\"" metal-api.json - yq e '.info.version' metal-api.json + yq e -i -o=json ".info.version=\"${METAL_API_VERSION}\"" metal-api.json + yq e -o=json '.info.version' metal-api.json rm -rf api mkdir -p api docker run --rm \ diff --git a/api/models/v1_server_capacity.go b/api/models/v1_server_capacity.go index e56c52bd..103fffa6 100644 --- a/api/models/v1_server_capacity.go +++ b/api/models/v1_server_capacity.go @@ -43,6 +43,10 @@ type V1ServerCapacity struct { // Required: true Othermachines []string `json:"othermachines" yaml:"othermachines"` + // the amount of reservations for this size + // Required: true + Reservations *int32 `json:"reservations" yaml:"reservations"` + // the size of the server // Required: true Size *string `json:"size" yaml:"size"` @@ -50,6 +54,10 @@ type V1ServerCapacity struct { // total amount of servers with this size // Required: true Total *int32 `json:"total" yaml:"total"` + + // the amount of unused reservations for this size + // Required: true + Unusedreservations *int32 `json:"unusedreservations" yaml:"unusedreservations"` } // Validate validates this v1 server capacity @@ -80,6 +88,10 @@ func (m *V1ServerCapacity) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateReservations(formats); err != nil { + res = append(res, err) + } + if err := m.validateSize(formats); err != nil { res = append(res, err) } @@ -88,6 +100,10 @@ func (m *V1ServerCapacity) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateUnusedreservations(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -148,6 +164,15 @@ func (m *V1ServerCapacity) validateOthermachines(formats strfmt.Registry) error return nil } +func (m *V1ServerCapacity) validateReservations(formats strfmt.Registry) error { + + if err := validate.Required("reservations", "body", m.Reservations); err != nil { + return err + } + + return nil +} + func (m *V1ServerCapacity) validateSize(formats strfmt.Registry) error { if err := validate.Required("size", "body", m.Size); err != nil { @@ -166,6 +191,15 @@ func (m *V1ServerCapacity) validateTotal(formats strfmt.Registry) error { return nil } +func (m *V1ServerCapacity) validateUnusedreservations(formats strfmt.Registry) error { + + if err := validate.Required("unusedreservations", "body", m.Unusedreservations); err != nil { + return err + } + + return nil +} + // ContextValidate validates this v1 server capacity based on context it is used func (m *V1ServerCapacity) ContextValidate(ctx context.Context, formats strfmt.Registry) error { return nil diff --git a/api/models/v1_size_create_request.go b/api/models/v1_size_create_request.go index 2641adf0..21991984 100644 --- a/api/models/v1_size_create_request.go +++ b/api/models/v1_size_create_request.go @@ -31,8 +31,14 @@ type V1SizeCreateRequest struct { // Required: true ID *string `json:"id" yaml:"id"` + // free labels that you associate with this network. + Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` + // a readable name for this entity Name string `json:"name,omitempty" yaml:"name,omitempty"` + + // reservations for this size, which are considered during machine allocation + Reservations []*V1SizeReservation `json:"reservations" yaml:"reservations"` } // Validate validates this v1 size create request @@ -47,6 +53,10 @@ func (m *V1SizeCreateRequest) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateReservations(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -89,6 +99,32 @@ func (m *V1SizeCreateRequest) validateID(formats strfmt.Registry) error { return nil } +func (m *V1SizeCreateRequest) validateReservations(formats strfmt.Registry) error { + if swag.IsZero(m.Reservations) { // not required + return nil + } + + for i := 0; i < len(m.Reservations); i++ { + if swag.IsZero(m.Reservations[i]) { // not required + continue + } + + if m.Reservations[i] != nil { + if err := m.Reservations[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("reservations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("reservations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // ContextValidate validate this v1 size create request based on the context it is used func (m *V1SizeCreateRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error @@ -97,6 +133,10 @@ func (m *V1SizeCreateRequest) ContextValidate(ctx context.Context, formats strfm res = append(res, err) } + if err := m.contextValidateReservations(ctx, formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -128,6 +168,31 @@ func (m *V1SizeCreateRequest) contextValidateConstraints(ctx context.Context, fo return nil } +func (m *V1SizeCreateRequest) contextValidateReservations(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Reservations); i++ { + + if m.Reservations[i] != nil { + + if swag.IsZero(m.Reservations[i]) { // not required + return nil + } + + if err := m.Reservations[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("reservations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("reservations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // MarshalBinary interface implementation func (m *V1SizeCreateRequest) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/api/models/v1_size_reservation.go b/api/models/v1_size_reservation.go new file mode 100644 index 00000000..8a690199 --- /dev/null +++ b/api/models/v1_size_reservation.go @@ -0,0 +1,108 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// V1SizeReservation v1 size reservation +// +// swagger:model v1.SizeReservation +type V1SizeReservation struct { + + // the amount of reserved machine allocations for this size + // Required: true + Amount *int32 `json:"amount" yaml:"amount"` + + // a description for this reservation + Description string `json:"description,omitempty" yaml:"description,omitempty"` + + // the partitions in which this size reservation is considered, the amount is valid for every partition + // Required: true + Partitionids []string `json:"partitionids" yaml:"partitionids"` + + // the project for which this size reservation is considered + // Required: true + Projectid *string `json:"projectid" yaml:"projectid"` +} + +// Validate validates this v1 size reservation +func (m *V1SizeReservation) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAmount(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePartitionids(formats); err != nil { + res = append(res, err) + } + + if err := m.validateProjectid(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *V1SizeReservation) validateAmount(formats strfmt.Registry) error { + + if err := validate.Required("amount", "body", m.Amount); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservation) validatePartitionids(formats strfmt.Registry) error { + + if err := validate.Required("partitionids", "body", m.Partitionids); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservation) validateProjectid(formats strfmt.Registry) error { + + if err := validate.Required("projectid", "body", m.Projectid); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this v1 size reservation based on context it is used +func (m *V1SizeReservation) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *V1SizeReservation) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *V1SizeReservation) UnmarshalBinary(b []byte) error { + var res V1SizeReservation + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/models/v1_size_response.go b/api/models/v1_size_response.go index e7c5a024..e7105dac 100644 --- a/api/models/v1_size_response.go +++ b/api/models/v1_size_response.go @@ -41,8 +41,15 @@ type V1SizeResponse struct { // Required: true ID *string `json:"id" yaml:"id"` + // free labels that you associate with this network. + // Required: true + Labels map[string]string `json:"labels" yaml:"labels"` + // a readable name for this entity Name string `json:"name,omitempty" yaml:"name,omitempty"` + + // reservations for this size, which are considered during machine allocation + Reservations []*V1SizeReservation `json:"reservations" yaml:"reservations"` } // Validate validates this v1 size response @@ -65,6 +72,14 @@ func (m *V1SizeResponse) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateLabels(formats); err != nil { + res = append(res, err) + } + + if err := m.validateReservations(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -131,6 +146,41 @@ func (m *V1SizeResponse) validateID(formats strfmt.Registry) error { return nil } +func (m *V1SizeResponse) validateLabels(formats strfmt.Registry) error { + + if err := validate.Required("labels", "body", m.Labels); err != nil { + return err + } + + return nil +} + +func (m *V1SizeResponse) validateReservations(formats strfmt.Registry) error { + if swag.IsZero(m.Reservations) { // not required + return nil + } + + for i := 0; i < len(m.Reservations); i++ { + if swag.IsZero(m.Reservations[i]) { // not required + continue + } + + if m.Reservations[i] != nil { + if err := m.Reservations[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("reservations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("reservations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // ContextValidate validate this v1 size response based on the context it is used func (m *V1SizeResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error @@ -147,6 +197,10 @@ func (m *V1SizeResponse) ContextValidate(ctx context.Context, formats strfmt.Reg res = append(res, err) } + if err := m.contextValidateReservations(ctx, formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -196,6 +250,31 @@ func (m *V1SizeResponse) contextValidateCreated(ctx context.Context, formats str return nil } +func (m *V1SizeResponse) contextValidateReservations(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Reservations); i++ { + + if m.Reservations[i] != nil { + + if swag.IsZero(m.Reservations[i]) { // not required + return nil + } + + if err := m.Reservations[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("reservations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("reservations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // MarshalBinary interface implementation func (m *V1SizeResponse) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/api/models/v1_size_update_request.go b/api/models/v1_size_update_request.go index e0fa1063..d217f366 100644 --- a/api/models/v1_size_update_request.go +++ b/api/models/v1_size_update_request.go @@ -30,8 +30,14 @@ type V1SizeUpdateRequest struct { // Required: true ID *string `json:"id" yaml:"id"` + // free labels that you associate with this network. + Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` + // a readable name for this entity Name string `json:"name,omitempty" yaml:"name,omitempty"` + + // reservations for this size, which are considered during machine allocation + Reservations []*V1SizeReservation `json:"reservations" yaml:"reservations"` } // Validate validates this v1 size update request @@ -46,6 +52,10 @@ func (m *V1SizeUpdateRequest) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateReservations(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -87,6 +97,32 @@ func (m *V1SizeUpdateRequest) validateID(formats strfmt.Registry) error { return nil } +func (m *V1SizeUpdateRequest) validateReservations(formats strfmt.Registry) error { + if swag.IsZero(m.Reservations) { // not required + return nil + } + + for i := 0; i < len(m.Reservations); i++ { + if swag.IsZero(m.Reservations[i]) { // not required + continue + } + + if m.Reservations[i] != nil { + if err := m.Reservations[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("reservations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("reservations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // ContextValidate validate this v1 size update request based on the context it is used func (m *V1SizeUpdateRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error @@ -95,6 +131,10 @@ func (m *V1SizeUpdateRequest) ContextValidate(ctx context.Context, formats strfm res = append(res, err) } + if err := m.contextValidateReservations(ctx, formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -126,6 +166,31 @@ func (m *V1SizeUpdateRequest) contextValidateConstraints(ctx context.Context, fo return nil } +func (m *V1SizeUpdateRequest) contextValidateReservations(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Reservations); i++ { + + if m.Reservations[i] != nil { + + if swag.IsZero(m.Reservations[i]) { // not required + return nil + } + + if err := m.Reservations[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("reservations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("reservations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // MarshalBinary interface implementation func (m *V1SizeUpdateRequest) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/metal-api.json b/metal-api.json index b905a814..d5fc508e 100644 --- a/metal-api.json +++ b/metal-api.json @@ -4248,6 +4248,11 @@ }, "type": "array" }, + "reservations": { + "description": "the amount of reservations for this size", + "format": "int32", + "type": "integer" + }, "size": { "description": "the size of the server", "type": "string" @@ -4256,6 +4261,11 @@ "description": "total amount of servers with this size", "format": "int32", "type": "integer" + }, + "unusedreservations": { + "description": "the amount of unused reservations for this size", + "format": "int32", + "type": "integer" } }, "required": [ @@ -4265,8 +4275,10 @@ "free", "other", "othermachines", + "reservations", "size", - "total" + "total", + "unusedreservations" ] }, "v1.SizeConstraint": { @@ -4337,9 +4349,23 @@ "type": "string", "uniqueItems": true }, + "labels": { + "additionalProperties": { + "type": "string" + }, + "description": "free labels that you associate with this network.", + "type": "object" + }, "name": { "description": "a readable name for this entity", "type": "string" + }, + "reservations": { + "description": "reservations for this size, which are considered during machine allocation", + "items": { + "$ref": "#/definitions/v1.SizeReservation" + }, + "type": "array" } }, "required": [ @@ -4473,6 +4499,35 @@ "name" ] }, + "v1.SizeReservation": { + "properties": { + "amount": { + "description": "the amount of reserved machine allocations for this size", + "format": "int32", + "type": "integer" + }, + "description": { + "description": "a description for this reservation", + "type": "string" + }, + "partitionids": { + "description": "the partitions in which this size reservation is considered, the amount is valid for every partition", + "items": { + "type": "string" + }, + "type": "array" + }, + "projectid": { + "description": "the project for which this size reservation is considered", + "type": "string" + } + }, + "required": [ + "amount", + "partitionids", + "projectid" + ] + }, "v1.SizeResponse": { "properties": { "changed": { @@ -4503,14 +4558,29 @@ "type": "string", "uniqueItems": true }, + "labels": { + "additionalProperties": { + "type": "string" + }, + "description": "free labels that you associate with this network.", + "type": "object" + }, "name": { "description": "a readable name for this entity", "type": "string" + }, + "reservations": { + "description": "reservations for this size, which are considered during machine allocation", + "items": { + "$ref": "#/definitions/v1.SizeReservation" + }, + "type": "array" } }, "required": [ "constraints", - "id" + "id", + "labels" ] }, "v1.SizeSuggestRequest": { @@ -4542,9 +4612,23 @@ "type": "string", "uniqueItems": true }, + "labels": { + "additionalProperties": { + "type": "string" + }, + "description": "free labels that you associate with this network.", + "type": "object" + }, "name": { "description": "a readable name for this entity", "type": "string" + }, + "reservations": { + "description": "reservations for this size, which are considered during machine allocation", + "items": { + "$ref": "#/definitions/v1.SizeReservation" + }, + "type": "array" } }, "required": [