Files
decort-golang-sdk/pkg/cloudbroker/grid/execute_maintenance_script.go

47 lines
1.1 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package grid
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// ExecuteMaintenanceScriptRequest struct to execute script
2022-12-22 17:56:47 +03:00
type ExecuteMaintenanceScriptRequest struct {
// Grid (platform) ID
// Required: true
2024-11-12 12:51:21 +03:00
GID uint64 `url:"gid" json:"gid" validate:"required"`
2022-12-22 17:56:47 +03:00
// Type of nodes you want to apply the action on
// Required: true
2023-03-24 17:09:30 +03:00
NodesType string `url:"nodestype" json:"nodestype" validate:"required"`
2022-12-22 17:56:47 +03:00
// The script you want to run
// Required: true
2023-03-24 17:09:30 +03:00
Script string `url:"script" json:"script" validate:"required"`
2022-12-22 17:56:47 +03:00
}
// ExecuteMaintenanceScript executes maintenance script
func (g Grid) ExecuteMaintenanceScript(ctx context.Context, req ExecuteMaintenanceScriptRequest) (bool, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/grid/executeMaintenanceScript"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}