Add new resources, extend fields in config

1.5.8-k8s-extnet-branch
stSolo 2 years ago
parent 5fd450382c
commit 8712561853

@ -1,6 +1,7 @@
package config package config
type Config struct { type Config struct {
Token string
AppID string AppID string
AppSecret string AppSecret string
SSOURL string SSOURL string

@ -17,6 +17,12 @@ func NewHttpClient(cfg config.Config) *http.Client {
}, },
} }
var expiredTime time.Time
if cfg.Token != "" {
expiredTime = time.Now().AddDate(0, 0, 1)
}
return &http.Client{ return &http.Client{
Transport: &transport{ Transport: &transport{
base: transCfg, base: transCfg,
@ -24,6 +30,8 @@ func NewHttpClient(cfg config.Config) *http.Client {
clientID: cfg.AppID, clientID: cfg.AppID,
clientSecret: cfg.AppSecret, clientSecret: cfg.AppSecret,
SSOURL: cfg.SSOURL, SSOURL: cfg.SSOURL,
token: cfg.Token,
expiryTime: expiredTime,
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}, },

@ -1,6 +1,6 @@
package cloudbroker package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc" import "github.com/rudecs/decort-sdk/pkg/cloudbroker/kvmppc"
func (cb *CloudBroker) KVMPPC() *kvmppc.KVMPPC { func (cb *CloudBroker) KVMPPC() *kvmppc.KVMPPC {
return kvmppc.New(cb.client) return kvmppc.New(cb.client)

@ -0,0 +1,70 @@
package kvmppc
import (
"context"
"errors"
"net/http"
"strconv"
)
type CreateRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name"`
CPU uint64 `url:"cpu"`
RAM uint64 `url:"ram"`
ImageID uint64 `url:"imageId"`
BootDisk uint64 `url:"bootDisk,omitempty"`
SepID uint64 `url:"sepId,omitempty"`
Pool string `url:"pool,omitempty"`
NetType string `url:"netType,omitempty"`
NetID uint64 `url:"netId,omitempty"`
IPAddr string `url:"ipAddr,omitempty"`
UserData string `url:"userdata,omitempty"`
Desc string `url:"desc,omitempty"`
Start bool `url:"start,omitempty"`
StackID uint64 `url:"stackId,omitempty"`
IS string `url:"IS,omitempty"`
IpaType string `url:"ipaType,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (krq CreateRequest) Validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
return nil
}
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/kvmppc/create"
res, err := k.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
}

@ -0,0 +1,70 @@
package kvmppc
import (
"context"
"errors"
"net/http"
"strconv"
)
type CreateBlankRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name"`
CPU uint64 `url:"cpu"`
RAM uint64 `url:"ram"`
BootDisk uint64 `url:"bootDisk"`
SepID uint64 `url:"sepId"`
Pool string `url:"pool"`
NetType string `url:"netType,omitempty"`
NetID uint64 `url:"netId,omitempty"`
IPAddr string `url:"ipAddr,omitempty"`
Desc string `url:"desc,omitempty"`
}
func (krq CreateBlankRequest) Validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.BootDisk == 0 {
return errors.New("validation-error: field BootDisk must be set")
}
if krq.SepID == 0 {
return errors.New("validation-error: field SepID must be set")
}
if krq.Pool == "" {
return errors.New("validation-error: field Pool must be set")
}
return nil
}
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/kvmppc/createBlank"
res, err := k.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
}

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

@ -0,0 +1,73 @@
package kvmppc
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type MassCreateRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name"`
Count uint64 `url:"count"`
CPU uint64 `url:"cpu"`
RAM uint64 `url:"ram"`
ImageID uint64 `url:"imageId"`
BootDisk uint64 `url:"bootDisk,omitempty"`
SepID uint64 `url:"sepId,omitempty"`
Pool string `url:"pool,omitempty"`
NetType string `url:"netType,omitempty"`
NetID uint64 `url:"netId,omitempty"`
IPAddr string `url:"ipAddr,omitempty"`
UserData string `url:"userdata,omitempty"`
Desc string `url:"desc,omitempty"`
Start bool `url:"start,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (krq MassCreateRequest) Validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.Count == 0 {
return errors.New("validation-error: field Count must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
return nil
}
func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/kvmppc/massCreate"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
computes := make([]uint64, 0)
err = json.Unmarshal(res, &computes)
if err != nil {
return nil, err
}
return computes, nil
}

@ -1,7 +1,7 @@
package cloudbroker package cloudbroker
import ( import (
"github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86" "github.com/rudecs/decort-sdk/pkg/cloudbroker/kvmx86"
) )
func (cb *CloudBroker) KVMX86() *kvmx86.KVMX86 { func (cb *CloudBroker) KVMX86() *kvmx86.KVMX86 {

@ -0,0 +1,70 @@
package kvmx86
import (
"context"
"errors"
"net/http"
"strconv"
)
type CreateRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name"`
CPU uint64 `url:"cpu"`
RAM uint64 `url:"ram"`
ImageID uint64 `url:"imageId"`
BootDisk uint64 `url:"bootDisk,omitempty"`
SepID uint64 `url:"sepId,omitempty"`
Pool string `url:"pool,omitempty"`
NetType string `url:"netType,omitempty"`
NetID uint64 `url:"netId,omitempty"`
IPAddr string `url:"ipAddr,omitempty"`
UserData string `url:"userdata,omitempty"`
Desc string `url:"desc,omitempty"`
Start bool `url:"start,omitempty"`
StackID uint64 `url:"stackId,omitempty"`
IS string `url:"IS,omitempty"`
IpaType string `url:"ipaType,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (krq CreateRequest) Validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
return nil
}
func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/kvmx86/create"
res, err := k.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
}

@ -0,0 +1,70 @@
package kvmx86
import (
"context"
"errors"
"net/http"
"strconv"
)
type CreateBlankRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name"`
CPU uint64 `url:"cpu"`
RAM uint64 `url:"ram"`
BootDisk uint64 `url:"bootDisk"`
SepID uint64 `url:"sepId"`
Pool string `url:"pool"`
NetType string `url:"netType,omitempty"`
NetID uint64 `url:"netId,omitempty"`
IPAddr string `url:"ipAddr,omitempty"`
Desc string `url:"desc,omitempty"`
}
func (krq CreateBlankRequest) Validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.BootDisk == 0 {
return errors.New("validation-error: field BootDisk must be set")
}
if krq.SepID == 0 {
return errors.New("validation-error: field SepID must be set")
}
if krq.Pool == "" {
return errors.New("validation-error: field Pool must be set")
}
return nil
}
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/kvmx86/createBlank"
res, err := k.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
}

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

