Refactoring

This commit is contained in:
stSolo
2022-08-11 16:39:39 +03:00
parent 9563097dcb
commit 39a6f9a1ce
300 changed files with 64 additions and 58 deletions

View File

@@ -0,0 +1,48 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AccessGrantRequest struct {
RGID uint64 `url:"rgId"`
User string `url:"user"`
Right string `url:"right"`
Reason string `url:"reason,omitempty"`
}
func (rgrq AccessGrantRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.User == "" {
return errors.New("field User can not be empty")
}
if !validators.StringInSlice(rgrq.Right, []string{"R", "RCX", "ARCXDU"}) {
return errors.New("field Right can only be one of 'R', 'RCX' or 'ARCXDU'")
}
return nil
}
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/accessGrant"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,42 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AccessRevokeRequest struct {
RGID uint64 `url:"rgId"`
User string `url:"user"`
Reason string `url:"reason,omitempty"`
}
func (rgrq AccessRevokeRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.User == "" {
return errors.New("field User can not be empty")
}
return nil
}
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/accessRevoke"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,46 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityGroupComputesRequest struct {
RGID uint64 `url:"rgId"`
AffinityGroup string `url:"affinityGroup"`
}
func (rgrq AffinityGroupComputesRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.AffinityGroup == "" {
return errors.New("field AffinityGroup cat not be empty")
}
return nil
}
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest, options ...opts.DecortOpts) (AffinityGroupComputeList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/affinityGroupComputes"
agcListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
agcList := AffinityGroupComputeList{}
if err := json.Unmarshal(agcListRaw, &agcList); err != nil {
return nil, err
}
return agcList, nil
}

View File

@@ -0,0 +1,46 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityGroupsGetRequest struct {
RGID uint64 `url:"rgId"`
AffinityGroup string `url:"affinityGroup"`
}
func (rgrq AffinityGroupsGetRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.AffinityGroup == "" {
return errors.New("field AffinityGroup cat not be empty")
}
return nil
}
func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest, options ...opts.DecortOpts) ([]uint64, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/affinityGroupsGet"
agListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
agList := []uint64{}
if err := json.Unmarshal(agListRaw, &agList); err != nil {
return nil, err
}
return agList, nil
}

View File

@@ -0,0 +1,41 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityGroupsListRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq AffinityGroupsListRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest, options ...opts.DecortOpts) (map[string][]uint64, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/affinityGroupsList"
agListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
agList := map[string][]uint64{}
if err := json.Unmarshal(agListRaw, &agList); err != nil {
return nil, err
}
return agList, nil
}

41
pkg/cloudapi/rg/audits.go Normal file
View File

@@ -0,0 +1,41 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AuditsRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq AuditsRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AuditList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/audits"
auditListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
auditList := AuditList{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
return nil, err
}
return auditList, nil
}

59
pkg/cloudapi/rg/create.go Normal file
View File

@@ -0,0 +1,59 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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"`
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNumPublicIP,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"`
}
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")
}
return nil
}
func (r RG) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
if err := req.Validate(); err != nil {
return 0, err
}
url := "/cloudapi/rg/create"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
}

39
pkg/cloudapi/rg/delete.go Normal file
View File

@@ -0,0 +1,39 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
RGID uint64 `url:"rgId"`
Force bool `url:"force,omitempty"`
Permanently bool `url:"permanently,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (rgrq DeleteRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/delete"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,37 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisableRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq DisableRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/disable"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

37
pkg/cloudapi/rg/enable.go Normal file
View File

@@ -0,0 +1,37 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type EnableRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq EnableRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/enable"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

42
pkg/cloudapi/rg/get.go Normal file
View File

@@ -0,0 +1,42 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq GetRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ResourceGroup, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/get"
rgRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
rg := &ResourceGroup{}
if err := json.Unmarshal(rgRaw, rg); err != nil {
return nil, err
}
return rg, nil
}

30
pkg/cloudapi/rg/list.go Normal file
View File

@@ -0,0 +1,30 @@
package rg
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
IncludeDeleted bool `url:"includedeleted,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (r RG) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ResourceGroupList, error) {
url := "/cloudapi/rg/list"
rgListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
rgList := ResourceGroupList{}
if err := json.Unmarshal(rgListRaw, &rgList); err != nil {
return nil, err
}
return rgList, nil
}

View File

@@ -0,0 +1,42 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListComputesRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq ListComputesRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (ComputeList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/listComputes"
computeListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
computeList := ComputeList{}
if err := json.Unmarshal(computeListRaw, &computeList); err != nil {
return nil, err
}
return computeList, nil
}

View File

@@ -0,0 +1,29 @@
package rg
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListDeletedRequest struct {
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (ResourceGroupList, error) {
url := "/cloudapi/rg/listDeleted"
rgListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
rgList := ResourceGroupList{}
if err := json.Unmarshal(rgListRaw, &rgList); err != nil {
return nil, err
}
return rgList, nil
}

View File

@@ -0,0 +1,41 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListLBRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq ListLBRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) ListLB(ctx context.Context, req ListLBRequest, options ...opts.DecortOpts) (LBList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/listLb"
lbListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
lbList := LBList{}
if err := json.Unmarshal(lbListRaw, &lbList); err != nil {
return nil, err
}
return lbList, nil
}

View File

