Skip to content

Commit

Permalink
Allow update DefaultChildPrefixLength
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Jan 2, 2025
1 parent e726090 commit c9c4b7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/metal/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/metal-api/internal/service/network-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/metal-api/internal/service/v1/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c9c4b7e

Please sign in to comment.