v1.10.2
This commit is contained in:
53
pkg/cloudbroker/resmon/get_by_compute.go
Normal file
53
pkg/cloudbroker/resmon/get_by_compute.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package resmon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetByComputeRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Start of time period - unixtime
|
||||
// Required: false
|
||||
StartTime uint64 `url:"starttime,omitempty" json:"starttime,omitempty"`
|
||||
|
||||
// End of time period - unixtime
|
||||
// Required: true
|
||||
EndTime uint64 `url:"endtime,omitempty" json:"endtime,omitempty"`
|
||||
}
|
||||
|
||||
// Get resource monitoring for the specified time period for the concrete compute instance
|
||||
func (r Resmon) GetByCompute(ctx context.Context, req GetByComputeRequest) (*GetByComputeData, error) {
|
||||
res, err := r.GetByComputeRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GetByComputeData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (r Resmon) GetByComputeRaw(ctx context.Context, req GetByComputeRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/resmon/getByCompute"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
49
pkg/cloudbroker/resmon/get_by_computes.go
Normal file
49
pkg/cloudbroker/resmon/get_by_computes.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package resmon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetByComputesRequest struct {
|
||||
// Start of time period - unixtime
|
||||
// Required: false
|
||||
StartTime uint64 `url:"starttime,omitempty" json:"starttime,omitempty"`
|
||||
|
||||
// End of time period - unixtime
|
||||
// Required: true
|
||||
EndTime uint64 `url:"endtime,omitempty" json:"endtime,omitempty"`
|
||||
}
|
||||
|
||||
// Get compute instances resource monitoring for the specified time period
|
||||
func (r Resmon) GetByComputes(ctx context.Context, req GetByComputesRequest) (*GetByComputeData, error) {
|
||||
res, err := r.GetByComputesRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GetByComputeData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (r Resmon) GetByComputesRaw(ctx context.Context, req GetByComputesRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/resmon/getByComputes"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
49
pkg/cloudbroker/resmon/get_by_grid.go
Normal file
49
pkg/cloudbroker/resmon/get_by_grid.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package resmon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetByGRIDRequest struct {
|
||||
// Start of time period - unixtime
|
||||
// Required: false
|
||||
StartTime uint64 `url:"starttime,omitempty" json:"starttime,omitempty"`
|
||||
|
||||
// End of time period - unixtime
|
||||
// Required: true
|
||||
EndTime uint64 `url:"endtime,omitempty" json:"endtime,omitempty"`
|
||||
}
|
||||
|
||||
// Get a grid resource monitoring for the specified time period
|
||||
func (r Resmon) GetByGRID(ctx context.Context, req GetByGRIDRequest) (*GetByGRIDData, error) {
|
||||
res, err := r.GetByGRIDRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GetByGRIDData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (r Resmon) GetByGRIDRaw(ctx context.Context, req GetByGRIDRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/resmon/getByGrid"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
53
pkg/cloudbroker/resmon/get_by_stack.go
Normal file
53
pkg/cloudbroker/resmon/get_by_stack.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package resmon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetByStackRequest struct {
|
||||
// Stack ID
|
||||
// Required: true
|
||||
StackID uint64 `url:"stackId" json:"stackId" validate:"required"`
|
||||
|
||||
// Start of time period - unixtime
|
||||
// Required: false
|
||||
StartTime uint64 `url:"starttime,omitempty" json:"starttime,omitempty"`
|
||||
|
||||
// End of time period - unixtime
|
||||
// Required: true
|
||||
EndTime uint64 `url:"endtime,omitempty" json:"endtime,omitempty"`
|
||||
}
|
||||
|
||||
// Get a grid resource monitoring for the specified time period
|
||||
func (r Resmon) GetByStack(ctx context.Context, req GetByStackRequest) (*GetByStackData, error) {
|
||||
res, err := r.GetByStackRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GetByStackData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (r Resmon) GetByStackRaw(ctx context.Context, req GetByStackRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/resmon/getByStack"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
49
pkg/cloudbroker/resmon/get_by_stacks.go
Normal file
49
pkg/cloudbroker/resmon/get_by_stacks.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package resmon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetByStacksRequest struct {
|
||||
// Start of time period - unixtime
|
||||
// Required: false
|
||||
StartTime uint64 `url:"starttime,omitempty" json:"starttime,omitempty"`
|
||||
|
||||
// End of time period - unixtime
|
||||
// Required: true
|
||||
EndTime uint64 `url:"endtime,omitempty" json:"endtime,omitempty"`
|
||||
}
|
||||
|
||||
// Get a grid resource monitoring for the specified time period
|
||||
func (r Resmon) GetByStacks(ctx context.Context, req GetByStacksRequest) (*GetByStackData, error) {
|
||||
res, err := r.GetByStacksRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GetByStackData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (r Resmon) GetByStacksRaw(ctx context.Context, req GetByStacksRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/resmon/getByStacks"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
89
pkg/cloudbroker/resmon/models.go
Normal file
89
pkg/cloudbroker/resmon/models.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package resmon
|
||||
|
||||
// GetByComputeData represents an array of data points
|
||||
type GetByComputeData []GetByComputePoint
|
||||
|
||||
type GetByComputePoint struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
Usage ComputeUsage `json:"usage"`
|
||||
Disks []ItemDisk `json:"disks"`
|
||||
UID string `json:"uid"`
|
||||
StackID uint64 `json:"stackId"`
|
||||
}
|
||||
|
||||
type ComputeUsage struct {
|
||||
VCPUsConsumed uint64 `json:"vcpusConsumed"`
|
||||
Storage uint64 `json:"storage"`
|
||||
CPUTime uint64 `json:"cpuTime"`
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
RAMConsumed uint64 `json:"ramConsumed"`
|
||||
VCPUsReserved uint64 `json:"vcpusReserved"`
|
||||
IsUp uint64 `json:"isUp"`
|
||||
RAMConsumedReal uint64 `json:"ramConsumedReal"`
|
||||
RAMReserved uint64 `json:"ramReserved"`
|
||||
}
|
||||
|
||||
type ItemDisk struct {
|
||||
Pool string `json:"pool"`
|
||||
ResID string `json:"resId"`
|
||||
SizeUsed uint64 `json:"sizeUsed"`
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
}
|
||||
|
||||
// GetByGRIDData represents an array of data points
|
||||
type GetByGRIDData []GetByGRIDPoint
|
||||
|
||||
type GetByGRIDPoint struct {
|
||||
UID string `json:"uid"`
|
||||
Total ItemTotalByGRID `json:"total"`
|
||||
Storages map[string]ItemStorage `json:"storages"`
|
||||
}
|
||||
|
||||
type ItemTotalByGRID struct {
|
||||
StacksCPU uint64 `json:"stacksCPU"`
|
||||
StorageCapacity uint64 `json:"storageCapacity"`
|
||||
CPUPower uint64 `json:"cpuPower"`
|
||||
CPUUtil uint64 `json:"cpuUtil"`
|
||||
TotalMem uint64 `json:"totalMem"`
|
||||
ReservedMem uint64 `json:"reservedMem"`
|
||||
UsedMem uint64 `json:"usedMem"`
|
||||
FreeMem uint64 `json:"freeMem"`
|
||||
VCPUConsumed uint64 `json:"vcpuConsumed"`
|
||||
}
|
||||
|
||||
type ItemStorage struct {
|
||||
CapacityLimit uint64 `json:"capacityLimit"`
|
||||
Consumed uint64 `json:"consumed"`
|
||||
Type string `json:"type"`
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// GetByStackData represents an array of data points
|
||||
type GetByStackData []GetByStackPoint
|
||||
|
||||
type GetByStackPoint struct {
|
||||
Usage StackUsage `json:"usage"`
|
||||
CPUInfo CPUinfoByStack `json:"cpuInfo"`
|
||||
Name string `json:"name"`
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
type StackUsage struct {
|
||||
CPUPower uint64 `json:"cpuPower"`
|
||||
UsedVCPUs uint64 `json:"usedVcpus"`
|
||||
PCPU uint64 `json:"pcpu"`
|
||||
UsedMem uint64 `json:"usedMem"`
|
||||
CPUUtil uint64 `json:"cpuUtil"`
|
||||
ReservedMem uint64 `json:"reservedMem"`
|
||||
FreeMem uint64 `json:"freeMem"`
|
||||
}
|
||||
|
||||
type CPUinfoByStack struct {
|
||||
ClockSpeed uint64 `json:"clockSpeed"`
|
||||
CoreCount uint64 `json:"coreCount"`
|
||||
PhysCount uint64 `json:"physCount"`
|
||||
}
|
||||
15
pkg/cloudbroker/resmon/resmon.go
Normal file
15
pkg/cloudbroker/resmon/resmon.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package resmon
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to resource monitoring
|
||||
type Resmon struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for resource monitoring endpoints
|
||||
func New(client interfaces.Caller) *Resmon {
|
||||
return &Resmon{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user