v9.0.0
This commit is contained in:
86
pkg/cloudbroker/node/enable.go
Normal file
86
pkg/cloudbroker/node/enable.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// EnableRequest struct to enable node from maintenance status to enabled
|
||||
type EnableRequest struct {
|
||||
// Node ID
|
||||
// Required: true
|
||||
NID uint64 `url:"nid" json:"nid" validate:"required"`
|
||||
|
||||
// Message
|
||||
// Required: false
|
||||
Message string `url:"message,omitempty" json:"message,omitempty"`
|
||||
|
||||
// Do not check locks, iscsi-sessions or disk-present
|
||||
// Default: true
|
||||
// Required: false
|
||||
Force interface{} `url:"force" json:"force" validate:"isBool" `
|
||||
|
||||
// Reason
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
type wrapperEnableRequest struct {
|
||||
EnableRequest
|
||||
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// Enable enables node from maintenance status to enabled
|
||||
func (n Node) Enable(ctx context.Context, req EnableRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
if req.Force == nil {
|
||||
req.Force = true
|
||||
}
|
||||
|
||||
reqWrapped := wrapperEnableRequest{
|
||||
EnableRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/node/enable"
|
||||
|
||||
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
|
||||
// EnableAsync enables node from maintenance status to enabled with AsyncMode
|
||||
func (n Node) EnableAsync(ctx context.Context, req EnableRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
if req.Force == nil {
|
||||
req.Force = true
|
||||
}
|
||||
|
||||
reqWrapped := wrapperEnableRequest{
|
||||
EnableRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/node/enable"
|
||||
|
||||
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
Reference in New Issue
Block a user