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

configurable reserve of machines per size per partition #134

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions cmd/metal-api/internal/metal/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Partition struct {
BootConfiguration BootConfiguration `rethinkdb:"bootconfig" json:"bootconfig"`
MgmtServiceAddress string `rethinkdb:"mgmtserviceaddr" json:"mgmtserviceaddr"`
PrivateNetworkPrefixLength int `rethinkdb:"privatenetworkprefixlength" json:"privatenetworkprefixlength"`
MachineReserve MachineReserve `rethinkdb:"machinereserve" json:"machinereserve"`
}

// BootConfiguration defines the metal-hammer initrd, kernel and commandline
Expand All @@ -15,6 +16,9 @@ type BootConfiguration struct {
CommandLine string `rethinkdb:"commandline" json:"commandline"`
}

// MachineReserve configures spare machine size to count
type MachineReserve map[string]int

// Partitions is a list of partitions.
type Partitions []Partition

Expand Down
15 changes: 15 additions & 0 deletions cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ func (r partitionResource) createPartition(request *restful.Request, response *r
if requestPayload.PartitionBootConfiguration.CommandLine != nil {
commandLine = *requestPayload.PartitionBootConfiguration.CommandLine
}
mr := metal.MachineReserve{}
if requestPayload.MachineReserve != nil {
for k, v := range *requestPayload.MachineReserve {
mr[k] = v
}
}

p := &metal.Partition{
Base: metal.Base{
Expand All @@ -207,6 +213,7 @@ func (r partitionResource) createPartition(request *restful.Request, response *r
KernelURL: kernelURL,
CommandLine: commandLine,
},
MachineReserve: mr,
}

fqn := metal.TopicMachine.GetFQN(p.GetID())
Expand Down Expand Up @@ -279,6 +286,13 @@ func (r partitionResource) updatePartition(request *restful.Request, response *r
if requestPayload.PartitionBootConfiguration.CommandLine != nil {
newPartition.BootConfiguration.CommandLine = *requestPayload.PartitionBootConfiguration.CommandLine
}
if requestPayload.MachineReserve != nil {
mr := metal.MachineReserve{}
for k, v := range *requestPayload.MachineReserve {
mr[k] = v
}
newPartition.MachineReserve = mr
}

err = r.ds.UpdatePartition(oldPartition, &newPartition)
if checkError(request, response, utils.CurrentFuncName(), err) {
Expand Down Expand Up @@ -361,6 +375,7 @@ func (r partitionResource) calcPartitionCapacity() ([]v1.PartitionCapacity, erro
cap.OtherMachines = append(cap.OtherMachines, m.ID)
}

cap.Reserved = p.MachineReserve[size]
cap.Total++
}
sc := []v1.ServerCapacity{}
Expand Down
11 changes: 11 additions & 0 deletions cmd/metal-api/internal/service/v1/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@ type PartitionCreateRequest struct {
Common
PartitionBase
PartitionBootConfiguration PartitionBootConfiguration `json:"bootconfig" description:"the boot configuration of this partition"`
MachineReserve *MachineReserve `json:"machine_reserve,omitempty"`
}

type PartitionUpdateRequest struct {
Common
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"`
MachineReserve *MachineReserve `json:"machine_reserve,omitempty"`
}

type PartitionResponse struct {
Common
PartitionBase
PartitionBootConfiguration PartitionBootConfiguration `json:"bootconfig" description:"the boot configuration of this partition"`
Timestamps
MachineReserve *MachineReserve `json:"machine_reserve,omitempty"`
}

type PartitionCapacity struct {
Common
ServerCapacities []ServerCapacity `json:"servers" description:"servers available in this partition"`
}

type MachineReserve map[string]int

type ServerCapacity struct {
Size string `json:"size" description:"the size of the server"`
Total int `json:"total" description:"total amount of servers with this size"`
Expand All @@ -48,12 +53,17 @@ type ServerCapacity struct {
FaultyMachines []string `json:"faultymachines" description:"servers with issues with this size"`
Other int `json:"other" description:"servers neither free, allocated or faulty with this size"`
OtherMachines []string `json:"othermachines" description:"servers neither free, allocated or faulty with this size"`
Reserved int `json:"reserved" description:"reserved machines"`
}

func NewPartitionResponse(p *metal.Partition) *PartitionResponse {
if p == nil {
return nil
}
mr := MachineReserve{}
for k, v := range p.MachineReserve {
mr[k] = v
}
return &PartitionResponse{
Common: Common{
Identifiable: Identifiable{
Expand All @@ -77,5 +87,6 @@ func NewPartitionResponse(p *metal.Partition) *PartitionResponse {
Created: p.Created,
Changed: p.Changed,
},
MachineReserve: &mr,
}
}
21 changes: 21 additions & 0 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,12 @@
"imageid"
]
},
"v1.MachineReserve": {
"additionalProperties": {
"type": "integer"
},
"type": "object"
},
"v1.MachineResponse": {
"properties": {
"allocation": {
Expand Down Expand Up @@ -2373,6 +2379,9 @@
"type": "string",
"uniqueItems": true
},
"machine_reserve": {
"$ref": "#/definitions/v1.MachineReserve"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -2421,6 +2430,9 @@
"type": "string",
"uniqueItems": true
},
"machine_reserve": {
"$ref": "#/definitions/v1.MachineReserve"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -2457,6 +2469,9 @@
"type": "string",
"uniqueItems": true
},
"machine_reserve": {
"$ref": "#/definitions/v1.MachineReserve"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -2607,6 +2622,11 @@
},
"type": "array"
},
"reserved": {
"description": "reserved machines",
"format": "int32",
"type": "integer"
},
"size": {
"description": "the size of the server",
"type": "string"
Expand All @@ -2624,6 +2644,7 @@
"free",
"other",
"othermachines",
"reserved",
"size",
"total"
]
Expand Down