v1.8.0
This commit is contained in:
40
pkg/cloudbroker/node/consumption.go
Normal file
40
pkg/cloudbroker/node/consumption.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user