Simplify logic when creating a new installer; no longer requires an entire server object be passed.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
@@ -44,10 +43,13 @@ func getAllServers(c *gin.Context) {
|
||||
// for it.
|
||||
func postCreateServer(c *gin.Context) {
|
||||
manager := middleware.ExtractManager(c)
|
||||
buf := bytes.Buffer{}
|
||||
buf.ReadFrom(c.Request.Body)
|
||||
|
||||
install, err := installer.New(c.Request.Context(), manager, buf.Bytes())
|
||||
details := installer.ServerDetails{}
|
||||
if err := c.BindJSON(&details); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
install, err := installer.New(c.Request.Context(), manager, details)
|
||||
if err != nil {
|
||||
if installer.IsValidationError(err) {
|
||||
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
||||
@@ -74,24 +76,21 @@ func postCreateServer(c *gin.Context) {
|
||||
}
|
||||
|
||||
if err := i.Server().Install(false); err != nil {
|
||||
log.WithFields(log.Fields{"server": i.Uuid(), "error": err}).Error("failed to run install process for server")
|
||||
log.WithFields(log.Fields{"server": i.Server().ID(), "error": err}).Error("failed to run install process for server")
|
||||
return
|
||||
}
|
||||
|
||||
if i.Server().Config().StartOnCompletion {
|
||||
if i.StartOnCompletion {
|
||||
log.WithField("server_id", i.Server().ID()).Debug("starting server after successful installation")
|
||||
if err := i.Server().HandlePowerAction(server.PowerActionStart, 30); err != nil {
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
log.WithFields(log.Fields{"server_id": i.Server().ID(), "action": "start"}).
|
||||
Warn("could not acquire a lock while attempting to perform a power action")
|
||||
log.WithFields(log.Fields{"server_id": i.Server().ID(), "action": "start"}).Warn("could not acquire a lock while attempting to perform a power action")
|
||||
} else {
|
||||
log.WithFields(log.Fields{"server_id": i.Server().ID(), "action": "start", "error": err}).
|
||||
Error("encountered error processing a server power action in the background")
|
||||
log.WithFields(log.Fields{"server_id": i.Server().ID(), "action": "start", "error": err}).Error("encountered error processing a server power action in the background")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.WithField("server_id", i.Server().ID()).
|
||||
Debug("skipping automatic start after successful server installation")
|
||||
log.WithField("server_id", i.Server().ID()).Debug("skipping automatic start after successful server installation")
|
||||
}
|
||||
}(install)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -47,10 +46,10 @@ type downloadProgress struct {
|
||||
|
||||
// Data passed over to initiate a server transfer.
|
||||
type serverTransferRequest struct {
|
||||
ServerID string `binding:"required" json:"server_id"`
|
||||
URL string `binding:"required" json:"url"`
|
||||
Token string `binding:"required" json:"token"`
|
||||
Server json.RawMessage `json:"server"`
|
||||
ServerID string `binding:"required" json:"server_id"`
|
||||
URL string `binding:"required" json:"url"`
|
||||
Token string `binding:"required" json:"token"`
|
||||
Server installer.ServerDetails `json:"server"`
|
||||
}
|
||||
|
||||
func getArchivePath(sID string) string {
|
||||
|
||||
Reference in New Issue
Block a user