diff --git a/VERSION b/VERSION index 70449b9..eaf8bae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.25.1 +v0.26.0 diff --git a/api/client/size/list_size_reservations_parameters.go b/api/client/size/list_size_reservations_parameters.go new file mode 100644 index 0000000..4bc31a9 --- /dev/null +++ b/api/client/size/list_size_reservations_parameters.go @@ -0,0 +1,128 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package size + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewListSizeReservationsParams creates a new ListSizeReservationsParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewListSizeReservationsParams() *ListSizeReservationsParams { + return &ListSizeReservationsParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewListSizeReservationsParamsWithTimeout creates a new ListSizeReservationsParams object +// with the ability to set a timeout on a request. +func NewListSizeReservationsParamsWithTimeout(timeout time.Duration) *ListSizeReservationsParams { + return &ListSizeReservationsParams{ + timeout: timeout, + } +} + +// NewListSizeReservationsParamsWithContext creates a new ListSizeReservationsParams object +// with the ability to set a context for a request. +func NewListSizeReservationsParamsWithContext(ctx context.Context) *ListSizeReservationsParams { + return &ListSizeReservationsParams{ + Context: ctx, + } +} + +// NewListSizeReservationsParamsWithHTTPClient creates a new ListSizeReservationsParams object +// with the ability to set a custom HTTPClient for a request. +func NewListSizeReservationsParamsWithHTTPClient(client *http.Client) *ListSizeReservationsParams { + return &ListSizeReservationsParams{ + HTTPClient: client, + } +} + +/* +ListSizeReservationsParams contains all the parameters to send to the API endpoint + + for the list size reservations operation. + + Typically these are written to a http.Request. +*/ +type ListSizeReservationsParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the list size reservations params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *ListSizeReservationsParams) WithDefaults() *ListSizeReservationsParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the list size reservations params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *ListSizeReservationsParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the list size reservations params +func (o *ListSizeReservationsParams) WithTimeout(timeout time.Duration) *ListSizeReservationsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the list size reservations params +func (o *ListSizeReservationsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the list size reservations params +func (o *ListSizeReservationsParams) WithContext(ctx context.Context) *ListSizeReservationsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the list size reservations params +func (o *ListSizeReservationsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the list size reservations params +func (o *ListSizeReservationsParams) WithHTTPClient(client *http.Client) *ListSizeReservationsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the list size reservations params +func (o *ListSizeReservationsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *ListSizeReservationsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/client/size/list_size_reservations_responses.go b/api/client/size/list_size_reservations_responses.go new file mode 100644 index 0000000..c334147 --- /dev/null +++ b/api/client/size/list_size_reservations_responses.go @@ -0,0 +1,181 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package size + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/metal-stack/metal-go/api/models" + "github.com/metal-stack/metal-lib/httperrors" +) + +// ListSizeReservationsReader is a Reader for the ListSizeReservations structure. +type ListSizeReservationsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *ListSizeReservationsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewListSizeReservationsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewListSizeReservationsDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewListSizeReservationsOK creates a ListSizeReservationsOK with default headers values +func NewListSizeReservationsOK() *ListSizeReservationsOK { + return &ListSizeReservationsOK{} +} + +/* +ListSizeReservationsOK describes a response with status code 200, with default header values. + +OK +*/ +type ListSizeReservationsOK struct { + Payload []*models.V1SizeReservationResponse +} + +// IsSuccess returns true when this list size reservations o k response has a 2xx status code +func (o *ListSizeReservationsOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this list size reservations o k response has a 3xx status code +func (o *ListSizeReservationsOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this list size reservations o k response has a 4xx status code +func (o *ListSizeReservationsOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this list size reservations o k response has a 5xx status code +func (o *ListSizeReservationsOK) IsServerError() bool { + return false +} + +// IsCode returns true when this list size reservations o k response a status code equal to that given +func (o *ListSizeReservationsOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the list size reservations o k response +func (o *ListSizeReservationsOK) Code() int { + return 200 +} + +func (o *ListSizeReservationsOK) Error() string { + return fmt.Sprintf("[POST /v1/size/reservations][%d] listSizeReservationsOK %+v", 200, o.Payload) +} + +func (o *ListSizeReservationsOK) String() string { + return fmt.Sprintf("[POST /v1/size/reservations][%d] listSizeReservationsOK %+v", 200, o.Payload) +} + +func (o *ListSizeReservationsOK) GetPayload() []*models.V1SizeReservationResponse { + return o.Payload +} + +func (o *ListSizeReservationsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewListSizeReservationsDefault creates a ListSizeReservationsDefault with default headers values +func NewListSizeReservationsDefault(code int) *ListSizeReservationsDefault { + return &ListSizeReservationsDefault{ + _statusCode: code, + } +} + +/* +ListSizeReservationsDefault describes a response with status code -1, with default header values. + +Error +*/ +type ListSizeReservationsDefault struct { + _statusCode int + + Payload *httperrors.HTTPErrorResponse +} + +// IsSuccess returns true when this list size reservations default response has a 2xx status code +func (o *ListSizeReservationsDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this list size reservations default response has a 3xx status code +func (o *ListSizeReservationsDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this list size reservations default response has a 4xx status code +func (o *ListSizeReservationsDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this list size reservations default response has a 5xx status code +func (o *ListSizeReservationsDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this list size reservations default response a status code equal to that given +func (o *ListSizeReservationsDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the list size reservations default response +func (o *ListSizeReservationsDefault) Code() int { + return o._statusCode +} + +func (o *ListSizeReservationsDefault) Error() string { + return fmt.Sprintf("[POST /v1/size/reservations][%d] listSizeReservations default %+v", o._statusCode, o.Payload) +} + +func (o *ListSizeReservationsDefault) String() string { + return fmt.Sprintf("[POST /v1/size/reservations][%d] listSizeReservations default %+v", o._statusCode, o.Payload) +} + +func (o *ListSizeReservationsDefault) GetPayload() *httperrors.HTTPErrorResponse { + return o.Payload +} + +func (o *ListSizeReservationsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(httperrors.HTTPErrorResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/api/client/size/size_client.go b/api/client/size/size_client.go index 729c42b..8489ae6 100644 --- a/api/client/size/size_client.go +++ b/api/client/size/size_client.go @@ -36,6 +36,8 @@ type ClientService interface { FromHardware(params *FromHardwareParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*FromHardwareOK, error) + ListSizeReservations(params *ListSizeReservationsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListSizeReservationsOK, error) + ListSizes(params *ListSizesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListSizesOK, error) Suggest(params *SuggestParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*SuggestOK, error) @@ -197,6 +199,44 @@ func (a *Client) FromHardware(params *FromHardwareParams, authInfo runtime.Clien return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +ListSizeReservations gets all size reservations +*/ +func (a *Client) ListSizeReservations(params *ListSizeReservationsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListSizeReservationsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewListSizeReservationsParams() + } + op := &runtime.ClientOperation{ + ID: "listSizeReservations", + Method: "POST", + PathPattern: "/v1/size/reservations", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &ListSizeReservationsReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*ListSizeReservationsOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*ListSizeReservationsDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* ListSizes gets all sizes */ diff --git a/api/models/v1_server_capacity.go b/api/models/v1_server_capacity.go index e56c52b..4104f38 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 used reservations for this size + // Required: true + Usedreservations *int32 `json:"usedreservations" yaml:"usedreservations"` } // 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.validateUsedreservations(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) validateUsedreservations(formats strfmt.Registry) error { + + if err := validate.Required("usedreservations", "body", m.Usedreservations); 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 2641adf..2199198 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 0000000..8a69019 --- /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_reservation_response.go b/api/models/v1_size_reservation_response.go new file mode 100644 index 0000000..c7795bf --- /dev/null +++ b/api/models/v1_size_reservation_response.go @@ -0,0 +1,190 @@ +// 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" +) + +// V1SizeReservationResponse v1 size reservation response +// +// swagger:model v1.SizeReservationResponse +type V1SizeReservationResponse struct { + + // the partition id of this size reservation + // Required: true + Partitionid *string `json:"partitionid" yaml:"partitionid"` + + // the amount of allocations of this project referenced by this size reservation + // Required: true + Projectallocations *int32 `json:"projectallocations" yaml:"projectallocations"` + + // the project id of this size reservation + // Required: true + Projectid *string `json:"projectid" yaml:"projectid"` + + // the project name of this size reservation + // Required: true + Projectname *string `json:"projectname" yaml:"projectname"` + + // the amount of reservations of this size reservation + // Required: true + Reservations *int32 `json:"reservations" yaml:"reservations"` + + // the size id of this size reservation + // Required: true + Sizeid *string `json:"sizeid" yaml:"sizeid"` + + // the tenant of this size reservation + // Required: true + Tenant *string `json:"tenant" yaml:"tenant"` + + // the used amount of reservations of this size reservation + // Required: true + Usedreservations *int32 `json:"usedreservations" yaml:"usedreservations"` +} + +// Validate validates this v1 size reservation response +func (m *V1SizeReservationResponse) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validatePartitionid(formats); err != nil { + res = append(res, err) + } + + if err := m.validateProjectallocations(formats); err != nil { + res = append(res, err) + } + + if err := m.validateProjectid(formats); err != nil { + res = append(res, err) + } + + if err := m.validateProjectname(formats); err != nil { + res = append(res, err) + } + + if err := m.validateReservations(formats); err != nil { + res = append(res, err) + } + + if err := m.validateSizeid(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTenant(formats); err != nil { + res = append(res, err) + } + + if err := m.validateUsedreservations(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *V1SizeReservationResponse) validatePartitionid(formats strfmt.Registry) error { + + if err := validate.Required("partitionid", "body", m.Partitionid); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateProjectallocations(formats strfmt.Registry) error { + + if err := validate.Required("projectallocations", "body", m.Projectallocations); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateProjectid(formats strfmt.Registry) error { + + if err := validate.Required("projectid", "body", m.Projectid); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateProjectname(formats strfmt.Registry) error { + + if err := validate.Required("projectname", "body", m.Projectname); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateReservations(formats strfmt.Registry) error { + + if err := validate.Required("reservations", "body", m.Reservations); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateSizeid(formats strfmt.Registry) error { + + if err := validate.Required("sizeid", "body", m.Sizeid); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateTenant(formats strfmt.Registry) error { + + if err := validate.Required("tenant", "body", m.Tenant); err != nil { + return err + } + + return nil +} + +func (m *V1SizeReservationResponse) validateUsedreservations(formats strfmt.Registry) error { + + if err := validate.Required("usedreservations", "body", m.Usedreservations); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this v1 size reservation response based on context it is used +func (m *V1SizeReservationResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *V1SizeReservationResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *V1SizeReservationResponse) UnmarshalBinary(b []byte) error { + var res V1SizeReservationResponse + 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 e7c5a02..e7105da 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 e0fa106..d217f36 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 b905a81..ba675b2 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" + }, + "usedreservations": { + "description": "the amount of used reservations for this size", + "format": "int32", + "type": "integer" } }, "required": [ @@ -4265,8 +4275,10 @@ "free", "other", "othermachines", + "reservations", "size", - "total" + "total", + "usedreservations" ] }, "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,84 @@ "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.SizeReservationResponse": { + "properties": { + "partitionid": { + "description": "the partition id of this size reservation", + "type": "string" + }, + "projectallocations": { + "description": "the amount of allocations of this project referenced by this size reservation", + "format": "int32", + "type": "integer" + }, + "projectid": { + "description": "the project id of this size reservation", + "type": "string" + }, + "projectname": { + "description": "the project name of this size reservation", + "type": "string" + }, + "reservations": { + "description": "the amount of reservations of this size reservation", + "format": "int32", + "type": "integer" + }, + "sizeid": { + "description": "the size id of this size reservation", + "type": "string" + }, + "tenant": { + "description": "the tenant of this size reservation", + "type": "string" + }, + "usedreservations": { + "description": "the used amount of reservations of this size reservation", + "format": "int32", + "type": "integer" + } + }, + "required": [ + "partitionid", + "projectallocations", + "projectid", + "projectname", + "reservations", + "sizeid", + "tenant", + "usedreservations" + ] + }, "v1.SizeResponse": { "properties": { "changed": { @@ -4503,14 +4607,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 +4661,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": [ @@ -5163,7 +5296,7 @@ "url": "https://www.gnu.org/licenses/agpl-3.0.de.html" }, "title": "metal-api", - "version": "v0.25.1" + "version": "v0.26.0" }, "paths": { "/v1/audit/find": { @@ -8801,6 +8934,38 @@ ] } }, + "/v1/size/reservations": { + "post": { + "consumes": [ + "application/json" + ], + "operationId": "listSizeReservations", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "items": { + "$ref": "#/definitions/v1.SizeReservationResponse" + }, + "type": "array" + } + }, + "default": { + "description": "Error", + "schema": { + "$ref": "#/definitions/httperrors.HTTPErrorResponse" + } + } + }, + "summary": "get all size reservations", + "tags": [ + "size" + ] + } + }, "/v1/size/suggest": { "post": { "consumes": [ diff --git a/test/mocks/size/ClientService.go b/test/mocks/size/ClientService.go index ebb3ae9..a62e153 100644 --- a/test/mocks/size/ClientService.go +++ b/test/mocks/size/ClientService.go @@ -146,6 +146,39 @@ func (_m *ClientService) FromHardware(params *clientsize.FromHardwareParams, aut return r0, r1 } +// ListSizeReservations provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) ListSizeReservations(params *clientsize.ListSizeReservationsParams, authInfo runtime.ClientAuthInfoWriter, opts ...clientsize.ClientOption) (*clientsize.ListSizeReservationsOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *clientsize.ListSizeReservationsOK + var r1 error + if rf, ok := ret.Get(0).(func(*clientsize.ListSizeReservationsParams, runtime.ClientAuthInfoWriter, ...clientsize.ClientOption) (*clientsize.ListSizeReservationsOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*clientsize.ListSizeReservationsParams, runtime.ClientAuthInfoWriter, ...clientsize.ClientOption) *clientsize.ListSizeReservationsOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*clientsize.ListSizeReservationsOK) + } + } + + if rf, ok := ret.Get(1).(func(*clientsize.ListSizeReservationsParams, runtime.ClientAuthInfoWriter, ...clientsize.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // ListSizes provides a mock function with given fields: params, authInfo, opts func (_m *ClientService) ListSizes(params *clientsize.ListSizesParams, authInfo runtime.ClientAuthInfoWriter, opts ...clientsize.ClientOption) (*clientsize.ListSizesOK, error) { _va := make([]interface{}, len(opts))