Skip to content

Commit

Permalink
Allow updating partition NTP and DNS servers. (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Nov 8, 2024
1 parent 5ce407c commit 3f09c81
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
28 changes: 28 additions & 0 deletions cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 22 additions & 0 deletions cmd/metal-api/internal/service/partition-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions cmd/metal-api/internal/service/v1/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": {
Expand Down

0 comments on commit 3f09c81

Please sign in to comment.