From c9c4b7e67ad4943a10cee6725f66e13cfd4b1fc6 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 2 Jan 2025 10:22:17 +0100 Subject: [PATCH] Allow update DefaultChildPrefixLength --- cmd/metal-api/internal/metal/switch.go | 2 +- .../internal/service/network-service.go | 16 ++++++++++++++++ cmd/metal-api/internal/service/v1/network.go | 1 + spec/metal-api.json | 7 +++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/metal-api/internal/metal/switch.go b/cmd/metal-api/internal/metal/switch.go index 4d717d44..89ae786f 100644 --- a/cmd/metal-api/internal/metal/switch.go +++ b/cmd/metal-api/internal/metal/switch.go @@ -201,7 +201,7 @@ func (s *Switch) TranslateNicMap(targetOS SwitchOSVendor) (NicMap, error) { nic, ok := nicMap[p] if !ok { - return nil, fmt.Errorf("an unknown error occured during port name translation") + return nil, fmt.Errorf("an unknown error occurred during port name translation") } translatedNicMap[targetPort] = nic } diff --git a/cmd/metal-api/internal/service/network-service.go b/cmd/metal-api/internal/service/network-service.go index 7a9db59b..f25d6f8a 100644 --- a/cmd/metal-api/internal/service/network-service.go +++ b/cmd/metal-api/internal/service/network-service.go @@ -798,6 +798,11 @@ func (r *networkResource) updateNetwork(request *restful.Request, response *rest return } + if len(requestPayload.DefaultChildPrefixLength) > 0 && !oldNetwork.PrivateSuper { + r.sendError(request, response, defaultError(errors.New("defaultchildprefixlength can only be set on privatesuper"))) + return + } + var ( prefixesToBeRemoved metal.Prefixes prefixesToBeAdded metal.Prefixes @@ -845,6 +850,17 @@ func (r *networkResource) updateNetwork(request *restful.Request, response *rest } newNetwork.AddressFamilies = addressFamilies + if len(requestPayload.DefaultChildPrefixLength) > 0 { + for af, defaultChildPrefixLength := range requestPayload.DefaultChildPrefixLength { + afExists := newNetwork.AddressFamilies[af] + if !afExists { + r.sendError(request, response, defaultError(fmt.Errorf("no addressfamily %q present for defaultchildprefixlength: %d", af, defaultChildPrefixLength))) + return + } + } + newNetwork.DefaultChildPrefixLength = requestPayload.DefaultChildPrefixLength + } + ctx := request.Request.Context() for _, p := range prefixesToBeRemoved { diff --git a/cmd/metal-api/internal/service/v1/network.go b/cmd/metal-api/internal/service/v1/network.go index c991320f..22be99d2 100644 --- a/cmd/metal-api/internal/service/v1/network.go +++ b/cmd/metal-api/internal/service/v1/network.go @@ -68,6 +68,7 @@ type NetworkUpdateRequest struct { Labels map[string]string `json:"labels" description:"free labels that you associate with this network." optional:"true"` Shared *bool `json:"shared" description:"marks a network as shareable." optional:"true"` AdditionalAnnouncableCIDRs []string `json:"additionalAnnouncableCIDRs" description:"list of cidrs which are added to the route maps per tenant private network, these are typically pod- and service cidrs, can only be set for private super networks" optional:"true"` + DefaultChildPrefixLength metal.ChildPrefixLength `json:"defaultchildprefixlength" description:"if privatesuper, this defines the bitlen of child prefixes per addressfamily if not nil" optional:"true"` } // NetworkResponse holds all properties returned in a FindNetwork or GetNetwork request. diff --git a/spec/metal-api.json b/spec/metal-api.json index 400391bf..e91510b2 100644 --- a/spec/metal-api.json +++ b/spec/metal-api.json @@ -4084,6 +4084,13 @@ }, "type": "array" }, + "defaultchildprefixlength": { + "additionalProperties": { + "type": "integer" + }, + "description": "if privatesuper, this defines the bitlen of child prefixes per addressfamily if not nil", + "type": "object" + }, "description": { "description": "a description for this entity", "type": "string"