@ -0,0 +1,73 @@
package kvmx86
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type MassCreateRequest struct {
RGID uint64 `url:"rgId"`
Name string `url:"name"`
Count uint64 `url:"count"`
CPU uint64 `url:"cpu"`
RAM uint64 `url:"ram"`
ImageID uint64 `url:"imageId"`
BootDisk uint64 `url:"bootDisk,omitempty"`
SepID uint64 `url:"sepId,omitempty"`
Pool string `url:"pool,omitempty"`
NetType string `url:"netType,omitempty"`
NetID uint64 `url:"netId,omitempty"`
IPAddr string `url:"ipAddr,omitempty"`
UserData string `url:"userdata,omitempty"`
Desc string `url:"desc,omitempty"`
Start bool `url:"start,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (krq MassCreateRequest) Validate() error {
if krq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if krq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if krq.Count == 0 {
return errors.New("validation-error: field Count must be set")
}
if krq.CPU == 0 {
return errors.New("validation-error: field CPU must be set")
}
if krq.RAM == 0 {
return errors.New("validation-error: field RAM must be set")
}
if krq.ImageID == 0 {
return errors.New("validation-error: field ImageID must be set")
}
return nil
}
func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/kvmx86/massCreate"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
computes := make([]uint64, 0)
err = json.Unmarshal(res, &computes)
if err != nil {
return nil, err
}
return computes, nil
}

@ -1,6 +1,6 @@
package cloudbroker package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg" import "github.com/rudecs/decort-sdk/pkg/cloudbroker/rg"
func (cb *CloudBroker) RG() *rg.RG { func (cb *CloudBroker) RG() *rg.RG {
return rg.New(cb.client) return rg.New(cb.client)

@ -0,0 +1,54 @@
package rg
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
)
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("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'")
}
return nil
}
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,46 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
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("validation-error: field RGID must be set")
}
if rgrq.User == "" {
return errors.New("validation-error: field User must be set")
}
return nil
}
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,46 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AffinityGroupComputesRequest struct {
RGID uint64 `url:"rgId"`
AffinityGroup string `url:"affinityGroup"`
}
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")
}
return nil
}
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (AffinityGroupComputeList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudbroker/rg/affinityGroupComputes"
agcListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
agcList := AffinityGroupComputeList{}
if err := json.Unmarshal(agcListRaw, &agcList); err != nil {
return nil, err
}
return agcList, nil
}

@ -0,0 +1,47 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AffinityGroupsGetRequest struct {
RGID uint64 `url:"rgId"`
AffinityGroup string `url:"affinityGroup"`
}
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")
}
return nil
}
func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudbroker/rg/affinityGroupsGet"
agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
agList := make([]uint64, 0)
err = json.Unmarshal(agListRaw, &agList)
if err != nil {
return nil, err
}
return agList, nil
}

@ -0,0 +1,42 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AffinityGroupsListRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq AffinityGroupsListRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudbroker/rg/affinityGroupsList"
agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
agList := make(map[string][]uint64)
err = json.Unmarshal(agListRaw, &agList)
if err != nil {
return nil, err
}
return agList, nil
}

@ -0,0 +1,41 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AuditsRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq AuditsRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudbroker/rg/audits"
auditListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
auditList := AuditList{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
return nil, err
}
return auditList, nil
}

@ -0,0 +1,64 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
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:"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"`
}
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) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,44 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
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("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,42 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
type DisableRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq DisableRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,42 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
type EnableRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason"`
}
func (rgrq EnableRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,44 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type GetRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq GetRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Get(ctx context.Context, req GetRequest) (*ResourceGroup, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/get"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
getResult := ResourceGroup{}
err = json.Unmarshal(res, &getResult)
if err != nil {
return nil, err
}
return &getResult, nil
}

@ -0,0 +1,31 @@
package rg
import (
"context"
"encoding/json"
"net/http"
)
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) (List, error) {
url := "/cloudbroker/rg/list"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := List{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

@ -0,0 +1,44 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListComputesRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq ListComputesRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/listComputes"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
listComputes := ListComputes{}
err = json.Unmarshal(res, &listComputes)
if err != nil {
return nil, err
}
return listComputes, nil
}

@ -0,0 +1,30 @@
package rg
import (
"context"
"encoding/json"
"net/http"
)
type ListDeletedRequest struct {
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeleted, error) {
url := "/cloudbroker/rg/listDeleted"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
listDeleted := ListDeleted{}
err = json.Unmarshal(res, &listDeleted)
if err != nil {
return nil, err
}
return listDeleted, nil
}

@ -0,0 +1,43 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListLBRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq ListLBRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/listLb"
lbListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
lbList := ListLB{}
err = json.Unmarshal(lbListRaw, &lbList)
if err != nil {
return nil, err
}
return lbList, nil
}