@@ -0,0 +1,41 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListPFWRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq ListPFWRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest, options ...opts.DecortOpts) (PortForwardList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/listPFW"
pfwListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
pfwList := PortForwardList{}
if err := json.Unmarshal(pfwListRaw, &pfwList); err != nil {
return nil, err
}
return pfwList, nil
}

View File

@@ -0,0 +1,42 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListVINSRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq ListVINSRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest, options ...opts.DecortOpts) (VINSList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/listVins"
vinsListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
vinsList := VINSList{}
if err := json.Unmarshal(vinsListRaw, &vinsList); err != nil {
return nil, err
}
return vinsList, nil
}

234
pkg/cloudapi/rg/models.go Normal file
View File

@@ -0,0 +1,234 @@
package rg
type ResourceGroup struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
ACL []ACL `json:"acl"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DefNetID uint64 `json:"def_net_id"`
DefNetType string `json:"def_net_type"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Desc string `json:"desc"`
Dirty bool `url:"dirty"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
LockStatus string `json:"lockStatus"`
Milestones int `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 []uint64 `json:"vins"`
Computes []uint64 `json:"vms"`
}
type ResourceGroupList []ResourceGroup
type ACL struct {
Explicit bool `json:"explicit"`
GUID string `json:"guid"`
Right string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UserGroupID string `json:"userGroupId"`
}
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"`
GPUUnits float64 `json:"gpu_units"`
}
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 Audit struct {
Call string `json:"call"`
ResponseTime float64 `json:"responsetime"`
StatusCode uint64 `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type AuditList []Audit
type Compute struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
AffinityLabel string `json:"affinityLabel"`
// TODO put actual type here
AffinityRules []any `json:"affinityRules"`
AffinityWeight uint64 `json:"affinityWeight"`
// TODO put actual type here
AntiAffinityRules []any `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 ComputeList []Compute
type LoadBalancer struct {
HAMode bool `json:"HAmode"`
ACL interface{} `json:"acl"`
Backends []Backend `json:"backends"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Description 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 Node `json:"primaryNode"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
SecondaryNode Node `json:"secondaryNode"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
VinsId uint64 `json:"vinsId"`
}
type LoadBalancerDetailed struct {
DPAPIPassword string `json:"dpApiPassword"`
LoadBalancer
}
type Backend struct {
Algorithm string `json:"algorithm"`
GUID string `json:"guid"`
Name string `json:"name"`
ServerDefaultSettings ServerSettings `json:"serverDefaultSettings"`
Servers []Server `json:"servers"`
}
type LBList []LoadBalancerDetailed
type ServerSettings struct {
Inter uint64 `json:"inter"`
GUID string `json:"guid"`
DownInter uint64 `json:"downinter"`
Rise uint `json:"rise"`
Fall uint `json:"fall"`
SlowStart uint64 `json:"slowstart"`
MaxConn uint `json:"maxconn"`
MaxQueue uint `json:"maxqueue"`
Weight uint `json:"weight"`
}
type Server struct {
Address string `json:"address"`
Check string `json:"check"`
GUID string `json:"guid"`
Name string `json:"name"`
Port uint `json:"port"`
ServerSettings ServerSettings `json:"serverSettings"`
}
type Node 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"`
}
type Frontend struct {
Backend string `json:"backend"`
Bindings []Binding `json:"bindings"`
GUID string `json:"guid"`
Name string `json:"name"`
}
type Binding struct {
Address string `json:"address"`
GUID string `json:"guid"`
Name string `json:"name"`
Port uint `json:"port"`
}
type PortForward struct {
PublicPortEnd uint16 `json:"Public Port End"`
PublicPortStart uint16 `json:"Public Port Start"`
VMID uint64 `json:"VM ID"`
VMIP string `json:"VM IP"`
VMName string `json:"VM Name"`
VMPort uint16 `json:"VM Port"`
VINSID uint64 `json:"ViNS ID"`
VINSName string `json:"ViNS Name"`
}
type PortForwardList []PortForward
type VINS struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
Computes uint64 `json:"computes"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID uint64 `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
PriVNFDevID uint64 `json:"priVnfDevId"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
}
type VINSList []VINS
type ResourceUsage struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
ExtraTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
}

View File

@@ -0,0 +1,37 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq RestoreRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/restore"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

15
pkg/cloudapi/rg/rg.go Normal file
View File

@@ -0,0 +1,15 @@
package rg
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type RG struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *RG {
return &RG{
client,
}
}

View File

@@ -0,0 +1,44 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SetDefNetRequest struct {
RGID uint64 `url:"rgId"`
NetType string `url:"netType"`
NetID uint64 `url:"netId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq SetDefNetRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if !validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"}) {
return errors.New("field NetType can only be one of 'PUBLIC' or 'PRIVATE'")
}
return nil
}
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest, options ...opts.DecortOpts) (uint64, error) {
if err := req.Validate(); err != nil {
return 0, err
}
url := "/cloudapi/rg/setDefNet"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
}

45
pkg/cloudapi/rg/update.go Normal file
View File

@@ -0,0 +1,45 @@
package rg
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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"`
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
RegisterComputes bool `url:"registerComputes,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (rgrq UpdateRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/rg/update"
res, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

42
pkg/cloudapi/rg/usage.go Normal file
View File

@@ -0,0 +1,42 @@
package rg
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UsageRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq UsageRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
func (r RG) Usage(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (*ResourceUsage, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/usage"
usageRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
usage := &ResourceUsage{}
if err := json.Unmarshal(usageRaw, usage); err != nil {
return nil, err
}
return usage, nil
}