v9.0.0
This commit is contained in:
49
pkg/cloudapi/rg/access_grant.go
Normal file
49
pkg/cloudapi/rg/access_grant.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AccessGrantRequest struct to grant access to resource group
|
||||
type AccessGrantRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// User or group name to grant access
|
||||
// Required: true
|
||||
User string `url:"user" json:"user" validate:"required"`
|
||||
|
||||
// Access rights to set, one of:
|
||||
// - "R"
|
||||
// - "RCX"
|
||||
// - "ARCXDU"
|
||||
// Required: true
|
||||
Right string `url:"right" json:"right" validate:"accessType"`
|
||||
}
|
||||
|
||||
// AccessGrant grants user or group access to the resource group as specified
|
||||
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/accessGrant"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
42
pkg/cloudapi/rg/access_revoke.go
Normal file
42
pkg/cloudapi/rg/access_revoke.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AccessRevokeRequest struct to revoke access
|
||||
type AccessRevokeRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// User or group name to revoke access
|
||||
// Required: true
|
||||
User string `url:"user" json:"user" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessRevoke revokes specified user or group access from the resource group
|
||||
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/accessRevoke"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
44
pkg/cloudapi/rg/affinity_group_computes.go
Normal file
44
pkg/cloudapi/rg/affinity_group_computes.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AffinityGroupComputesRequest struct to get list of all computes with their relationships
|
||||
type AffinityGroupComputesRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Affinity group label
|
||||
// Required: true
|
||||
AffinityGroup string `url:"affinityGroup" json:"affinityGroup" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityGroupComputes gets list of all computes with their relationships to another computes
|
||||
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroupsComputes, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupComputes"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListAffinityGroupsComputes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
44
pkg/cloudapi/rg/affinity_groups_get.go
Normal file
44
pkg/cloudapi/rg/affinity_groups_get.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AffinityGroupsGetRequest struct to get list computes from affinity group
|
||||
type AffinityGroupsGetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Label affinity group
|
||||
// Required: true
|
||||
AffinityGroup string `url:"affinityGroup" json:"affinityGroup" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityGroupsGet gets list computes in the specified affinity group
|
||||
func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupsGet"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := []uint64{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
48
pkg/cloudapi/rg/affinity_groups_list.go
Normal file
48
pkg/cloudapi/rg/affinity_groups_list.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AffinityGroupsListRequest struct to get list of affinity groups from resource group
|
||||
type AffinityGroupsListRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
|
||||
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (*ListAffinityGroups, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupsList"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := &ListAffinityGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
40
pkg/cloudapi/rg/audits.go
Normal file
40
pkg/cloudapi/rg/audits.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AuditsRequest struct to get audit
|
||||
type AuditsRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Audits gets audit records for the specified resource group object
|
||||
func (r RG) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/audits"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListAudits{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
100
pkg/cloudapi/rg/create.go
Normal file
100
pkg/cloudapi/rg/create.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create resource group
|
||||
type CreateRequest struct {
|
||||
// Account, which will own this resource group
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Grid ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Name of this resource group. Must be unique within the account
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required,min=2"`
|
||||
|
||||
// Max size of memory in MB
|
||||
// Required: false
|
||||
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
||||
|
||||
// Max size of aggregated virtual disks in GB
|
||||
// Required: false
|
||||
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
||||
|
||||
// Max number of CPU cores
|
||||
// Required: false
|
||||
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
||||
|
||||
// Max sent/received network transfer peering
|
||||
// Required: false
|
||||
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
||||
|
||||
// Max number of assigned public IPs
|
||||
// Required: false
|
||||
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
||||
|
||||
// Username - owner of this resource group.
|
||||
// Leave blank to set current user as owner
|
||||
// Required: false
|
||||
Owner string `url:"owner,omitempty" json:"owner,omitempty"`
|
||||
|
||||
// Type of the default network for this resource group.
|
||||
// virtual machines created in this resource group will be by default connected to this network.
|
||||
// Allowed values are:
|
||||
// - PRIVATE
|
||||
// - PUBLIC
|
||||
// - NONE
|
||||
// Required: false
|
||||
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty" validate:"omitempty,rgDefNet"`
|
||||
|
||||
// Private network IP CIDR if default network PRIVATE
|
||||
// Required: false
|
||||
IPCIDR string `url:"ipcidr,omitempty" json:"ipcidr,omitempty"`
|
||||
|
||||
// Text description of this resource group
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// External network ID
|
||||
// Required: false
|
||||
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||
|
||||
// External IP address
|
||||
// Required: false
|
||||
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
||||
|
||||
// Register computes in registration system
|
||||
// Required: false
|
||||
RegisterComputes bool `url:"registerComputes,omitempty" json:"registerComputes,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates resource group
|
||||
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/create"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
47
pkg/cloudapi/rg/delete.go
Normal file
47
pkg/cloudapi/rg/delete.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct to delete resource group
|
||||
type DeleteRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Set to True if you want force delete non-empty resource group
|
||||
// Required: false
|
||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||
|
||||
// Set to True if you want to destroy resource group and all linked resources, if any, immediately.
|
||||
// Otherwise, they will be placed into recycle bin and could be restored later within recycle bin's purge period
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
// Delete deletes resource group
|
||||
func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/delete"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
38
pkg/cloudapi/rg/disable.go
Normal file
38
pkg/cloudapi/rg/disable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DisableRequest struct to disable resource group
|
||||
type DisableRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables resource group
|
||||
func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/disable"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
38
pkg/cloudapi/rg/enable.go
Normal file
38
pkg/cloudapi/rg/enable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// EnableRequest struct to enable resource group
|
||||
type EnableRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables resource group
|
||||
func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/enable"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
80
pkg/cloudapi/rg/filter.go
Normal file
80
pkg/cloudapi/rg/filter.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package rg
|
||||
|
||||
// FilterByID returns ListResourceGroups with specified ID.
|
||||
func (lrg ListResourceGroups) FilterByID(id uint64) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.ID == id
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListResourceGroups with specified Name.
|
||||
func (lrg ListResourceGroups) FilterByName(name string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.Name == name
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy return ListResourceGroups created by specified user.
|
||||
func (lrg ListResourceGroups) FilterByCreatedBy(createdBy string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListResourceGroups with specified Status.
|
||||
func (lrg ListResourceGroups) FilterByStatus(status string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.Status == status
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLockStatus return ListResourceGroups with specified LockStatus.
|
||||
func (lrg ListResourceGroups) FilterByLockStatus(lockStatus string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.LockStatus == lockStatus
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDefNetType returns ListResourceGroups with specified DefNetType.
|
||||
func (lrg ListResourceGroups) FilterByDefNetType(defNetType string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.DefNetType == defNetType
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListResourceGroups based on a user-specified predicate.
|
||||
func (lrg ListResourceGroups) FilterFunc(predicate func(irg ItemResourceGroup) bool) ListResourceGroups {
|
||||
var result ListResourceGroups
|
||||
|
||||
for _, rgItem := range lrg.Data {
|
||||
if predicate(rgItem) {
|
||||
result.Data = append(result.Data, rgItem)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemResourceGroup.
|
||||
// If none was found, returns an empty struct.
|
||||
func (lrg ListResourceGroups) FindOne() ItemResourceGroup {
|
||||
if len(lrg.Data) == 0 {
|
||||
return ItemResourceGroup{}
|
||||
}
|
||||
|
||||
return lrg.Data[0]
|
||||
}
|
||||
236
pkg/cloudapi/rg/filter_test.go
Normal file
236
pkg/cloudapi/rg/filter_test.go
Normal file
@@ -0,0 +1,236 @@
|
||||
package rg
|
||||
|
||||
import "testing"
|
||||
|
||||
var rgs = ListResourceGroups{
|
||||
Data: []ItemResourceGroup{
|
||||
{
|
||||
AccountID: 1,
|
||||
AccountName: "std",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_1@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676645305,
|
||||
DefNetID: 1,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7971,
|
||||
ID: 7971,
|
||||
LockStatus: "UNLOCKED",
|
||||
Milestones: 363459,
|
||||
Name: "rg_1",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "CREATED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
{
|
||||
AccountID: 2,
|
||||
AccountName: "std_2",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_1@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676645461,
|
||||
DefNetID: 2,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7972,
|
||||
ID: 7972,
|
||||
LockStatus: "UNLOCKED",
|
||||
Milestones: 363468,
|
||||
Name: "rg_2",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "CREATED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
{
|
||||
AccountID: 3,
|
||||
AccountName: "std_3",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_2@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedBy: "sample_user_2@decs3o",
|
||||
CreatedTime: 1676645548,
|
||||
DefNetID: 3,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7973,
|
||||
ID: 7973,
|
||||
LockStatus: "kjLOCKED",
|
||||
Milestones: 363471,
|
||||
Name: "rg_3",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "DISABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{
|
||||
48500,
|
||||
},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := rgs.FilterByID(7972).FindOne()
|
||||
|
||||
if actual.ID != 7972 {
|
||||
t.Fatal("expected ID 2, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := rgs.FilterByName("rg_1").FindOne()
|
||||
|
||||
if actual.Name != "rg_1" {
|
||||
t.Fatal("expected Name 'rg_1', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByCreatedBy(t *testing.T) {
|
||||
actual := rgs.FilterByCreatedBy("sample_user_1@decs3o")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.CreatedBy != "sample_user_1@decs3o" {
|
||||
t.Fatal("expected CreatedBy 'sample_user_1@decs3o', found: ", item.CreatedBy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := rgs.FilterByStatus("CREATED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "CREATED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByLockStatus(t *testing.T) {
|
||||
actual := rgs.FilterByLockStatus("UNLOCKED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.LockStatus != "UNLOCKED" {
|
||||
t.Fatal("expected LockStatus 'UNLOCKED', found: ", item.LockStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDefNetType(t *testing.T) {
|
||||
actual := rgs.FilterByDefNetType("NONE")
|
||||
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.DefNetType != "NONE" {
|
||||
t.Fatal("expected DefNetType 'NONE', found: ", item.DefNetType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := rgs.FilterFunc(func(ir ItemResourceGroup) bool {
|
||||
return len(ir.Computes) > 0
|
||||
})
|
||||
|
||||
if len(actual.Data) < 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if len(item.Computes) < 1 {
|
||||
t.Fatal("expected VMs to contain at least 1 element, found empty")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := rgs.SortByCreatedTime(true)
|
||||
|
||||
if actual.Data[0].CreatedTime != 1676645548 || actual.Data[2].CreatedTime != 1676645305 {
|
||||
t.Fatal("expected descending order, found ascending")
|
||||
}
|
||||
}
|
||||
46
pkg/cloudapi/rg/get.go
Normal file
46
pkg/cloudapi/rg/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get detailed information about resource group
|
||||
type GetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets current configuration of the resource group as a RecordResourceGroup struct
|
||||
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordResourceGroup, error) {
|
||||
res, err := r.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordResourceGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets current configuration of the resource group as an array of bytes
|
||||
func (r RG) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/get"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
40
pkg/cloudapi/rg/get_resource_consumption.go
Normal file
40
pkg/cloudapi/rg/get_resource_consumption.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetResourceConsumptionRequest struct to get detailed information about resource consumption for ResGroup
|
||||
type GetResourceConsumptionRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetResourceConsumption gets resource consumption of the resource group
|
||||
func (r RG) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*ItemResourceConsumption, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/getResourceConsumption"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ItemResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
64
pkg/cloudapi/rg/ids.go
Normal file
64
pkg/cloudapi/rg/ids.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package rg
|
||||
|
||||
// IDs gets array of ResourceGroupIDs from ListResourceGroups struct
|
||||
func (lrg ListResourceGroups) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lrg.Data))
|
||||
for _, rg := range lrg.Data {
|
||||
res = append(res, rg.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of ComputeIDs from ListAffinityGroupsComputes struct
|
||||
func (lag ListAffinityGroupsComputes) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lag))
|
||||
for _, ag := range lag {
|
||||
res = append(res, ag.ComputeID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of ComputeIDs from ListComputes struct
|
||||
func (lc ListComputes) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lc.Data))
|
||||
for _, c := range lc.Data {
|
||||
res = append(res, c.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of LBIDs from ListLB struct
|
||||
func (llb ListLB) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(llb.Data))
|
||||
for _, lb := range llb.Data {
|
||||
res = append(res, lb.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of VINSIDs from ListVINS struct
|
||||
func (llb ListVINS) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(llb.Data))
|
||||
for _, lb := range llb.Data {
|
||||
res = append(res, lb.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of ResourceGroupIDs from ListResourceConsumption struct
|
||||
func (lrc ListResourceConsumption) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lrc.Data))
|
||||
for _, rc := range lrc.Data {
|
||||
res = append(res, rc.RGID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of ResourceGroupIDs from ListAffinityGroup struct
|
||||
func (lag ListAffinityGroup) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lag))
|
||||
for _, ag := range lag {
|
||||
res = append(res, ag.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
91
pkg/cloudapi/rg/list.go
Normal file
91
pkg/cloudapi/rg/list.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of resource groups
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by name account
|
||||
// Required: false
|
||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||
|
||||
// Find by created after time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
|
||||
|
||||
// Find by created before time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by status lock
|
||||
// Required: false
|
||||
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
|
||||
|
||||
// Included deleted resource groups
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all resource groups the user has access to as a ListResourceGroups struct
|
||||
func (r RG) List(ctx context.Context, req ListRequest) (*ListResourceGroups, error) {
|
||||
|
||||
res, err := r.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListResourceGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all resource groups the user has access to as an array of bytes
|
||||
func (r RG) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/list"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
85
pkg/cloudapi/rg/list_computes.go
Normal file
85
pkg/cloudapi/rg/list_computes.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListComputesRequest struct to get list of computes
|
||||
type ListComputesRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Find by compute id
|
||||
// Required: false
|
||||
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// ID an account
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by tech status
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by ip address
|
||||
// Required: false
|
||||
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
||||
|
||||
// Find by external network name
|
||||
// Required: false
|
||||
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
|
||||
|
||||
// Find by external network id
|
||||
// Required: false
|
||||
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListComputes gets list of all compute instances under specified resource group, accessible by the user
|
||||
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listComputes"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListComputes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
76
pkg/cloudapi/rg/list_deleted.go
Normal file
76
pkg/cloudapi/rg/list_deleted.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list deleted resource groups
|
||||
type ListDeletedRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by name account
|
||||
// Required: false
|
||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||
|
||||
// Find by created after time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
|
||||
|
||||
// Find by created before time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
|
||||
|
||||
// Find by status lock
|
||||
// Required: false
|
||||
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list all deleted resource groups the user has access to
|
||||
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListResourceGroups, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listDeleted"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListResourceGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
77
pkg/cloudapi/rg/list_lb.go
Normal file
77
pkg/cloudapi/rg/list_lb.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListLBRequest struct to get list of load balancers
|
||||
type ListLBRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by tech status
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by frontend Ip
|
||||
// Required: false
|
||||
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
|
||||
|
||||
// Find by backend Ip
|
||||
// Required: false
|
||||
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListLB gets list all load balancers in the specified resource group, accessible by the user
|
||||
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (*ListLB, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listLb"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListLB{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
41
pkg/cloudapi/rg/list_pfw.go
Normal file
41
pkg/cloudapi/rg/list_pfw.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListPFWRequest struct to get list of port forward rules
|
||||
type ListPFWRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// ListPFW gets list port forward rules for the specified resource group
|
||||
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (*ListPortForwards, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listPFW"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListPortForwards{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
26
pkg/cloudapi/rg/list_resource_consumption.go
Normal file
26
pkg/cloudapi/rg/list_resource_consumption.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ListResourceConsumption gets resource consumptions of the resource groups
|
||||
func (r RG) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
|
||||
url := "/cloudapi/rg/listResourceConsumption"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
69
pkg/cloudapi/rg/list_vins.go
Normal file
69
pkg/cloudapi/rg/list_vins.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListVINSRequest struct to get list of VINSes
|
||||
type ListVINSRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// ID an account
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by ip extnet address
|
||||
// Required: false
|
||||
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
||||
|
||||
// Find by vins id
|
||||
// Required: false
|
||||
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListVINS gets list all ViNSes under specified resource group, accessible by the user
|
||||
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listVins"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
854
pkg/cloudapi/rg/models.go
Normal file
854
pkg/cloudapi/rg/models.go
Normal file
@@ -0,0 +1,854 @@
|
||||
package rg
|
||||
|
||||
// Resources used
|
||||
type Resource struct {
|
||||
// Number of cores
|
||||
CPU int64 `json:"cpu"`
|
||||
|
||||
// Disk size
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Max disk size
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
|
||||
// Number of External IPs
|
||||
ExtIPs int64 `json:"extips"`
|
||||
|
||||
// External traffic
|
||||
ExtTraffic int64 `json:"exttraffic"`
|
||||
|
||||
// Number of grafic cores
|
||||
GPU int64 `json:"gpu"`
|
||||
|
||||
// Number of RAM
|
||||
RAM int64 `json:"ram"`
|
||||
|
||||
// SEPs
|
||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
||||
}
|
||||
|
||||
// Disk usage
|
||||
type DiskUsage struct {
|
||||
// Disk size
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
}
|
||||
|
||||
// Information about resources
|
||||
type Resources struct {
|
||||
// Current information about resources
|
||||
Current Resource `json:"Current"`
|
||||
|
||||
// Reserved information about resources
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
// Detailed information about resource consumption
|
||||
type ItemResourceConsumption struct {
|
||||
// Consumed information about resources
|
||||
Consumed Resource `json:"consumed"`
|
||||
|
||||
// Reserved information about resources
|
||||
Reserved Resource `json:"reserved"`
|
||||
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgid"`
|
||||
}
|
||||
|
||||
type ListResourceConsumption struct {
|
||||
Data []ItemResourceConsumption `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Detailed information about resource group
|
||||
type RecordResourceGroup struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Compute Features
|
||||
ComputeFeatures []string `json:"computeFeatures"`
|
||||
|
||||
// CPU allocation parameter
|
||||
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||
|
||||
// CPU allocation ratio
|
||||
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// DefNetID
|
||||
DefNetID int64 `json:"def_net_id"`
|
||||
|
||||
// DefNetType
|
||||
DefNetType string `json:"def_net_type"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Dirty
|
||||
Dirty bool `json:"dirty"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// RegisterComputes
|
||||
RegisterComputes bool `json:"registerComputes"`
|
||||
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
|
||||
// List of resource types
|
||||
ResTypes []string `json:"resourceTypes"`
|
||||
|
||||
// Secret
|
||||
Secret string `json:"secret"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// UniqPools
|
||||
UniqPools []string `json:"uniqPools"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// List of VINS IDs
|
||||
VINS []uint64 `json:"vins"`
|
||||
|
||||
// List of compute IDs
|
||||
Computes []uint64 `json:"vms"`
|
||||
}
|
||||
|
||||
// Main information about resource group
|
||||
type ItemResourceGroup struct {
|
||||
//
|
||||
AccountACL ItemACL `json:"accountAcl"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Compute Features
|
||||
ComputeFeatures []string `json:"computeFeatures"`
|
||||
|
||||
// CPU allocation parameter
|
||||
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||
|
||||
// CPU allocation ratio
|
||||
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// DefNetID
|
||||
DefNetID int64 `json:"def_net_id"`
|
||||
|
||||
// DefNetType
|
||||
DefNetType string `json:"def_net_type"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Dirty
|
||||
Dirty bool `json:"dirty"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// RegisterComputes
|
||||
RegisterComputes bool `json:"registerComputes"`
|
||||
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
|
||||
// List of resource types
|
||||
ResTypes []string `json:"resourceTypes"`
|
||||
|
||||
// Secret
|
||||
Secret string `json:"secret"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// UniqPools
|
||||
UniqPools []string `json:"uniqPools"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// List of VINS IDs
|
||||
VINS []uint64 `json:"vins"`
|
||||
|
||||
// List of compute IDs
|
||||
Computes []uint64 `json:"vms"`
|
||||
}
|
||||
|
||||
// List of resource groups
|
||||
type ListResourceGroups struct {
|
||||
Data []ItemResourceGroup `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about Access Control List
|
||||
type ItemACL struct {
|
||||
// Explicit
|
||||
Explicit bool `json:"explicit"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Right
|
||||
Right string `json:"right"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// User group ID
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
// List ACL
|
||||
type ListACL []ItemACL
|
||||
|
||||
// Resource limits
|
||||
type ResourceLimits struct {
|
||||
// CUC
|
||||
CUC float64 `json:"CU_C"`
|
||||
|
||||
// CUD
|
||||
CUD float64 `json:"CU_D"`
|
||||
|
||||
// CUDM
|
||||
CUDM float64 `json:"CU_DM"`
|
||||
|
||||
// CUI
|
||||
CUI float64 `json:"CU_I"`
|
||||
|
||||
// CUM
|
||||
CUM float64 `json:"CU_M"`
|
||||
|
||||
// CUNP
|
||||
CUNP float64 `json:"CU_NP"`
|
||||
|
||||
// GPU units
|
||||
GPUUnits float64 `json:"gpu_units"`
|
||||
}
|
||||
|
||||
// Main information about affinity group
|
||||
type ItemAffinityGroupComputes struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Other node
|
||||
OtherNode []uint64 `json:"otherNode"`
|
||||
|
||||
// Other node indirect
|
||||
OtherNodeIndirect []uint64 `json:"otherNodeIndirect"`
|
||||
|
||||
// Other node indirect soft
|
||||
OtherNodeIndirectSoft []uint64 `json:"otherNodeIndirectSoft"`
|
||||
|
||||
// Other node soft
|
||||
OtherNodeSoft []uint64 `json:"otherNodeSoft"`
|
||||
|
||||
// Same node
|
||||
SameNode []uint64 `json:"sameNode"`
|
||||
|
||||
// Same node soft
|
||||
SameNodeSoft []uint64 `json:"sameNodeSoft"`
|
||||
}
|
||||
|
||||
// List of affinity groups
|
||||
type ListAffinityGroupsComputes []ItemAffinityGroupComputes
|
||||
|
||||
// Main information about
|
||||
type ItemAffinityGroup struct {
|
||||
ID uint64 `json:"id"`
|
||||
NodeID uint64 `json:"node_id"`
|
||||
}
|
||||
|
||||
// List of affinity group
|
||||
type ListAffinityGroup []ItemAffinityGroup
|
||||
|
||||
// List of affinity groups
|
||||
type ListAffinityGroups struct {
|
||||
// Data
|
||||
Data []map[string]ListAffinityGroup `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about audit
|
||||
type ItemAudit struct {
|
||||
// Call
|
||||
Call string `json:"call"`
|
||||
|
||||
// Response time
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
|
||||
// Status code
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
|
||||
// User
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
// List of audits
|
||||
type ListAudits []ItemAudit
|
||||
|
||||
// Main information about affinity rules
|
||||
type ItemRule struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Key
|
||||
Key string `json:"key"`
|
||||
|
||||
// Mode
|
||||
Mode string `json:"mode"`
|
||||
|
||||
// Policy
|
||||
Policy string `json:"policy"`
|
||||
|
||||
// Topology
|
||||
Topology string `json:"topology"`
|
||||
|
||||
// Value
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// List of rules
|
||||
type ListRules []ItemRule
|
||||
|
||||
// Main information about compute
|
||||
type ItemCompute struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Affinity label
|
||||
AffinityLabel string `json:"affinityLabel"`
|
||||
|
||||
// List of affinity rules
|
||||
AffinityRules ListRules `json:"affinityRules"`
|
||||
|
||||
// Affinity weight
|
||||
AffinityWeight uint64 `json:"affinityWeight"`
|
||||
|
||||
// List of anti affinity rules
|
||||
AntiAffinityRules ListRules `json:"antiAffinityRules"`
|
||||
|
||||
// Number of CPU
|
||||
CPUs uint64 `json:"cpus"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Registered
|
||||
Registered bool `json:"registered"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Total disks size
|
||||
TotalDisksSize uint64 `json:"totalDisksSize"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User managed
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// Number of ViNS connected
|
||||
VINSConnected uint64 `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
// List of computes
|
||||
type ListComputes struct {
|
||||
//Data
|
||||
Data []ItemCompute `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about load balancer
|
||||
type RecordLoadBalancer struct {
|
||||
// HAMode
|
||||
HAMode bool `json:"HAmode"`
|
||||
|
||||
// Access Control List
|
||||
ACL interface{} `json:"acl"`
|
||||
|
||||
// BackendHAIP
|
||||
BackendHAIP string `json:"backendHAIP"`
|
||||
|
||||
// List of Backends
|
||||
Backends ListBackends `json:"backends"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// DPAPIUser
|
||||
DPAPIUser string `json:"dpApiUser"`
|
||||
|
||||
// External network ID
|
||||
ExtNetID uint64 `json:"extnetId"`
|
||||
|
||||
// FrontendHAIP
|
||||
FrontendHAIP string `json:"frontendHAIP"`
|
||||
|
||||
// List of frontends
|
||||
Frontends ListFrontends `json:"frontends"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Primary node
|
||||
PrimaryNode RecordNode `json:"primaryNode"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Secondary node
|
||||
SecondaryNode RecordNode `json:"secondaryNode"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"vinsId"`
|
||||
}
|
||||
|
||||
// Detailed information about load balancer
|
||||
type ItemLoadBalancer struct {
|
||||
// DPAPI password
|
||||
DPAPIPassword string `json:"dpApiPassword"`
|
||||
|
||||
// Main information about load balancer
|
||||
RecordLoadBalancer
|
||||
}
|
||||
|
||||
// Main information about backend
|
||||
type ItemBackend struct {
|
||||
// Algorithm
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Server settings
|
||||
ServerDefaultSettings RecordServerSettings `json:"serverDefaultSettings"`
|
||||
|
||||
// List of servers
|
||||
Servers ListServers `json:"servers"`
|
||||
}
|
||||
|
||||
// List of backends
|
||||
type ListBackends []ItemBackend
|
||||
|
||||
// List of load balancers
|
||||
type ListLB struct {
|
||||
// Data
|
||||
Data []ItemLoadBalancer `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Server settings
|
||||
type RecordServerSettings struct {
|
||||
// Inter
|
||||
Inter uint64 `json:"inter"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Down inter
|
||||
DownInter uint64 `json:"downinter"`
|
||||
|
||||
// Rise
|
||||
Rise uint64 `json:"rise"`
|
||||
|
||||
// Fall
|
||||
Fall uint64 `json:"fall"`
|
||||
|
||||
// Slow start
|
||||
SlowStart uint64 `json:"slowstart"`
|
||||
|
||||
// Max connections
|
||||
MaxConn uint64 `json:"maxconn"`
|
||||
|
||||
// Max queue
|
||||
MaxQueue uint64 `json:"maxqueue"`
|
||||
|
||||
// Weight
|
||||
Weight uint64 `json:"weight"`
|
||||
}
|
||||
|
||||
// Main information about server
|
||||
type ItemServer struct {
|
||||
// Address
|
||||
Address string `json:"address"`
|
||||
|
||||
// Check
|
||||
Check string `json:"check"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
|
||||
// Server settings
|
||||
ServerSettings RecordServerSettings `json:"serverSettings"`
|
||||
}
|
||||
|
||||
// List of servers
|
||||
type ListServers []ItemServer
|
||||
|
||||
// Main information about node
|
||||
type RecordNode struct {
|
||||
// Backend IP
|
||||
BackendIP string `json:"backendIp"`
|
||||
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Frontend IP
|
||||
FrontendIP string `json:"frontendIp"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// MGMT IP
|
||||
MGMTIP string `json:"mgmtIp"`
|
||||
|
||||
// Network ID
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
}
|
||||
|
||||
// Main information about frontend
|
||||
type ItemFrontend struct {
|
||||
// Backend
|
||||
Backend string `json:"backend"`
|
||||
|
||||
// List of bindings
|
||||
Bindings ListBindings `json:"bindings"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// List of frontends
|
||||
type ListFrontends []ItemFrontend
|
||||
|
||||
// Main information of binding
|
||||
type ItemBinding struct {
|
||||
// Address
|
||||
Address string `json:"address"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
}
|
||||
|
||||
// List of bindings
|
||||
type ListBindings []ItemBinding
|
||||
|
||||
// Main information about port forward
|
||||
type ItemPortForward struct {
|
||||
// Public port end
|
||||
PublicPortEnd uint64 `json:"Public Port End"`
|
||||
|
||||
// Public port start
|
||||
PublicPortStart uint64 `json:"Public Port Start"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"VM ID"`
|
||||
|
||||
// Virtual machine IP
|
||||
VMIP string `json:"VM IP"`
|
||||
|
||||
// Virtual machine name
|
||||
VMName string `json:"VM Name"`
|
||||
|
||||
// Virtual machine port
|
||||
VMPort uint64 `json:"VM Port"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"ViNS ID"`
|
||||
|
||||
// VINS name
|
||||
VINSName string `json:"ViNS Name"`
|
||||
}
|
||||
|
||||
// List of port forwards
|
||||
type ListPortForwards struct {
|
||||
//Data
|
||||
Data []ItemPortForward `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about VINS
|
||||
type ItemVINS struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Computes
|
||||
Computes uint64 `json:"computes"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// External IP
|
||||
ExternalIP string `json:"externalIP"`
|
||||
|
||||
// Extnet ID
|
||||
ExtnetId uint64 `json:"extnetId"`
|
||||
|
||||
// Free IPs
|
||||
FreeIPs int64 `json:"freeIPs"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network
|
||||
Network string `json:"network"`
|
||||
|
||||
// PriVNFDev ID
|
||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
// List of VINSes
|
||||
type ListVINS struct {
|
||||
// Data
|
||||
Data []ItemVINS `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about usage of resource
|
||||
type RecordResourceUsage struct {
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Disk size
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Max disk size
|
||||
DiskSizeMax uint64 `json:"disksizemax"`
|
||||
|
||||
// Number of external IPs
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
|
||||
// ExtraTraffic
|
||||
ExtraTraffic uint64 `json:"exttraffic"`
|
||||
|
||||
// Number of GPU
|
||||
GPU uint64 `json:"gpu"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// SEPs
|
||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
||||
}
|
||||
38
pkg/cloudapi/rg/remove_def_net.go
Normal file
38
pkg/cloudapi/rg/remove_def_net.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// RemoveDefNetRequest struct to remove default network
|
||||
type RemoveDefNetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// RemoveDefNet removes default network from resource group
|
||||
func (r RG) RemoveDefNet(ctx context.Context, req RemoveDefNetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/removeDefNet"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
38
pkg/cloudapi/rg/restore.go
Normal file
38
pkg/cloudapi/rg/restore.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// RestoreRequest struct to restore resource group
|
||||
type RestoreRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restores resource group from recycle bin
|
||||
func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/restore"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
18
pkg/cloudapi/rg/rg.go
Normal file
18
pkg/cloudapi/rg/rg.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// API Actors for managing resource groups. These actors are the final API for end users to manage resource groups
|
||||
package rg
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to resource group
|
||||
type RG struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for resource group endpoints
|
||||
func New(client interfaces.Caller) *RG {
|
||||
return &RG{
|
||||
client,
|
||||
}
|
||||
}
|
||||
43
pkg/cloudapi/rg/serialize.go
Normal file
43
pkg/cloudapi/rg/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lrg ListResourceGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lrg.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lrg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lrg)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (irg ItemResourceGroup) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(irg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(irg)
|
||||
}
|
||||
49
pkg/cloudapi/rg/set_def_net.go
Normal file
49
pkg/cloudapi/rg/set_def_net.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// SetDefNetRequest struct to set default network
|
||||
type SetDefNetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// Should be one of:
|
||||
// - "PUBLIC"
|
||||
// - "PRIVATE"
|
||||
// Required: true
|
||||
NetType string `url:"netType" json:"netType" validate:"rgNetType"`
|
||||
|
||||
// Network ID
|
||||
// Required: false
|
||||
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
|
||||
}
|
||||
|
||||
// SetDefNet sets default network for attach associated virtual machines
|
||||
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/setDefNet"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
60
pkg/cloudapi/rg/sorting.go
Normal file
60
pkg/cloudapi/rg/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package rg
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListResourceGroups by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByCreatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg.Data) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg.Data[i].CreatedTime > lrg.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lrg.Data[i].CreatedTime < lrg.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListResourceGroups by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByUpdatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg.Data) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg.Data[i].UpdatedTime > lrg.Data[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lrg.Data[i].UpdatedTime < lrg.Data[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListResourceGroups by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByDeletedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg.Data) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg.Data[i].DeletedTime > lrg.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return lrg.Data[i].DeletedTime < lrg.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
79
pkg/cloudapi/rg/update.go
Normal file
79
pkg/cloudapi/rg/update.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateRequest struct to update resource group
|
||||
type UpdateRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// New name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// New description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// Max size of memory in MB
|
||||
// Required: false
|
||||
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
||||
|
||||
// Max size of aggregated virtual disks in GB
|
||||
// Required: false
|
||||
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
||||
|
||||
// Max number of CPU cores
|
||||
// Required: false
|
||||
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
||||
|
||||
// Max sent/received network transfer peering
|
||||
// Required: false
|
||||
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
||||
|
||||
// Max number of assigned public IPs
|
||||
// Required: false
|
||||
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
||||
|
||||
// Register computes in registration system
|
||||
// Required: false
|
||||
RegisterComputes bool `url:"registerComputes,omitempty" json:"registerComputes,omitempty"`
|
||||
|
||||
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
|
||||
// Required: false
|
||||
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
|
||||
|
||||
// if True the field will be cleared
|
||||
// Default: false
|
||||
// Required: false
|
||||
ClearUniqPools bool `url:"clearUniqPools" json:"clearUniqPools"`
|
||||
}
|
||||
|
||||
// Update updates resource group
|
||||
func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/update"
|
||||
|
||||
res, err := r.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
|
||||
}
|
||||
40
pkg/cloudapi/rg/usage.go
Normal file
40
pkg/cloudapi/rg/usage.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UsageRequest struct to get report of resource usage
|
||||
type UsageRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Usage gets report resource usage on the resource group
|
||||
func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/usage"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordResourceUsage{}
|
||||
err = json.Unmarshal(res, &info)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user