Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow updating partition NTP and DNS servers. #589

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading