You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
899 B
41 lines
899 B
package node
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// ConsumptionRequest struct to get node summary by resources and consumption
|
|
type ConsumptionRequest struct {
|
|
// Node ID
|
|
// Required: true
|
|
NID uint64 `url:"nid" json:"nid" validate:"required"`
|
|
}
|
|
|
|
// Consumption gets node summary by resources and consumption
|
|
func (n Node) Consumption(ctx context.Context, req ConsumptionRequest) (*ConsumptionInfo, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudbroker/node/consumption"
|
|
|
|
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info := ConsumptionInfo{}
|
|
|
|
err = json.Unmarshal(res, &info)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &info, nil
|
|
}
|