diff --git a/cmd/metal-api/internal/service/partition-service.go b/cmd/metal-api/internal/service/partition-service.go index 81fae26f..58d77e6a 100644 --- a/cmd/metal-api/internal/service/partition-service.go +++ b/cmd/metal-api/internal/service/partition-service.go @@ -333,6 +333,34 @@ func (r *partitionResource) updatePartition(request *restful.Request, response * newPartition.BootConfiguration.CommandLine = *requestPayload.PartitionBootConfiguration.CommandLine } + if requestPayload.DNSServers != nil { + newPartition.DNSServers = metal.DNSServers{} + for _, s := range requestPayload.DNSServers { + newPartition.DNSServers = append(newPartition.DNSServers, metal.DNSServer{ + IP: s.IP, + }) + } + } + + if requestPayload.NTPServers != nil { + newPartition.NTPServers = metal.NTPServers{} + for _, s := range requestPayload.NTPServers { + newPartition.NTPServers = append(newPartition.NTPServers, metal.NTPServer{ + Address: s.Address, + }) + } + } + + if err := newPartition.DNSServers.Validate(); err != nil { + r.sendError(request, response, httperrors.BadRequest(err)) + return + } + + if err := newPartition.NTPServers.Validate(); err != nil { + r.sendError(request, response, httperrors.BadRequest(err)) + return + } + err = r.ds.UpdatePartition(oldPartition, &newPartition) if err != nil { r.sendError(request, response, httperrors.BadRequest(err)) diff --git a/cmd/metal-api/internal/service/partition-service_test.go b/cmd/metal-api/internal/service/partition-service_test.go index 06a03275..1d57dab2 100644 --- a/cmd/metal-api/internal/service/partition-service_test.go +++ b/cmd/metal-api/internal/service/partition-service_test.go @@ -224,6 +224,17 @@ func TestUpdatePartition(t *testing.T) { PartitionBootConfiguration: &v1.PartitionBootConfiguration{ ImageURL: &downloadableFile, }, + NTPServers: []v1.NTPServer{ + { + Address: "ntp.address1", + }, + { + Address: "ntp.address2", + }, + { + Address: "ntp.address3", + }, + }, } js, err := json.Marshal(updateRequest) require.NoError(t, err) @@ -246,6 +257,17 @@ func TestUpdatePartition(t *testing.T) { require.Equal(t, testdata.Partition2.Description, *result.Description) require.Equal(t, mgmtService, *result.MgmtServiceAddress) require.Equal(t, downloadableFile, *result.PartitionBootConfiguration.ImageURL) + require.Equal(t, []v1.NTPServer{ + { + Address: "ntp.address1", + }, + { + Address: "ntp.address2", + }, + { + Address: "ntp.address3", + }, + }, result.NTPServers) } func TestPartitionCapacity(t *testing.T) { diff --git a/cmd/metal-api/internal/service/v1/partition.go b/cmd/metal-api/internal/service/v1/partition.go index 0e5d3cec..fc0c7e96 100644 --- a/cmd/metal-api/internal/service/v1/partition.go +++ b/cmd/metal-api/internal/service/v1/partition.go @@ -8,8 +8,8 @@ type PartitionBase struct { MgmtServiceAddress *string `json:"mgmtserviceaddress" description:"the address to the management service of this partition" optional:"true"` PrivateNetworkPrefixLength *int `json:"privatenetworkprefixlength" description:"the length of private networks for the machine's child networks in this partition, default 22" optional:"true" minimum:"16" maximum:"30"` Labels map[string]string `json:"labels" description:"free labels that you associate with this partition" optional:"true"` - DNSServers []DNSServer `json:"dns_servers" description:"the dns servers for this partition" optional:"true"` - NTPServers []NTPServer `json:"ntp_servers" description:"the ntp servers for this partition" optional:"true"` + DNSServers []DNSServer `json:"dns_servers,omitempty" description:"the dns servers for this partition" optional:"true"` + NTPServers []NTPServer `json:"ntp_servers,omitempty" description:"the ntp servers for this partition" optional:"true"` } type PartitionBootConfiguration struct { @@ -29,6 +29,8 @@ type PartitionUpdateRequest struct { MgmtServiceAddress *string `json:"mgmtserviceaddress" description:"the address to the management service of this partition" optional:"true"` PartitionBootConfiguration *PartitionBootConfiguration `json:"bootconfig" description:"the boot configuration of this partition" optional:"true"` Labels map[string]string `json:"labels" description:"free labels that you associate with this partition" optional:"true"` + DNSServers []DNSServer `json:"dns_servers" description:"the dns servers for this partition"` + NTPServers []NTPServer `json:"ntp_servers" description:"the ntp servers for this partition"` } type PartitionResponse struct { diff --git a/spec/metal-api.json b/spec/metal-api.json index 79df1274..721eea9f 100644 --- a/spec/metal-api.json +++ b/spec/metal-api.json @@ -4311,6 +4311,13 @@ "description": "a description for this entity", "type": "string" }, + "dns_servers": { + "description": "the dns servers for this partition", + "items": { + "$ref": "#/definitions/v1.DNSServer" + }, + "type": "array" + }, "id": { "description": "the unique ID of this entity", "type": "string" @@ -4329,10 +4336,19 @@ "name": { "description": "a readable name for this entity", "type": "string" + }, + "ntp_servers": { + "description": "the ntp servers for this partition", + "items": { + "$ref": "#/definitions/v1.NTPServer" + }, + "type": "array" } }, "required": [ - "id" + "dns_servers", + "id", + "ntp_servers" ] }, "v1.PowerMetric": {