@ -0,0 +1,43 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListPFWRequest struct {
RGID uint64 `url:"rgId"`
}
func (rgrq ListPFWRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPFW, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/listPFW"
pfwListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
pfwList := ListPFW{}
err = json.Unmarshal(pfwListRaw, &pfwList)
if err != nil {
return nil, err
}
return pfwList, nil
}

@ -0,0 +1,44 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListVINSRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq ListVINSRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/listVins"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
listVINS := ListVINS{}
err = json.Unmarshal(res, &listVINS)
if err != nil {
return nil, err
}
return listVINS, nil
}

@ -0,0 +1,38 @@
package rg
import (
"context"
"errors"
"net/http"
)
type MassDeleteRequest struct {
RGIDs []uint64 `url:"rgIds"`
Force bool `url:"force,omitempty"`
Permanently bool `url:"permanently,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (rgrq MassDeleteRequest) Validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
return nil
}
func (r RG) MassDelete(ctx context.Context, req MassDeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/rg/massDelete"
_, err = r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

@ -0,0 +1,36 @@
package rg
import (
"context"
"errors"
"net/http"
)
type MassDisableRequest struct {
RGIDs []uint64 `url:"rgIds"`
Reason string `url:"reason,omitempty"`
}
func (rgrq MassDisableRequest) Validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
return nil
}
func (r RG) MassDisable(ctx context.Context, req MassDisableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/rg/massDisable"
_, err = r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

@ -0,0 +1,36 @@
package rg
import (
"context"
"errors"
"net/http"
)
type MassEnableRequest struct {
RGIDs []uint64 `url:"rgIds"`
Reason string `url:"reason,omitempty"`
}
func (rgrq MassEnableRequest) Validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
return nil
}
func (r RG) MassEnable(ctx context.Context, req MassEnableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/rg/massEnable"
_, err = r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

@ -0,0 +1,264 @@
package rg
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 Current 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"`
}
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"`
}
type Resources struct {
Current Current `json:"Current"`
Reserved Reserved `json:"Reserved"`
}
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 ResourceGroup struct {
Resources Resources `json:"Resources"`
InfoResponse
}
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"`
}
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"`
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 ListVINS []VINS
type PFW struct {
PublicPortEnd uint64 `json:"Public Port End"`
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"`
}
type ListPFW []PFW
type ServerSettings struct {
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"`
SlowStart uint64 `json:"slowstart"`
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"`
ServerSettings ServerSettings `json:"serverSettings"`
}
type Backends struct {
Algorithm string `json:"algorithm"`
GUID string `json:"guid"`
Name string `json:"name"`
ServerDefaultSettings ServerSettings `json:"serverDefaultSettings"`
Servers []Server `json:"servers"`
}
type Binding struct {
Address string `json:"address"`
GUID string `json:"guid"`
Name string `json:"name"`
Port uint64 `json:"port"`
}
type Frontend struct {
Backend string `json:"backend"`
Bindings []Binding `json:"bindings"`
GUID string `json:"guid"`
Name string `json:"name"`
}
type PrimaryNode 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 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"`
}
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

@ -0,0 +1,42 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
type RestoreRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq RestoreRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

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

@ -0,0 +1,50 @@
package rg
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
)
type SetDefNetRequest struct {
RGID uint64 `url:"rgId"`
NetType string `url:"netType"`
NetID uint64 `url:"netId,omitempty"`
Reason string `url:"reason,omitempty"`
}
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")
}
return nil
}
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,50 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
)
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:"maxNetworkPeerTransfer,omitempty"`
RegisterComputes bool `url:"registerComputes,omitempty"`
Reason string `url:"reason"`
}
func (rgrq UpdateRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

@ -0,0 +1,44 @@
package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type UsageRequest struct {
RGID uint64 `url:"rgId"`
Reason string `url:"reason,omitempty"`
}
func (rgrq UsageRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
func (r RG) Usage(ctx context.Context, req UsageRequest) (*Reserved, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/rg/usage"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
usage := Reserved{}
err = json.Unmarshal(res, &usage)
if err != nil {
return nil, err
}
return &usage, nil
}
Loading…
Cancel
Save