This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -3,27 +3,42 @@ package rg
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for grant access to resource group
type AccessGrantRequest struct {
RGID uint64 `url:"rgId"`
User string `url:"user"`
Right string `url:"right"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// User or group name to grant access
// Required: true
User string `url:"user"`
// Access rights to set,
// Should be one of:
// - "R"
// - "RCX"
// - "ARCXDU"
// Required: true
Right string `url:"right"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq AccessGrantRequest) Validate() error {
func (rgrq AccessGrantRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if rgrq.User == "" {
return errors.New("validation-error: field User must be set")
}
validate := validators.StringInSlice(rgrq.Right, []string{"R", "RCX", "ARCXDU"})
if !validate {
return errors.New("field Right can only be one of 'R', 'RCX' or 'ARCXDU'")
@@ -32,8 +47,9 @@ func (rgrq AccessGrantRequest) Validate() error {
return nil
}
// AccessGrant grants user or group access to the resource group as specified
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,17 +7,25 @@ import (
"strconv"
)
// Request struct for revoke access
type AccessRevokeRequest struct {
RGID uint64 `url:"rgId"`
User string `url:"user"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// User or group name to revoke access
// Required: true
User string `url:"user"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq AccessRevokeRequest) Validate() error {
func (rgrq AccessRevokeRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if rgrq.User == "" {
return errors.New("validation-error: field User must be set")
}
@@ -25,8 +33,10 @@ func (rgrq AccessRevokeRequest) Validate() error {
return nil
}
// AccessRevoke revokes specified user or group access from the resource group
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
if err := req.Validate(); err != nil {
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,16 +7,21 @@ import (
"net/http"
)
// Request struct for get list of all computes with their relationships
type AffinityGroupComputesRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Affinity group label
// Required: true
AffinityGroup string `url:"affinityGroup"`
}
func (rgrq AffinityGroupComputesRequest) Validate() error {
func (rgrq AffinityGroupComputesRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if rgrq.AffinityGroup == "" {
return errors.New("validation-error: field AffinityGroup must be set")
}
@@ -24,23 +29,25 @@ func (rgrq AffinityGroupComputesRequest) Validate() error {
return nil
}
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (AffinityGroupComputeList, error) {
if err := req.Validate(); err != nil {
// AffinityGroupComputes gets list of all computes with their relationships to another computes
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroupCompute, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/affinityGroupComputes"
agcListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
agcList := AffinityGroupComputeList{}
list := ListAffinityGroupCompute{}
if err := json.Unmarshal(agcListRaw, &agcList); err != nil {
if err := json.Unmarshal(res, &list); err != nil {
return nil, err
}
return agcList, nil
return list, nil
}

View File

@@ -7,16 +7,21 @@ import (
"net/http"
)
// Request struct for get list computes from affinity group
type AffinityGroupsGetRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Label affinity group
// Required: true
AffinityGroup string `url:"affinityGroup"`
}
func (rgrq AffinityGroupsGetRequest) Validate() error {
func (rgrq AffinityGroupsGetRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if rgrq.AffinityGroup == "" {
return errors.New("validation-error: field AffinityGroup must be set")
}
@@ -24,24 +29,26 @@ func (rgrq AffinityGroupsGetRequest) Validate() error {
return nil
}
// AffinityGroupsGet gets list computes in the specified affinity group
func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) {
if err := req.Validate(); err != nil {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/affinityGroupsGet"
agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
agList := make([]uint64, 0)
list := make([]uint64, 0)
err = json.Unmarshal(agListRaw, &agList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return agList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list of affinity groups from resource group
type AffinityGroupsListRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
}
func (rgrq AffinityGroupsListRequest) Validate() error {
func (rgrq AffinityGroupsListRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -19,24 +22,26 @@ func (rgrq AffinityGroupsListRequest) Validate() error {
return nil
}
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) {
if err := req.Validate(); err != nil {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/affinityGroupsList"
agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
agList := make(map[string][]uint64)
list := make(map[string][]uint64)
err = json.Unmarshal(agListRaw, &agList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return agList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get audit
type AuditsRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
}
func (rgrq AuditsRequest) Validate() error {
func (rgrq AuditsRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -19,23 +22,26 @@ func (rgrq AuditsRequest) Validate() error {
return nil
}
func (r RG) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) {
if err := req.Validate(); err != nil {
// Audits gets audit records for the specified resource group object
func (r RG) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/audits"
auditListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
auditList := AuditList{}
list := ListAudits{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return auditList, nil
return list, nil
}

View File

@@ -5,45 +5,123 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create resource group
type CreateRequest struct {
AccountID uint64 `url:"accountId"`
GID uint64 `url:"gid"`
Name string `url:"name"`
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Account, which will own this resource group
// Required: true
AccountID uint64 `url:"accountId"`
// Grid ID
// Required: true
GID uint64 `url:"gid"`
// Name of this resource group. Must be unique within the account
// Required: true
Name string `url:"name"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
// Max size of aggregated virtual disks in GB
// Required: false
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
// Max number of CPU cores
// Required: false
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Max sent/received network transfer peering
// Required: false
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNetworkPeerTransfer,omitempty"`
Owner string `url:"owner,omitempty"`
DefNet string `url:"def_net,omitempty"`
IPCIDR string `url:"ipcidr,omitempty"`
Desc string `url:"desc,omitempty"`
Reason string `url:"reason,omitempty"`
ExtNetID uint64 `url:"extNetId,omitempty"`
ExtIP string `url:"extIp,omitempty"`
RegisterComputes bool `url:"registerComputes,omitempty"`
// Max number of assigned public IPs
// Required: false
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
// Username - owner of this resource group.
// Leave blank to set current user as owner
// Required: false
Owner string `url:"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.
// Should be one of:
// - PRIVATE
// - PUBLIC
// - NONE
// Required: false
DefNet string `url:"def_net,omitempty"`
// Private network IP CIDR if default network PRIVATE
// Required: false
IPCIDR string `url:"ipcidr,omitempty"`
// Text description of this resource group
// Required: false
Description string `url:"desc,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
// External network ID
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty"`
// External IP address
// Required: false
ExtIP string `url:"extIp,omitempty"`
// Register computes in registration system
// Required: false
RegisterComputes bool `url:"registerComputes,omitempty"`
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2"]
// Required: false
UniqPools []string `url:"unuqPools,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice should be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (rgrq CreateRequest) Validate() error {
func (rgrq CreateRequest) validate() error {
if rgrq.AccountID == 0 {
return errors.New("field AccountID can not be empty or equal to 0")
}
if rgrq.GID == 0 {
return errors.New("field GID can not be empty or equal to 0")
}
if len(rgrq.Name) < 2 {
return errors.New("field Name can not be shorter than two bytes")
}
if len(rgrq.ResTypes) > 0 {
for _, value := range rgrq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}
// Create creates resource group
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,14 +7,27 @@ import (
"strconv"
)
// Request struct for delete resource group
type DeleteRequest struct {
RGID uint64 `url:"rgId"`
Force bool `url:"force,omitempty"`
Permanently bool `url:"permanently,omitempty"`
Reason string `url:"reason,omitempty"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Set to True if you want force delete non-empty resource group
// Required: false
Force bool `url:"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"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq DeleteRequest) Validate() error {
func (rgrq DeleteRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -22,8 +35,9 @@ func (rgrq DeleteRequest) Validate() error {
return nil
}
// Delete deletes resource group
func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -41,4 +55,4 @@ func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for disable resource group
type DisableRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq DisableRequest) Validate() error {
func (rgrq DisableRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq DisableRequest) Validate() error {
return nil
}
// Disable disables resource group by ID
func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -39,4 +46,4 @@ func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for enable resource group
type EnableRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq EnableRequest) Validate() error {
func (rgrq EnableRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq EnableRequest) Validate() error {
return nil
}
// Enable enables resource group by ID
func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -39,4 +46,4 @@ func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -7,12 +7,18 @@ import (
"net/http"
)
// Request struct for get detailed information about resource group
type GetRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq GetRequest) Validate() error {
func (rgrq GetRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq GetRequest) Validate() error {
return nil
}
func (r RG) Get(ctx context.Context, req GetRequest) (*ResourceGroup, error) {
err := req.Validate()
// Get gets current configuration of the resource group
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordRG, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -33,12 +40,12 @@ func (r RG) Get(ctx context.Context, req GetRequest) (*ResourceGroup, error) {
return nil, err
}
getResult := ResourceGroup{}
info := RecordRG{}
err = json.Unmarshal(res, &getResult)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &getResult, nil
return &info, nil
}

View File

@@ -6,13 +6,23 @@ import (
"net/http"
)
// Request struct for get list of resource groups
type ListRequest struct {
IncludeDeleted bool `url:"includedeleted,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// Included deleted resource groups
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (r RG) List(ctx context.Context, req ListRequest) (List, error) {
// List gets list of all resource groups the user has access to
func (r RG) List(ctx context.Context, req ListRequest) (ListRG, error) {
url := "/cloudbroker/rg/list"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -20,7 +30,7 @@ func (r RG) List(ctx context.Context, req ListRequest) (List, error) {
return nil, err
}
list := List{}
list := ListRG{}
err = json.Unmarshal(res, &list)
if err != nil {

View File

@@ -7,12 +7,18 @@ import (
"net/http"
)
// Request struct for get list of computes
type ListComputesRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq ListComputesRequest) Validate() error {
func (rgrq ListComputesRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq ListComputesRequest) Validate() error {
return nil
}
// 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 := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}
@@ -33,12 +40,12 @@ func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComp
return nil, err
}
listComputes := ListComputes{}
list := ListComputes{}
err = json.Unmarshal(res, &listComputes)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return listComputes, nil
return list, nil
}

View File

@@ -6,12 +6,19 @@ import (
"net/http"
)
// Request struct for get list deleted resource groups
type ListDeletedRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeleted, error) {
// ListDeleted gets list all deleted resource groups the user has access to
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListRG, error) {
url := "/cloudbroker/rg/listDeleted"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -19,12 +26,12 @@ func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDelete
return nil, err
}
listDeleted := ListDeleted{}
list := ListRG{}
err = json.Unmarshal(res, &listDeleted)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return listDeleted, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list load balancers
type ListLBRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
}
func (rgrq ListLBRequest) Validate() error {
func (rgrq ListLBRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -19,25 +22,26 @@ func (rgrq ListLBRequest) Validate() error {
return nil
}
// 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 := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/listLb"
lbListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
lbList := ListLB{}
list := ListLB{}
err = json.Unmarshal(lbListRaw, &lbList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return lbList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list port forward rules
type ListPFWRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
}
func (rgrq ListPFWRequest) Validate() error {
func (rgrq ListPFWRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -19,25 +22,26 @@ func (rgrq ListPFWRequest) Validate() error {
return nil
}
// ListPFW gets list port forward rules for the specified resource group
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPFW, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/listPFW"
pfwListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
pfwList := ListPFW{}
list := ListPFW{}
err = json.Unmarshal(pfwListRaw, &pfwList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return pfwList, nil
return list, nil
}

View File

@@ -7,12 +7,18 @@ import (
"net/http"
)
// Request struct for get list VINSes
type ListVINSRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq ListVINSRequest) Validate() error {
func (rgrq ListVINSRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq ListVINSRequest) Validate() error {
return nil
}
// 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 := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}
@@ -33,12 +40,12 @@ func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error)
return nil, err
}
listVINS := ListVINS{}
list := ListVINS{}
err = json.Unmarshal(res, &listVINS)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return listVINS, nil
return list, nil
}

View File

@@ -6,14 +6,29 @@ import (
"net/http"
)
// Request struct for delete several resource groups
type MassDeleteRequest struct {
RGIDs []uint64 `url:"rgIds"`
Force bool `url:"force,omitempty"`
Permanently bool `url:"permanently,omitempty"`
Reason string `url:"reason,omitempty"`
// IDs of the resource groups
// Required: true
RGIDs []uint64 `url:"rgIds"`
// Set to true if you want force delete non-empty resource groups
// Required: false
Force bool `url:"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 bins purge period
// Required: false
Permanently bool `url:"permanently,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq MassDeleteRequest) Validate() error {
func (rgrq MassDeleteRequest) validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
@@ -21,8 +36,9 @@ func (rgrq MassDeleteRequest) Validate() error {
return nil
}
// MassDelete starts jobs to delete several resource groups
func (r RG) MassDelete(ctx context.Context, req MassDeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,12 +6,18 @@ import (
"net/http"
)
// Request struct for disable several resource groups
type MassDisableRequest struct {
RGIDs []uint64 `url:"rgIds"`
Reason string `url:"reason,omitempty"`
// IDs of the resource groups
// Required: true
RGIDs []uint64 `url:"rgIds"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq MassDisableRequest) Validate() error {
func (rgrq MassDisableRequest) validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
@@ -19,8 +25,9 @@ func (rgrq MassDisableRequest) Validate() error {
return nil
}
// MassDisable start jobs to disable several resource groups
func (r RG) MassDisable(ctx context.Context, req MassDisableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,12 +6,18 @@ import (
"net/http"
)
// Request struct for enable several resource groups
type MassEnableRequest struct {
RGIDs []uint64 `url:"rgIds"`
Reason string `url:"reason,omitempty"`
// IDs of the resource groups
// Required: true
RGIDs []uint64 `url:"rgIds"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq MassEnableRequest) Validate() error {
func (rgrq MassEnableRequest) validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
@@ -19,8 +25,9 @@ func (rgrq MassEnableRequest) Validate() error {
return nil
}
// MassEnable start jobs to enable several resource groups
func (r RG) MassEnable(ctx context.Context, req MassEnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -1,264 +1,622 @@
package rg
type Audit struct {
Call string `json:"call"`
// Main information about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
StatusCode uint64 `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type AuditList []Audit
type Current struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
// List Audits
type ListAudits []ItemAudit
// Reservation information of usage
type Reservation struct {
// Number of CPU
CPU uint64 `json:"cpu"`
// Disk size
DiskSize uint64 `json:"disksize"`
// External IPs
ExtIPs uint64 `json:"extips"`
// External traffic
ExtTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
}
type Reserved struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
ExtTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
// Number of GPU
GPU uint64 `json:"gpu"`
// Number of RAM
RAM uint64 `json:"ram"`
}
// Resources usage information
type Resources struct {
Current Current `json:"Current"`
Reserved Reserved `json:"Reserved"`
// Current information
Current Reservation `json:"Current"`
// Reserved information
Reserved Reservation `json:"Reserved"`
}
// Access Control List
type ACL struct {
Explicit bool `json:"explicit"`
GUID string `json:"guid"`
Right string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
// 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 []ACL
// Resource limits
type ResourceLimits struct {
CuC float64 `json:"CU_C"`
CuD float64 `json:"CU_D"`
CuI float64 `json:"CU_I"`
CuM float64 `json:"CU_M"`
CuNp float64 `json:"CU_NP"`
// CUC
CUC float64 `json:"CU_C"`
// CUD
CuD float64 `json:"CU_D"`
// 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"`
}
type ResourceGroup struct {
// Detailed information about resource group
type RecordRG struct {
// Resource information
Resources Resources `json:"Resources"`
InfoResponse
// Main information about resource group
ItemRG
}
type InfoResponse struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
ACL []ACL `json:"acl"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DefNetID int64 `json:"def_net_id"`
DefNetType string `json:"def_net_type"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Desc string `json:"desc"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
LockStatus string `json:"lockStatus"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
RegisterComputes bool `json:"registerComputes"`
ResourceLimits ResourceLimits `json:"resourceLimits"`
Secret string `json:"secret"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
VINS []interface{} `json:"vins"`
VMs []interface{} `json:"vms"`
}
// Main information about resource group
type ItemRG struct {
// Account ID
AccountID uint64 `json:"accountId"`
type List []InfoResponse
type ListDeleted []InfoResponse
type AffinityGroupCompute struct {
ComputeID uint64 `json:"computeId"`
OtherNode []uint64 `json:"otherNode"`
OtherNodeIndirect []uint64 `json:"otherNodeIndirect"`
OtherNodeIndirectSoft []uint64 `json:"otherNodeIndirectSoft"`
OtherNodeSoft []uint64 `json:"otherNodeSoft"`
SameNode []uint64 `json:"sameNode"`
SameNodeSoft []uint64 `json:"sameNodeSoft"`
}
type AffinityGroupComputeList []AffinityGroupCompute
type AffinityRules struct {
GUID string `json:"guid"`
Key string `json:"key"`
Mode string `json:"mode"`
Policy string `json:"policy"`
Topology string `json:"topology"`
Value string `json:"value"`
}
type Compute struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
AffinityLabel string `json:"affinityLabel"`
AffinityRules []AffinityRules `json:"affinityRules"`
AffinityWeight uint64 `json:"affinityWeight"`
AntiAffinityRules []interface{} `json:"antiAffinityRules"`
CPUs uint64 `json:"cpus"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
ID uint64 `json:"id"`
Name string `json:"name"`
RAM uint64 `json:"ram"`
Registered bool `json:"registered"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TotalDisksSize uint64 `json:"totalDisksSize"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
VINSConnected uint64 `json:"vinsConnected"`
}
type ListComputes []Compute
type VINS struct {
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
Computes uint64 `json:"computes"`
CreatedBy string `json:"createdBy"`
// List ACL
ACL ListACL `json:"acl"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
// DefNet ID
DefNetID int64 `json:"def_net_id"`
// DefNet type
DefNetType string `json:"def_net_type"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID uint64 `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
// Description
Description string `json:"desc"`
// 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"`
// Register computes
RegisterComputes bool `json:"registerComputes"`
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// Secret
Secret string `json:"secret"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// List VINS IDs
VINS []uint64 `json:"vins"`
// List virtual machine IDs
VMs []uint64 `json:"vms"`
// Resource types list
ResTypes []string `json:"resTypes"`
// Uniq pools
UniqPools []string `json:"uniqPools"`
}
// List resource groups
type ListRG []ItemRG
// Main information about affinity group
type ItemAffinityGroupCompute 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 ListAffinityGroupCompute []ItemAffinityGroupCompute
// Main information about affinity rule
type ItemAffinityRule 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 affinity rules
type ListAffinityRules []ItemAffinityRule
// 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 affinity rules
AffinityRules ListAffinityRules `json:"affinityRules"`
// Affinity weight
AffinityWeight uint64 `json:"affinityWeight"`
// Anti affinity rules
AntiAffinityRules []interface{} `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"`
// VINS connected
VINSConnected uint64 `json:"vinsConnected"`
}
// List computes
type ListComputes []ItemCompute
// 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"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Network
Network string `json:"network"`
// PriVNFDev ID
PriVNFDevID uint64 `json:"priVnfDevId"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
// 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"`
}
type ListVINS []VINS
// List VINSes
type ListVINS []ItemVINS
type PFW struct {
PublicPortEnd uint64 `json:"Public Port End"`
// Main information about port forward
type ItemPFW struct {
// Public port end
PublicPortEnd uint64 `json:"Public Port End"`
// Public port start
PublicPortStart uint64 `json:"Public Port Start"`
VMID uint64 `json:"VM ID"`
VMIP string `json:"VM IP"`
VMName string `json:"VM Name"`
VMPort uint64 `json:"VM Port"`
VINSID uint64 `json:"ViNS ID"`
VINSName string `json:"ViNS Name"`
// 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"`
}
type ListPFW []PFW
// List PFWs
type ListPFW []ItemPFW
// Server settings
type ServerSettings struct {
// Inter
Inter uint64 `json:"inter"`
// GUID
GUID string `json:"guid"`
// Down inter
DownInter uint64 `json:"downinter"`
Fall uint64 `json:"fall"`
GUID string `json:"guid"`
Inter uint64 `json:"inter"`
MaxConn uint64 `json:"maxconn"`
MaxQueue uint64 `json:"maxqueue"`
Rise uint64 `json:"rise"`
// Rise
Rise uint64 `json:"rise"`
// Fall
Fall uint64 `json:"fall"`
// Slow start
SlowStart uint64 `json:"slowstart"`
Weight uint64 `json:"weight"`
// Max connections
MaxConn uint64 `json:"maxconn"`
// Max queue
MaxQueue uint64 `json:"maxqueue"`
// Weight
Weight uint64 `json:"weight"`
}
type Server struct {
Address string `json:"address"`
Check string `json:"check"`
GUID string `json:"guid"`
Name string `json:"name"`
Port uint64 `json:"port"`
// 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 ServerSettings `json:"serverSettings"`
}
type Backends struct {
Algorithm string `json:"algorithm"`
GUID string `json:"guid"`
Name string `json:"name"`
// List of servers
type ListServers []ItemServer
// 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 ServerSettings `json:"serverDefaultSettings"`
Servers []Server `json:"servers"`
// List of servers
Servers ListServers `json:"servers"`
}
type Binding struct {
// List of backends
type ListBackends []ItemBackend
// Main information of binding
type ItemBinding struct {
// Address
Address string `json:"address"`
GUID string `json:"guid"`
Name string `json:"name"`
Port uint64 `json:"port"`
// GUID
GUID string `json:"guid"`
// Name
Name string `json:"name"`
// Port
Port uint64 `json:"port"`
}
type Frontend struct {
Backend string `json:"backend"`
Bindings []Binding `json:"bindings"`
GUID string `json:"guid"`
Name string `json:"name"`
// List of bindings
type ListBindings []ItemBinding
// 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"`
}
type PrimaryNode struct {
BackendIP string `json:"backendIp"`
ComputeID uint64 `json:"computeId"`
// List of frontends
type ListFrontends []ItemFrontend
// 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 string `json:"guid"`
MgmtIP string `json:"mgmtIp"`
NetworkID uint64 `json:"networkId"`
// GUID
GUID string `json:"guid"`
// MGMT IP
MGMTIP string `json:"mgmtIp"`
// Network ID
NetworkID uint64 `json:"networkId"`
}
type SecondaryNode struct {
BackendIP string `json:"backendIp"`
ComputeID uint64 `json:"computeId"`
FrontendIP string `json:"frontendIp"`
GUID string `json:"guid"`
MgmtIP string `json:"mgmtIp"`
NetworkID uint64 `json:"networkId"`
// Main information about load balancer
type ItemLB struct {
// HAMode
HAMode bool `json:"HAmode"`
// List ACL
ACL ListACL `json:"acl"`
// List 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"`
// DPAPI user
DPAPIUser string `json:"dpApiUser"`
// External network ID
ExtNetID uint64 `json:"extnetId"`
// 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"`
}
type LB struct {
HAMode bool `json:"HAmode"`
ACL []ACL `json:"acl"`
Backends []Backends `json:"backends"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Desc string `json:"desc"`
DpAPIUser string `json:"dpApiUser"`
ExtNetID uint64 `json:"extnetId"`
Frontends []Frontend `json:"frontends"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
ImageID uint64 `json:"imageId"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
PrimaryNode PrimaryNode `json:"primaryNode"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
SecondaryNode SecondaryNode `json:"secondaryNode"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
VINSID uint64 `json:"vinsId"`
}
type ListLB []LB
// List load balancers
type ListLB []ItemLB

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for restore resource group
type RestoreRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq RestoreRequest) Validate() error {
func (rgrq RestoreRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq RestoreRequest) Validate() error {
return nil
}
// Restore restores resource group from recycle bin
func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -39,4 +46,4 @@ func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
}
return result, nil
}
}

View File

@@ -1,11 +1,16 @@
// API Actors for managing resource groups. These actors are the final API for end users to manage resource groups
package rg
import "github.com/rudecs/decort-sdk/interfaces"
import (
"github.com/rudecs/decort-sdk/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: client,

View File

@@ -3,23 +3,38 @@ package rg
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for set default network
type SetDefNetRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Network type
// Should be one of:
// - "PUBLIC"
// - "PRIVATE"
// Required: true
NetType string `url:"netType"`
NetID uint64 `url:"netId,omitempty"`
Reason string `url:"reason,omitempty"`
// Network ID
// Required: false
NetID uint64 `url:"netId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq SetDefNetRequest) Validate() error {
func (rgrq SetDefNetRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
validate := validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"})
if !validate {
return errors.New("validation-error: field NetType must be one of PRIVATE or PUBLIC")
@@ -28,8 +43,9 @@ func (rgrq SetDefNetRequest) Validate() error {
return nil
}
// SetDefNet sets default network for attach associated virtual machines
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -5,31 +5,86 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update resource group
type UpdateRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name,omitempty"`
Desc string `url:"desc,omitempty"`
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// New name
// Required: false
Name string `url:"name,omitempty"`
// New description
// Required: false
Description string `url:"desc,omitempty"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
// Max size of aggregated virtual disks in GB
// Required: false
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
// Max number of CPU cores
// Required: false
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Max sent/received network transfer peering
// Required: false
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNetworkPeerTransfer,omitempty"`
RegisterComputes bool `url:"registerComputes,omitempty"`
Reason string `url:"reason"`
// Max number of assigned public IPs
// Required: false
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
// Register computes in registration system
// Required: false
RegisterComputes bool `url:"registerComputes,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice should be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (rgrq UpdateRequest) Validate() error {
func (rgrq UpdateRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if len(rgrq.ResTypes) > 0 {
for _, value := range rgrq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}
// Update updates resource group
func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,12 +7,18 @@ import (
"net/http"
)
// Request struct for get report of resource usage
type UsageRequest struct {
RGID uint64 `url:"rgId"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (rgrq UsageRequest) Validate() error {
func (rgrq UsageRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
@@ -20,8 +26,9 @@ func (rgrq UsageRequest) Validate() error {
return nil
}
func (r RG) Usage(ctx context.Context, req UsageRequest) (*Reserved, error) {
err := req.Validate()
// Usage gets report resource usage on the resource group
func (r RG) Usage(ctx context.Context, req UsageRequest) (*Reservation, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -33,12 +40,12 @@ func (r RG) Usage(ctx context.Context, req UsageRequest) (*Reserved, error) {
return nil, err
}
usage := Reserved{}
info := Reservation{}
err = json.Unmarshal(res, &usage)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &usage, nil
return &info, nil
}