v1.0.0
This commit is contained in:
@@ -9,39 +9,61 @@ import (
|
||||
"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, 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("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"}) {
|
||||
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
|
||||
}
|
||||
|
||||
// AccessGrant grants user or group access to the resource group as specified
|
||||
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/accessGrant"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if rgrq.User == "" {
|
||||
return errors.New("field User can not be empty")
|
||||
}
|
||||
@@ -25,16 +33,24 @@ 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
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/accessRevoke"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if rgrq.AffinityGroup == "" {
|
||||
return errors.New("field AffinityGroup cat not be empty")
|
||||
}
|
||||
@@ -24,21 +29,26 @@ func (rgrq AffinityGroupComputesRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (AffinityGroupComputeList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupComputes"
|
||||
agcListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// AffinityGroupComputes gets list of all computes with their relationships to another computes
|
||||
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroups, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agcList := AffinityGroupComputeList{}
|
||||
if err := json.Unmarshal(agcListRaw, &agcList); err != nil {
|
||||
url := "/cloudapi/rg/affinityGroupComputes"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return agcList, nil
|
||||
list := ListAffinityGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if rgrq.AffinityGroup == "" {
|
||||
return errors.New("field AffinityGroup cat not be empty")
|
||||
}
|
||||
@@ -24,21 +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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupsGet"
|
||||
agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agList := []uint64{}
|
||||
if err := json.Unmarshal(agListRaw, &agList); err != nil {
|
||||
url := "/cloudapi/rg/affinityGroupsGet"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return agList, nil
|
||||
list := []uint64{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupsList"
|
||||
agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agList := map[string][]uint64{}
|
||||
if err := json.Unmarshal(agListRaw, &agList); err != nil {
|
||||
url := "/cloudapi/rg/affinityGroupsList"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return agList, nil
|
||||
list := map[string][]uint64{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/audits"
|
||||
auditListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// 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
|
||||
}
|
||||
|
||||
auditList := AuditList{}
|
||||
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
|
||||
url := "/cloudapi/rg/audits"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return auditList, nil
|
||||
list := ListAudits{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -5,53 +5,134 @@ 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:"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"`
|
||||
|
||||
// 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.
|
||||
// Allowed values are:
|
||||
// - 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"`
|
||||
|
||||
// Resource types available to create in this account
|
||||
// Each element in a resource type slice must 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) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/create"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -22,16 +35,24 @@ func (rgrq DeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes resource group
|
||||
func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/delete"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,16 +26,24 @@ func (rgrq DisableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables resource group
|
||||
func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/disable"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,12 +7,18 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for enable resource group
|
||||
type EnableRequest 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 EnableRequest) Validate() error {
|
||||
func (rgrq EnableRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,16 +26,24 @@ func (rgrq EnableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables resource group
|
||||
func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/enable"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,21 +26,26 @@ func (rgrq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) Get(ctx context.Context, req GetRequest) (*ResourceGroup, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/get"
|
||||
rgRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// Get gets current configuration of the resource group
|
||||
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordResourceGroup, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rg := &ResourceGroup{}
|
||||
if err := json.Unmarshal(rgRaw, rg); err != nil {
|
||||
url := "/cloudapi/rg/get"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rg, nil
|
||||
info := RecordResourceGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -6,23 +6,36 @@ 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) (ResourceGroupList, error) {
|
||||
// List gets list of all resource groups the user has access to
|
||||
func (r RG) List(ctx context.Context, req ListRequest) (ListResourceGroups, error) {
|
||||
url := "/cloudapi/rg/list"
|
||||
rgListRaw, 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
|
||||
}
|
||||
|
||||
rgList := ResourceGroupList{}
|
||||
if err := json.Unmarshal(rgListRaw, &rgList); err != nil {
|
||||
list := ListResourceGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rgList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,21 +26,26 @@ func (rgrq ListComputesRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ComputeList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listComputes"
|
||||
computeListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// 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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
computeList := ComputeList{}
|
||||
if err := json.Unmarshal(computeListRaw, &computeList); err != nil {
|
||||
url := "/cloudapi/rg/listComputes"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return computeList, nil
|
||||
list := ListComputes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -6,22 +6,32 @@ 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) (ResourceGroupList, error) {
|
||||
// ListDeleted gets list all deleted resource groups the user has access to
|
||||
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListResourceGroups, error) {
|
||||
url := "/cloudapi/rg/listDeleted"
|
||||
rgListRaw, 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
|
||||
}
|
||||
|
||||
rgList := ResourceGroupList{}
|
||||
if err := json.Unmarshal(rgListRaw, &rgList); err != nil {
|
||||
list := ListResourceGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rgList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +22,26 @@ func (rgrq ListLBRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (LBList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listLb"
|
||||
lbListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// 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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lbList := LBList{}
|
||||
if err := json.Unmarshal(lbListRaw, &lbList); err != nil {
|
||||
url := "/cloudapi/rg/listLb"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lbList, nil
|
||||
list := ListLB{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +22,26 @@ func (rgrq ListPFWRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (PortForwardList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listPFW"
|
||||
pfwListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// ListPFW gets list port forward rules for the specified resource group
|
||||
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pfwList := PortForwardList{}
|
||||
if err := json.Unmarshal(pfwListRaw, &pfwList); err != nil {
|
||||
url := "/cloudapi/rg/listPFW"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pfwList, nil
|
||||
list := ListPortForwards{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,21 +26,26 @@ func (rgrq ListVINSRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (VINSList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listVins"
|
||||
VINSListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// 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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
VINSList := VINSList{}
|
||||
if err := json.Unmarshal(VINSListRaw, &VINSList); err != nil {
|
||||
url := "/cloudapi/rg/listVins"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return VINSList, nil
|
||||
list := ListVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -1,234 +1,592 @@
|
||||
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 int64 `json:"def_net_id"`
|
||||
DefNetType string `json:"def_net_type"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
Dirty bool `json:"dirty"`
|
||||
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 []uint64 `json:"vins"`
|
||||
Computes []uint64 `json:"vms"`
|
||||
// Detailed information about resource group
|
||||
type RecordResourceGroup struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// DefNetID
|
||||
DefNetID int64 `json:"def_net_id"`
|
||||
|
||||
// DefNetType
|
||||
DefNetType string `json:"def_net_type"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Dirty
|
||||
Dirty bool `json:"dirty"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// RegisterComputes
|
||||
RegisterComputes bool `json:"registerComputes"`
|
||||
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
|
||||
// Secret
|
||||
Secret string `json:"secret"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// List of VINS IDs
|
||||
VINS []uint64 `json:"vins"`
|
||||
|
||||
// List of compute IDs
|
||||
Computes []uint64 `json:"vms"`
|
||||
|
||||
// List of resource types
|
||||
ResTypes []string `json:"resTypes"`
|
||||
|
||||
// UniqPools
|
||||
UniqPools []string `json:"uniqPools"`
|
||||
}
|
||||
|
||||
type ResourceGroupList []ResourceGroup
|
||||
// List of resource groups
|
||||
type ListResourceGroups []RecordResourceGroup
|
||||
|
||||
type ACL struct {
|
||||
Explicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Right string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
// Main information about Access Control List
|
||||
type ItemACL struct {
|
||||
// Explicit
|
||||
Explicit bool `json:"explicit"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Right
|
||||
Right string `json:"right"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// User group ID
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
// List ACL
|
||||
type ListACL []ItemACL
|
||||
|
||||
// Resource limits
|
||||
type ResourceLimits struct {
|
||||
CUC 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 AffinityGroupCompute struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
OtherNode []uint64 `json:"otherNode"`
|
||||
OtherNodeIndirect []uint64 `json:"otherNodeIndirect"`
|
||||
// Main information about affinity group
|
||||
type ItemAffinityGroup 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"`
|
||||
OtherNodeSoft []uint64 `json:"otherNodeSoft"`
|
||||
SameNode []uint64 `json:"sameNode"`
|
||||
SameNodeSoft []uint64 `json:"sameNodeSoft"`
|
||||
|
||||
// Other node soft
|
||||
OtherNodeSoft []uint64 `json:"otherNodeSoft"`
|
||||
|
||||
// Same node
|
||||
SameNode []uint64 `json:"sameNode"`
|
||||
|
||||
// Same node soft
|
||||
SameNodeSoft []uint64 `json:"sameNodeSoft"`
|
||||
}
|
||||
|
||||
type AffinityGroupComputeList []AffinityGroupCompute
|
||||
// List of affinity groups
|
||||
type ListAffinityGroups []ItemAffinityGroup
|
||||
|
||||
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"`
|
||||
|
||||
// Status code
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
|
||||
// User
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type AuditList []Audit
|
||||
// List of audits
|
||||
type ListAudits []ItemAudit
|
||||
|
||||
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"`
|
||||
}
|
||||
// Main information about compute
|
||||
type ItemCompute struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
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 uint64 `json:"rise"`
|
||||
Fall uint64 `json:"fall"`
|
||||
SlowStart uint64 `json:"slowstart"`
|
||||
MaxConn uint64 `json:"maxconn"`
|
||||
MaxQueue uint64 `json:"maxqueue"`
|
||||
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 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 uint64 `json:"port"`
|
||||
}
|
||||
|
||||
type PortForward 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 PortForwardList []PortForward
|
||||
|
||||
type VINS struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
Computes uint64 `json:"computes"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Affinity label
|
||||
AffinityLabel string `json:"affinityLabel"`
|
||||
|
||||
// List of affinity rules
|
||||
AffinityRules []interface{} `json:"affinityRules"`
|
||||
|
||||
// Affinity weight
|
||||
AffinityWeight uint64 `json:"affinityWeight"`
|
||||
|
||||
// List of 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"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Registered
|
||||
Registered bool `json:"registered"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Total disks size
|
||||
TotalDisksSize uint64 `json:"totalDisksSize"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User managed
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// Number of ViNS connected
|
||||
VINSConnected uint64 `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
// List of computes
|
||||
type ListComputes []ItemCompute
|
||||
|
||||
// Main information about load balancer
|
||||
type RecordLoadBalancer struct {
|
||||
// HAMode
|
||||
HAMode bool `json:"HAmode"`
|
||||
|
||||
// Access Control List
|
||||
ACL interface{} `json:"acl"`
|
||||
|
||||
// List of Backends
|
||||
Backends ListBackends `json:"backends"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// DPAPIUser
|
||||
DPAPIUser string `json:"dpApiUser"`
|
||||
|
||||
// External network ID
|
||||
ExtNetID uint64 `json:"extnetId"`
|
||||
|
||||
// List of frontends
|
||||
Frontends ListFrontends `json:"frontends"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Primary node
|
||||
PrimaryNode RecordNode `json:"primaryNode"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Secondary node
|
||||
SecondaryNode RecordNode `json:"secondaryNode"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"vinsId"`
|
||||
}
|
||||
|
||||
// Detailed information about load balancer
|
||||
type ItemLoadBalancer struct {
|
||||
// DPAPI password
|
||||
DPAPIPassword string `json:"dpApiPassword"`
|
||||
|
||||
// Main information about load balancer
|
||||
RecordLoadBalancer
|
||||
}
|
||||
|
||||
// Main information about backend
|
||||
type ItemBackend struct {
|
||||
// Algorithm
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Server settings
|
||||
ServerDefaultSettings RecordServerSettings `json:"serverDefaultSettings"`
|
||||
|
||||
// List of servers
|
||||
Servers ListServers `json:"servers"`
|
||||
}
|
||||
|
||||
// List of backends
|
||||
type ListBackends []ItemBackend
|
||||
|
||||
// List of load balancers
|
||||
type ListLB []ItemLoadBalancer
|
||||
|
||||
// Server settings
|
||||
type RecordServerSettings struct {
|
||||
// Inter
|
||||
Inter uint64 `json:"inter"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Down inter
|
||||
DownInter uint64 `json:"downinter"`
|
||||
|
||||
// Rise
|
||||
Rise uint64 `json:"rise"`
|
||||
|
||||
// Fall
|
||||
Fall uint64 `json:"fall"`
|
||||
|
||||
// Slow start
|
||||
SlowStart uint64 `json:"slowstart"`
|
||||
|
||||
// Max connections
|
||||
MaxConn uint64 `json:"maxconn"`
|
||||
|
||||
// Max queue
|
||||
MaxQueue uint64 `json:"maxqueue"`
|
||||
|
||||
// Weight
|
||||
Weight uint64 `json:"weight"`
|
||||
}
|
||||
|
||||
// Main information about server
|
||||
type ItemServer struct {
|
||||
// Address
|
||||
Address string `json:"address"`
|
||||
|
||||
// Check
|
||||
Check string `json:"check"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
|
||||
// Server settings
|
||||
ServerSettings RecordServerSettings `json:"serverSettings"`
|
||||
}
|
||||
|
||||
// List of servers
|
||||
type ListServers []ItemServer
|
||||
|
||||
// Main information about node
|
||||
type RecordNode struct {
|
||||
// Backend IP
|
||||
BackendIP string `json:"backendIp"`
|
||||
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Frontend IP
|
||||
FrontendIP string `json:"frontendIp"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// MGMT IP
|
||||
MGMTIP string `json:"mgmtIp"`
|
||||
|
||||
// Network ID
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
}
|
||||
|
||||
// Main information about frontend
|
||||
type ItemFrontend struct {
|
||||
// Backend
|
||||
Backend string `json:"backend"`
|
||||
|
||||
// List of bindings
|
||||
Bindings ListBindings `json:"bindings"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// List of frontends
|
||||
type ListFrontends []ItemFrontend
|
||||
|
||||
// Main information of binding
|
||||
type ItemBinding struct {
|
||||
// Address
|
||||
Address string `json:"address"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
}
|
||||
|
||||
// List of bindings
|
||||
type ListBindings []ItemBinding
|
||||
|
||||
// Main information about port forward
|
||||
type ItemPortForward struct {
|
||||
// Public port end
|
||||
PublicPortEnd uint64 `json:"Public Port End"`
|
||||
|
||||
// Public port start
|
||||
PublicPortStart uint64 `json:"Public Port Start"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"VM ID"`
|
||||
|
||||
// Virtual machine IP
|
||||
VMIP string `json:"VM IP"`
|
||||
|
||||
// Virtual machine name
|
||||
VMName string `json:"VM Name"`
|
||||
|
||||
// Virtual machine port
|
||||
VMPort uint64 `json:"VM Port"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"ViNS ID"`
|
||||
|
||||
// VINS name
|
||||
VINSName string `json:"ViNS Name"`
|
||||
}
|
||||
|
||||
// List of port forwards
|
||||
type ListPortForwards []ItemPortForward
|
||||
|
||||
// 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 VINSList []VINS
|
||||
// List of VINSes
|
||||
type ListVINS []ItemVINS
|
||||
|
||||
type ResourceUsage struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
// Main information about usage of resource
|
||||
type RecordResourceUsage struct {
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Disk size
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
|
||||
// Number of external IPs
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
|
||||
// ExtraTraffic
|
||||
ExtraTraffic 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"`
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,16 +26,24 @@ 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) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/restore"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +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"
|
||||
)
|
||||
|
||||
// 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,
|
||||
|
||||
@@ -9,18 +9,32 @@ import (
|
||||
"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"`
|
||||
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("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'")
|
||||
}
|
||||
@@ -28,16 +42,24 @@ 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) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/setDefNet"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -5,39 +5,98 @@ 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:"maxNumPublicIP,omitempty"`
|
||||
RegisterComputes bool `url:"registerComputes,omitempty"`
|
||||
Reason string `url:"reason,omitempty"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// Resource types available to create in this account
|
||||
// Each element in a resource type slice must 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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
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) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/update"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -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("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,21 +26,25 @@ func (rgrq UsageRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RG) Usage(ctx context.Context, req UpdateRequest) (*ResourceUsage, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/usage"
|
||||
usageRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// Usage gets report resource usage on the resource group
|
||||
func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
usage := &ResourceUsage{}
|
||||
if err := json.Unmarshal(usageRaw, usage); err != nil {
|
||||
url := "/cloudapi/rg/usage"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return usage, nil
|
||||
info := RecordResourceUsage{}
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user